Uart没有在C++中阅读整个消息
Uart not reading whole message in C++
我正在使用termios从uart设备中读取线路,尽管它的行为不稳定。我使用的是阻塞规范模式,我发现大多数时候我只接收消息的后端。我启用的标志有:ICRNL、ICANON、ISIG、CLOCAL、O_RDWR、O_NOCTTY和CREAD。我的波特率是38400。
从设备发出的消息以回车结束,我使用了一个逻辑分析器来查看进出设备的信号是否符合我的预期。
//The code for all of our flags
uart.inputModes.IgnoreCharactersWithParityError = false;
uart.localModes.CanonicalInput = true;
uart.localModes.EnableSignals = true;
uart.controlModes.ParityEnabled = false;
uart.controlModes.IgnoreModemStatusLines = true;
uart.controlModes.EnableReceiver = true;
uart.inputModes.MapCR_To_NL = true;
uart.openDeviceUart();
int readArraySize = 50;
unsigned char readData[readArraySize];
memset(readData, 0, readArraySize);
uart.SendBytes("$C01,03,41r");
int myBytes = uart.ReadBytes(readData, readArraySize);
std::cout << "Bytes Received: " << myBytes << std::endl;
for (int i = 0; i < readArraySize; i++) {
std::cout << (char) readData[i];
}
uart.CLOSE();
所以我找到了问题的原因。我的termios代码是正确的,我的信号看起来和我们预期的差不多,但我们为设备使用的命令启动了一个流,每次我们想读取时,我们都会打开它。谢谢大家的帮助。
相关文章:
- boost::进程间消息队列引发错误
- 在线编译器中的分段C++没有打印消息
- C++错误消息*成员参考.**初学者*
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- 如何通过参数抛出错误消息
- 从服务器传输到客户端的消息不会出现
- ROS2 动态消息模板
- C++秘密消息学校作业
- glad 导致 glfwSwapBuffers 返回错误消息
- C++入门 5 版:类消息和文件夹
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- 如何处理从一个对象传递到另一个在C++中具有公共抽象类的对象的消息
- 如何接受 [ENTER] 键作为无效输入并发送错误消息
- 由于无效的 ValidateRgn() 子窗口不会收到WM_PAINT消息
- "string.h"在构建适用于iOS的qt应用程序中找不到消息
- 如何将 Firebase 与基于 Linux 的客户端应用配合使用,以便与服务器进行双向消息通信
- 重新定义预定义的 errno 错误消息 (E2BIG)
- Libmosquitto publish 不会将所有消息传递到 Azure IoT Hub
- 在 capnp FlatArrayMessageReader 的对齐内存缓冲区中接收 zmq 消息