Closed UnknownObject000 closed 1 year ago
建议先不设置读取超时进行测试 serial.setReadIntervalTimeout(0);
或者 参考以下文档在4.2.2或4.3.0中开启日志功能测试 https://blog.csdn.net/itas109/article/details/129250464
[CSERIALPORT_DEBUG] CSerialPortWinBase::openPort - portName: COM1, baudRate: 9600, dataBit: 8, parity: 0, stopBit: 0, flowControl: 0, mode: async, readBufferSize:4096(4096), readIntervalTimeoutMS: 0, minByteReadNotify: 1
Open COM1 Success
[CSERIALPORT_DEBUG] CSerialPortWinBase::writeData - write. len: 5, hex(top100): 3132333435
[CSERIALPORT_DEBUG] CSerialPortWinBase::writeData - write. len: 7, hex(top100): 69746173313039
[CSERIALPORT_DEBUG] CSerialPortWinBase::commThreadMonitor - write buffer(usedLen 29). len: 29, hex(top100): 68747470733A2F2F626C6F672E6373646E2E6E65742F69746173313039
[CSERIALPORT_DEBUG] CSerialPortWinBase::commThreadMonitor - onReadEvent. portName: COM1, readLen: 29
[CSERIALPORT_DEBUG] CSerialPortWinBase::readData - read. len: 29, hex(top100): 68747470733A2F2F626C6F672E6373646E2E6E65742F69746173313039
COM1 - Count: 1, Length: 29, Str: https://blog.csdn.net/itas109, Hex: 0x68 0x74 0x74 0x70 0x73 0x3A 0x2F 0x2F 0x62 0x6C 0x6F 0x67 0x2E 0x63 0x73 0x64 0x6E 0x2E 0x6E 0x65 0x74 0x2F 0x69 0x74 0x61 0x73 0x31 0x30 0x39
[CSERIALPORT_DEBUG] CSerialPortWinBase::writeData - write. len: 29, hex(top100): 68747470733A2F2F626C6F672E6373646E2E6E65742F69746173313039
建议先不设置读取超时进行测试 serial.setReadIntervalTimeout(0);
或者 参考以下文档在4.2.2或4.3.0中开启日志功能测试 https://blog.csdn.net/itas109/article/details/129250464
[CSERIALPORT_DEBUG] CSerialPortWinBase::openPort - portName: COM1, baudRate: 9600, dataBit: 8, parity: 0, stopBit: 0, flowControl: 0, mode: async, readBufferSize:4096(4096), readIntervalTimeoutMS: 0, minByteReadNotify: 1 Open COM1 Success [CSERIALPORT_DEBUG] CSerialPortWinBase::writeData - write. len: 5, hex(top100): 3132333435 [CSERIALPORT_DEBUG] CSerialPortWinBase::writeData - write. len: 7, hex(top100): 69746173313039 [CSERIALPORT_DEBUG] CSerialPortWinBase::commThreadMonitor - write buffer(usedLen 29). len: 29, hex(top100): 68747470733A2F2F626C6F672E6373646E2E6E65742F69746173313039 [CSERIALPORT_DEBUG] CSerialPortWinBase::commThreadMonitor - onReadEvent. portName: COM1, readLen: 29 [CSERIALPORT_DEBUG] CSerialPortWinBase::readData - read. len: 29, hex(top100): 68747470733A2F2F626C6F672E6373646E2E6E65742F69746173313039 COM1 - Count: 1, Length: 29, Str: https://blog.csdn.net/itas109, Hex: 0x68 0x74 0x74 0x70 0x73 0x3A 0x2F 0x2F 0x62 0x6C 0x6F 0x67 0x2E 0x63 0x73 0x64 0x6E 0x2E 0x6E 0x65 0x74 0x2F 0x69 0x74 0x61 0x73 0x31 0x30 0x39 [CSERIALPORT_DEBUG] CSerialPortWinBase::writeData - write. len: 29, hex(top100): 68747470733A2F2F626C6F672E6373646E2E6E65742F69746173313039
我也遇到了同样的问题,但是 add_definitions(-DCSERIALPORT_DEBUG) 参数似乎在vcpkg安装的CSerialPort中不起作用,并没有打印调试信息,其版本过低。我试过在vcpkg中执行git pull更新数据,最新版本依旧是4.2.1。
利用readAllData(data)函数可以正常读取串口发来的数据。
CSerialPort版本:4.2.1 运行平台:Windows 10 22H2 编译器:VS2022 打开C++ 20支持
我还在进一步检查问题出在哪里了。。。
vcpkg的CSerialPort已更新到4.3.0
描述bug 根据示例编写测试程序,可以发送数据但无法从串口读取数据
重现步骤 运行以下代码
预期行为 串口数据正常被读取
截图 以下是控制台输出结果
运行环境信息:
其他内容
PurgeComm
和ReadFile
函数正常读取。例如: