热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

linux系统管理客户端1--串口配置代码编写

1、下载qextserialport-1.2win-alpha.zip2、自定义串口配置类(comDialog:以备主界面调用)3、UI需要自己定义自定义类的头文件:

1、下载qextserialport-1.2win-alpha.zip

2、自定义串口配置类(comDialog:以备主界面调用) 3、UI需要自己定义

 

//自定义类的头文件:
////////////////////////////////////////////////////////////////////////

#ifndef COMDIALOG_H
#define COMDIALOG_H


#include


namespace Ui {

class comDialog;

}


class comDialog : public QDialog

{

Q_OBJECT


public:

explicit comDialog(QWidget *parent = 0);

~comDialog();


private:

Ui::comDialog *ui;


private:

void getCom(); //获取当前机器的可用端口函




private slots:

void clickCommitButton(); //确定按钮槽函数

void clickCancleButton(); //取消按钮槽函数


void clickBackButton(); //恢复默认函数




public:


QString comPort;

int comBaud;

int comStopBit;

int comDataBit;

int comPariy;

int comFlow;

};


#endif // COMDIALOG_H



//自定义类的源文件:

////////////////////////////////////////////////////////////////////////


#include "comdialog.h"

#include "ui_comdialog.h"

#include




comDialog::comDialog(QWidget *parent) :

QDialog(parent),

ui(new Ui::comDialog)

{

ui->setupUi(this);

getCom();

ui->commitButton->setDefault(true);

connect(ui->commitButton,SIGNAL(clicked()),this,SLOT(clickCommitButton()));

connect(ui->cancleButton,SIGNAL(clicked()),this,SLOT(clickCancleButton()));


connect(ui->recoverButton,SIGNAL(clicked()),this,SLOT(clickBackButton()));

}


comDialog::~comDialog()

{

delete ui;

}



void comDialog::getCom()

{

ui->portcomboBox->clear();



for(int portCount = 1;portCount<17;i++) //听说COM口最多16

{

QString strCom = "COM";

strCom += QString::number(portCount,10);

HANDLE Win_Handle =CreateFileA(strCom.toAscii(),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);



if(Win_Handle != INVALID_HANDLE_VALUE)

{

ui->portcomboBox->addItem(strCom);

CloseHandle(Win_Handle);

}

}

}



//取消


void comDialog::clickCancleButton()

{

this->close();

}



//确定


void comDialog::clickCommitButton()

{


comPort = ui->portcomboBox->currentText();

comBaud = ui->baudcomboBox->currentIndex();

comStopBit = ui->stopBitcomboBox->currentIndex();

comDataBit = ui->dataBitcomboBox->currentIndex();

comPariy = ui->paritycomboBox->currentIndex();

comFlow = ui->flowCtrlcomboBox->currentIndex();

}



//恢复默认


void comDialog::clickBackButton()

{

ui->baudcomboBox->setCurrentIndex(7);

ui->stopBitcomboBox->setCurrentIndex(0);

ui->dataBitcomboBox->setCurrentIndex(3);

ui->paritycomboBox->setCurrentIndex(0);

ui->flowCtrlcomboBox->setCurrentIndex(0);

}



//效果图如下:

/////////////////////////////////////////////////////////////////////

 


 

 

 


推荐阅读
author-avatar
古零零碎碎
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有