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

一个主机放多个网站网页制作基础教程自学

一个主机放多个网站,网页制作基础教程自学,wordpress主题动漫,wordpress博客搬家主页404QT综合示例#xff1a;QT串口通信0、界面#xff1a;1、代码#xff1a;如果用qt写程序作为上位机#xff0c;然后通过和usb和下位机通信的时候#xff0c;就需要用到qt中的串口通信了。 0、界面#xff1a; 1、代码#xff1a; 1#xff09;.pro 添加#xff1a; … QT综合示例QT串口通信0、界面1、代码如果用qt写程序作为上位机然后通过和usb和下位机通信的时候就需要用到qt中的串口通信了。 0、界面 1、代码 1.pro 添加 QT serialport2主函数 main.cpp 添加 #include mywidget.h #include QApplicationint main(int argc, char *argv[]) {QApplication a(argc, argv);myWidget w;w.show();return a.exec(); } 3myWidget.h 添加 #ifdef WIN32 #pragma execution_character_set(utf-8) #endif#ifndef MYWIDGET_H #define MYWIDGET_H#include QWidget#include QSerialPort #include QSerialPortInfo#include QDebug #include QMessageBoxnamespace Ui { class myWidget; }class myWidget : public QWidget {Q_OBJECTpublic:explicit myWidget(QWidget *parent 0);~myWidget();void initUI();public slots:void receiveInfo();private slots:void on_m_OpenPortButton_clicked();void on_btn_Send_clicked();private:Ui::myWidget *ui;private:QStringList getPortNameList(); // 获取所有可用的串口列表QSerialPort* m_serialPort; // 串口类QStringList m_portNameList; // 端口名列表private:void sendInfo(char* info,int len);void sendInfo(QString info);void convertStringToHex(const QString str, QByteArray byteData);char convertCharToHex(char ch); };#endif // MYWIDGET_H4myWidget.cpp 添加 #include mywidget.h #include ui_mywidget.hmyWidget::myWidget(QWidget *parent) :QWidget(parent),ui(new Ui::myWidget) {ui-setupUi(this);m_serialPort new QSerialPort();this-setWindowTitle(QSerialPort);// 设置默认选项ui-m_OpenPortButton-setText(打开串口);ui-cBox_PortName-addItems(getPortNameList());ui-cBox_DataBits-setCurrentIndex(1);ui-cBox_BaudRate-setCurrentIndex(2); }myWidget::~myWidget() {delete ui;m_serialPort-close();delete m_serialPort; }// 1、获得有效串行端口 QStringList myWidget::getPortNameList() {QStringList m_serialPortName;foreach(const QSerialPortInfo info,QSerialPortInfo::availablePorts()){m_serialPortName info.portName();//QMessageBox::information(this,tr(提示),tr(serialPortName: %1).arg(info.portName()),QMessageBox::Ok);//qDebug()serialPortName:info.portName();}return m_serialPortName; }// 2、连接、断开 void myWidget::on_m_OpenPortButton_clicked() {if(m_serialPort-isOpen())//如果串口已经打开了 先给他关闭了{ // m_serialPort-flush(); // m_serialPort-clear();m_serialPort-close();}else{//当前选择的串口名字m_serialPort-setPortName(ui-cBox_PortName-currentText());//用ReadWrite 的模式尝试打开串口if(!m_serialPort-open(QIODevice::ReadWrite)){QMessageBox::warning(this,tr(提示),tr(串口打开失败!),QMessageBox::Ok);return;}// 串口设置m_serialPort-setFlowControl(QSerialPort::NoFlowControl); //无流控制// 1、波特率和读写方向switch(ui-cBox_BaudRate-currentIndex()){case 0:m_serialPort-setBaudRate(QSerialPort::Baud2400,QSerialPort::AllDirections);break;case 1:m_serialPort-setBaudRate(QSerialPort::Baud4800,QSerialPort::AllDirections);break;case 2:m_serialPort-setBaudRate(QSerialPort::Baud9600,QSerialPort::AllDirections);//9600 比特率break;case 3:m_serialPort-setBaudRate(QSerialPort::Baud19200,QSerialPort::AllDirections);break;case 4:m_serialPort-setBaudRate(QSerialPort::Baud57600,QSerialPort::AllDirections);break;case 5:m_serialPort-setBaudRate(QSerialPort::Baud115200,QSerialPort::AllDirections);break;default:break;}// 2、数据位switch(ui-cBox_DataBits-currentIndex()){case 0:m_serialPort-setDataBits(QSerialPort::Data6);//6 bit 数据位break;case 1:m_serialPort-setDataBits(QSerialPort::Data7);//7 bit 数据位break;case 2:m_serialPort-setDataBits(QSerialPort::Data8);//8 bit 数据位break;default:break;}// 3、停止位switch(ui-cBox_StopBits-currentIndex()){case 0:m_serialPort-setStopBits(QSerialPort::OneStop);//1 bit停止位break;case 1:m_serialPort-setStopBits(QSerialPort::OneAndHalfStop); //1.5 bit停止位break;case 2:m_serialPort-setStopBits(QSerialPort::TwoStop); //2 bitbreak;default:break;}// 4、校验位switch(ui-cBox_Parity-currentIndex()){case 0:m_serialPort-setParity(QSerialPort::EvenParity);break;case 1:m_serialPort-setParity(QSerialPort::OddParity);break;default:m_serialPort-setParity(QSerialPort::NoParity);break;}connect(m_serialPort,SIGNAL(readyRead()),this,SLOT(receiveInfo()));}ui-m_OpenPortButton-setText(m_serialPort-isOpen()?tr(关闭串口) : tr(连接串口));ui-m_OpenPortButton-setStyleSheet(m_serialPort-isOpen()?color: red;:color: black;); }// 3、信息接收 void myWidget::receiveInfo() {QByteArray info m_serialPort-readAll();//qDebug()receive info:info;if(!info.isEmpty()){QString str ui-textEdit_receive-toPlainText();strtr(info);ui-textEdit_receive-clear();ui-textEdit_receive-append(str);}info.clear();// QByteArray hexData info.toHex(); // //这里面的协议 你们自己定义就行 单片机发什么 代表什么 我们这里简单模拟一下 // if(hexData 0x10000) // { // //do something // } // else if(hexData 0x100001) // { // //do something // } }// 4、发送按钮 void myWidget::on_btn_Send_clicked() {m_serialPort-write(ui-textEdit_send-toPlainText().toLatin1()); }//写两个函数 向单片机发送数据: // 信息发送函数一 void myWidget::sendInfo(char* info,int len) {for(int i0; ilen; i){printf(0x%x\n, info[i]);}m_serialPort-write(info,len);//这句是真正的给单片机发数据 用到的是QIODevice::write 具体可以看文档 }// 信息发送函数二 void myWidget::sendInfo(QString info) {QByteArray sendBuf;if (info.contains( )){info.replace(QString( ),QString());//我这里是把空格去掉根据你们定的协议来}qDebug()Write to serial: info;convertStringToHex(info, sendBuf); //把QString 转换 为 hexm_serialPort-write(sendBuf); //这句是真正的给单片机发数据 用到的是QIODevice::write 具体可以看文档 }// 基本和单片机交互数据都是16进制的 // Qstring 转为16进制的函数 void myWidget::convertStringToHex(const QString str, QByteArray byteData) {int hexdata,lowhexdata;int hexdatalen 0;int len str.length();byteData.resize(len/2);char lstr,hstr;for(int i0; ilen; ){//char lstr,hstrstr[i].toLatin1();if(hstr ){i;continue;}i;if(i len)break;lstr str[i].toLatin1();hexdata convertCharToHex(hstr);lowhexdata convertCharToHex(lstr);if((hexdata 16) || (lowhexdata 16))break;elsehexdata hexdata*16lowhexdata;i;byteData[hexdatalen] (char)hexdata;hexdatalen;}byteData.resize(hexdatalen); }//另一个 函数 char 转为 16进制 char myWidget::convertCharToHex(char ch) {/*0x30等于十进制的4848也是0的ASCII值1-9的ASCII值是49-57所以某一个值0x30就是将字符0-9转换为0-9*/if((ch 0) (ch 9))return ch-0x30;else if((ch A) (ch F))return ch-A10;else if((ch a) (ch f))return ch-a10;else return (-1); }
http://www.pierceye.com/news/801558/

