问题描述
我正在维护一个在Win Embedded Compact 7下运行的C ++应用程序。应用程序通过串口COM1进行通信。该应用程序能够打开串行端口并与终端设备建立通信。但是,从时间
到时间会发生以下情况:
- Windows API ReadFile停止读取数据:返回TRUE并读取零字节。使用串行传递,我们知道数据是由终端设备成功发送的,但由于某种原因,应用程序无法读取它。
- 然后,应用程序开始向客户端发送否定确认(NACK)。终端设备,以便再次请求数据。
- 在发送到终端设备的一定数量的NACK(最多10个)之后,之前请求的所有数据(包括第一个)都可以通过应用程序:数据不会丢失,只能保存在应用程序和串口之间。
- 我想知道是否有人之前已经遇到过这个问题,为什么数据被保存在哪里。更重要的是,我想知道如何首先避免这种情况。
- 相同的代码库在Windows 7上完美运行。
以下是一些使用的设置:
19200,O,8,1
pTimeouts-> ReadIntervalTimeout = 0;
pTimeouts-> ReadTotalTimeoutMultiplier = 0;
pTimeouts-> ReadTotalTimeoutConstant = m_dwTimeOut; //通常为1000毫秒
pTimeouts-> WriteTotalTimeoutMultiplier = 0;
pTimeouts-> WriteTotalTimeoutConstant = m_dwTimeOut;
谢谢
Hi,
I'm maintaining a C++ application that runs under Win Embedded Compact 7. The application communicates through the serial port COM1. The application is able to open the serial port and establish communication with the end device. However, from time to time the following happens:
- Windows API ReadFile stops reading data : returns TRUE and zero bytes read. Using a serial pass-through we know that the data was successfully sent by the end device but for some reason the application is not able to read it.
- The application then starts sending negative acknowledgments (NACK) to the end device in order to request the data again.
- After a certain number of NACK sent to the end device (up to 10), all the data previously requested (including the very first one) can be read by the application : data doesn't get lost, only hold somewhere between the application and the serial port.
- I would like to know if anyone did already encounter this issue before, why the data is being hold and where. More importantly, I would like to know how to avoid this situation in the first place.
- The same code base works perfectly on Windows 7.
The following are some settings used:
19200,O,8,1
pTimeouts->ReadIntervalTimeout=0;
pTimeouts->ReadTotalTimeoutMultiplier=0;
pTimeouts->ReadTotalTimeoutConstant=m_dwTimeOut; // Typically 1000 milliseconds
pTimeouts->WriteTotalTimeoutMultiplier=0;
pTimeouts->WriteTotalTimeoutConstant=m_dwTimeOut;
Thanks
这篇关于ReadFile在Windows Embedded Compact 7下返回TRUE和零字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!