资源简介
使用Qt5自带的QSerialPort和QSerialPortInfo写的控制台程序,可读取串口数据。环境:win7 64位系统,Qt版本:qt-opensource-windows-x86-mingw482_opengl-5.3.0
![](http://www.nz998.com/pic/65999.jpg)
代码片段和文件信息
#include
#include
#include
#include
#include
QT_USE_NAMESPACE
int main(int argc char *argv[])
{
QCoreApplication (argc argv);
QTextStream standardOutput(stdout);
QSerialPort serialPort;
QList serialPortInfoList = QSerialPortInfo::availablePorts();
/*standardOutput << Qobject::tr(“Total number of ports available: “) << serialPortInfoList.count() << endl;
const QString blankString = Qobject::tr(“N/A“);
QString description;
QString manufacturer;
QString serialNumber;*/
foreach (const QSerialPortInfo &serialPortInfo serialPortInfoList) {
/*description = serialPortInfo.description();
manufacturer = serialPortInfo.manufacturer();
serialNumber = serialPortInfo.serialNumber();*/
serialPort.setBaudRate(QSerialPort::Baud115200);
serialPort.setPortName(serialPortInfo.portName());
standardOutput << endl
<< Qobject::tr(“Port: “) << serialPortInfo.portName() << endl
/*<< Qobject::tr(“Location: “) << serialPortInfo.systemLocation() << endl
<< Qobject::tr(“Description: “) << (!description.isEmpty() ? description : blankString) << endl
<< Qobject::tr(“Manufacturer: “) << (!manufacturer.isEmpty() ? manufacturer : blankString) << endl
<< Qobject::tr(“Serial number: “) << (!serialNumber.isEmpty() ? serialNumber : blankString) << endl
<< Qobject::tr(“Vendor Identifier: “) << (serialPortInfo.hasVendorIdentifier() ? QByteArray::number(serialPortInfo.vendorIdentifier() 16) : blankString) << endl
<< Qobject::tr(“Product Identifier: “) << (serialPortInfo.hasProductIdentifier() ? QByteArray::number(serialPortInfo.productIdentifier() 16) : blankString) << endl
<< Qobject::tr(“Busy: “) << (serialPortInfo.isBusy() ? Qobject::tr(“Yes“) : Qobject::tr(“No“)) << endl*/
<< Qobject::tr(“Baud Rate: %1“).arg(serialPort.baudRate()) << endl;
}
if (!serialPort.open(QIODevice::ReadWrite))
{
standardOutput << Qobject::tr(“Failed to open port %1 error: %2“).arg(serialPort.portName()).arg(serialPort.error()) << endl;
return 1;
}
QByteArray readData = serialPort.readAll();
while (serialPort.waitForReadyRead(1000))
readData.append(serialPort.readAll());
if (serialPort.error() == QSerialPort::ReadError)
{
standardOutput << Qobject::tr(“Failed to read from port %1 error: %2“).arg(serialPort.portName()).arg(serialPort.errorString()) << endl;
return 1;
}
else if (serialPort.error() == QSerialPort::TimeoutError && readData.isEmpty())
{
standardOutput << Qobject::tr(“No data was currently available for reading from port %1“).arg(serialPort.portName()) << endl;
return 0;
}
else
{
standardOutput << Qobject::t
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3363 2014-07-04 13:47 Sreader\main.cpp
文件 469 2014-07-02 16:09 Sreader\Sreader.pro
文件 18211 2014-07-04 13:47 Sreader\Sreader.pro.user
目录 0 2014-07-04 13:47 Sreader
----------- --------- ---------- ----- ----
22043 4
相关资源
- 易语言OTG串口通信
- delphi 串口通讯
- STM32蓝牙和串口程序
- LCD显示温度+串口接收温度.rar
- WPF USB 网络 串口 通信软件
- DELPHI与西门子200PLC的串口通信实例
- Verilog FPGA UART串口控制器
- USB转串口驱动,FT232R驱动程序,最新
- PC -- 单片机的串口数据传输系统设计
- STM32F103 串口程序(完整版)
- stm32 ds18b20 温度传感器 测试通过
- ply格式文件的读写程序
- QT局域网聊天系统(基于QT5.修改过)
- PC 串口调试软件
- 51单片机读取温度数据存储到SD卡中并
- 单片机与PC机串口通讯仿真
- 串口调试助手V5.0
- 双串口调试助手 V4.0 _ 可同时调试两个
- 读取串口数据并画实时曲线的VC 程序
- 网络(UDP)转串口程序
- 串口绘制曲线 将收到的数据进行曲线
- 基于ARM蓝牙传输源程序
- JS操作本地网页串口源码
- 学生成绩管理系统C 源码(很完整)
- AT89S ISP下载编程软件(串口)
- 串口操作类(justinio)
- 《Visual Basic 串口通信与测控应用技术
- 耀华XK3190-A9地磅串口代码
- ch452串口键盘驱动程序
- 托利多电子秤ind245协议读取串口数据
评论
共有 条评论