相关文章:

  • 全国较好的网站建设公司织梦网做网站步骤
  • dedecms小说网站模板自动生成网站地图的工具
  • 中国比较好的设计网站php网站怎么做静态化
  • Dedecms手机网站源码wordpress小程序制作
  • 成都网站建设备案重庆找网站推广
  • 商务网站建设的调研wordpress 视频 全屏
  • 网站策划案例广州高端网站定制开发价格
  • 大连网站制作优选ls15227微信公众号小程序搭建
  • 个人空间网站建设报告网站建设培训哪个好
  • wap微信网站模板在线网络培训平台
  • asp网站怎么做三语网络推广计划书格式
  • 徽州网站建设企业网站备案域名信息
  • 广州建设信息网官方网站火车头采集wordpress发布
  • 易记域名网站大全火车票网站建设多少
  • 怎么将网站权重提上去怎样在网站图片做超级链接
  • 网站建设需求分析报告功能百度官方电话24小时
  • 扬州市城市建设监察支队网站做空比特币网站
  • 石家庄做网站 vtkj网站空间怎样设置用户名和密码
  • 自考网页制作与网站建设网站虚拟主机建设
  • 手机网站建站视频教程阿里云虚拟主机与网站吗
  • 孝感做招聘信息的网站鹏翔科技 网站建设
  • 阿里云 建设网站怎么样长春网站建设翻译
  • 网站空间位置是什么枝江企业网站
  • 网站到期查询固定ip做网站和域名区别
  • 北京专业网站制作大概费用红色网站建设的比较好的高校
  • 廊坊网站的优化html5网站地址
  • 少儿图书销售网站开发背景网络个性化定制
  • 网站制作价格情况微信输入法使用方法
  • 首饰网站建设策划案我的主页制作代码
  • 网站专题页面模板科技有限公司可以做网站建设吗