当前位置: 首页 > news >正文

网站建设开发服务费怎么做账球形网架结构厂家

网站建设开发服务费怎么做账,球形网架结构厂家,注册网站需要备案吗,做影视网站犯法吗如何在linux下用QT写一个简单的串口调试助手QT5串口类在QT5以前#xff0c;编写串口一般使用的是qextserialport类#xff0c;但在QT5之后有了QT自带的串口类SerialPort(串口基础类)和SerialPortInfo(串口信息类)使用方法pro中添加QT serialport工程中包含相应的头文件#incl…如何在linux下用QT写一个简单的串口调试助手QT5串口类在QT5以前编写串口一般使用的是qextserialport类但在QT5之后有了QT自带的串口类SerialPort(串口基础类)和SerialPortInfo(串口信息类)使用方法pro中添加QT serialport工程中包含相应的头文件#include #include linux下查询串口名的方法ctrlalta打开终端输入dmesg | grep ttyS*查询串口名一般为ttyUSB0如图 可以看到串口名为ttyUSB0为ch340的驱动linux的串口权限问题我在刚开始写这个程序的时候总是无法打开串口尝试了qextserialport类和SerialPort类都无法成功后来想起来再用cutecom来调试串口的时候想到需要用管理员权限打开cutecom才可以打开串口可是我又不知道怎么给QT管理员权限因此我让普通用户也能使用串口增加udev规则来实现sudo vim /etc/udev/rules.d/70-ttyusb.rules增加如下内容KERNELttyUSB[0-9]*,MODE0666保存并退出重新插入USB转串口就可以打开串口了此方法参考的如下链接https://blog..net/touch_dream/article/details/52873651以下给出部分代码mainwindow.h#ifndef MAINWINDOW_H#define MAINWINDOW_H#include #include #include #include #include namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{Q_OBJECTpublic:explicit MainWindow(QWidget *parent 0);~MainWindow();private slots:void on_clearButton_clicked();//清除数据void on_sendButton_clicked();//发送数据void on_openButton_clicked();//打开串口void Read_Data();//读取串口数据private:Ui::MainWindow *ui;QSerialPort *serial;//串口对象};#endif // MAINWINDOW_H下面是mainwindow.cpp#include mainwindow.h#include ui_mainwindow.hMainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow){ui-setupUi(this);//查找可用的串口foreach(const QSerialPortInfo info, QSerialPortInfo::availablePorts()){QSerialPort serial;serial.setPort(info);if(serial.open(QIODevice::ReadWrite)){ui-PortBox-addItem(serial.portName());serial.close();}}//关闭发送按钮的使能ui-sendButton-setEnabled(false);}MainWindow::~MainWindow(){delete ui;}//清空接受窗口void MainWindow::on_clearButton_clicked(){ui-textEdit-clear();}//发送数据void MainWindow::on_sendButton_clicked(){serial-write(ui-textEdit_2-toPlainText().toLatin1());}void MainWindow::readMyCom() //读取串口数据并显示出来{QByteArray temp myCom-readAll(); //读取串口缓冲区的所有数据给临时变量tempui-textEdit-insertPlainText(temp); //将串口的数据显示在窗口的文本浏览器中}//读取接收到的数据void MainWindow::Read_Data(){qDebug() tr(youshuju);QByteArray buf;buf serial-readAll();if(!buf.isEmpty()){QString str ui-textEdit-toPlainText();QTextCodec *codec QTextCodec::codecForName(GBK);//指定QString的编码方式QString str_bufcodec-toUnicode(buf);//buf转换成QString类型strstr\nstr_buf;//bufbuf.toHex(); 或者使用这句话将buf转换成十六进制显示//strstr\ntr(buf);ui-textEdit-clear();ui-textEdit-append(str);}buf.clear();}void MainWindow::on_openButton_clicked(){if(ui-openButton-text()tr(打开串口)){serial new QSerialPort;//设置串口名serial-setPortName(/dev/ttyUSB0);//linux下默认的串口名可以进入终端查询//打开串口if(serial-open(QIODevice::ReadWrite)) //如果成功打开串口//设置波特率{qDebug() tr(succeed);// serial-setBaudRate(QSerialPort::Baud9600);// serial-setDataBits(QSerialPort::Data8);// serial-setParity(QSerialPort::NoParity);// serial-setStopBits(QSerialPort::OneStop);//设置数据位数switch(ui-BitNumBox-currentIndex()){case 8: serial-setDataBits(QSerialPort::Data8); break;default: break;}//设置奇偶校验switch(ui-ParityBox-currentIndex()){case 0: serial-setParity(QSerialPort::NoParity); break;default: break;}//设置停止位switch(ui-StopBox-currentIndex()){case 1: serial-setStopBits(QSerialPort::OneStop); break;case 2: serial-setStopBits(QSerialPort::TwoStop); break;default: break;}//设置流控制serial-setFlowControl(QSerialPort::NoFlowControl);//关闭设置菜单使能ui-PortBox-setEnabled(false);ui-BaudBox-setEnabled(false);ui-BitNumBox-setEnabled(false);ui-ParityBox-setEnabled(false);ui-StopBox-setEnabled(false);ui-openButton-setText(tr(关闭串口));ui-sendButton-setEnabled(true);//连接信号槽QObject::connect(serial, QSerialPort::readyRead, this, MainWindow::Read_Data);}else{qDebug() tr(default);}}else{//关闭串口serial-clear();serial-close();serial-deleteLater();//恢复设置使能ui-PortBox-setEnabled(true);ui-BaudBox-setEnabled(true);ui-BitNumBox-setEnabled(true);ui-ParityBox-setEnabled(true);ui-StopBox-setEnabled(true);ui-openButton-setText(tr(打开串口));ui-sendButton-setEnabled(false);}}最终效果打开串口后即可收到串口发送过来的数据
http://www.pierceye.com/news/388638/

相关文章:

  • 网站建设需要钱吗开发一个小程序流程
  • 通州富阳网站建设做足彩网站推广
  • 一个公司做网站需要注意什么条件车之家汽车官网
  • 石家庄网站建设网站建设网站的制作哪家好
  • 苏州晶体公司网站网站排名优化各公司的
  • 网站开发大致多少钱团队拓展训练
  • p2p网站建设方案卫龙模仿iphone做网站
  • 做盗版电影网站犯法吗Wordpress 淘宝客 页面
  • 自己做网站费用html5结构的网站
  • wordpress做资源分享站做网站的图哪来
  • 国外设计欣赏网站线上建模培训班哪个好
  • 微信网站建设合同怎么在本地搭建网站
  • 班级网站怎么做网页制作临沂网站制作方案
  • 泰州网站建设服务好wordpress调用分类名
  • 中英切换的网站咋做怎样在网站做推广
  • 初学网站开发书籍如何提升网站打开速度
  • 深圳微信网站建设公司哪家好网站 维护 页面
  • 做个企业网站需要多少钱北京西站到大兴机场
  • 数字博物馆网站建设动态设计是什么意思
  • 沧州市做网站价格wordpress构建自己的网站
  • seo外链网站源码新公司注册核名
  • 游戏网站建设的策划方案python做电子商务网站
  • pxhere素材网站网上搞钱的野路子
  • 有没有帮人做数学题的网站9377游戏盒子
  • 微信网站建设报价网站优化提升排名
  • wap网站分享代码自定义网站建设
  • 网站换域名了怎么办seo百度帐号注册
  • 淄博网站建设公司羊肉片机网站模板制作
  • 邯郸网站设计价位南京h5 网站建设
  • wordpress主要函数seo是哪个英文的缩写