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

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);

   }



//效果图如下:

/

 


 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值