简体   繁体   English

USB串行虚拟COM端口:读取无效,但写入有效

[英]USB Serial Virtual COM Port : Read not working but write works

I use embedded hardware (by TI : Piccolo Control Stick xxx69) which uses FTDI usb to serial converter hardware. 我使用嵌入式硬件(由TI:Piccolo Control Stick xxx69)使用FTDI usb到串行转换器硬件。

On PC, I have simple VC++ application which tries to communicate to hardware over Virtual COM port (VCOM : typically COM7). 在PC上,我有一个简单的VC ++应用程序,该应用程序尝试通过虚拟COM端口(VCOM:通常为COM7)与硬件进行通信。

  • I am able to connect to port properly. 我能够正确连接到端口。

  • I am able to send data from application/PC to hardware and it is received correctly. 我能够将数据从应用程序/ PC发送到硬件,并且可以正确接收。 (So, Tx on PC is working fine), Application first opens the connection using createfile(... ... ...) API and then uses writefile(.. ... ..) windows apis to write into the port directly. (因此,PC上的Tx正常工作),应用程序首先使用createfile(... ... ...) API打开连接,然后使用writefile(.. ... ..) Windows API将端口写入端口直。

  • SURPRISINGLY, I am not able to read from serial port to application. 令人惊讶的是,我无法从串行端口读取应用程序。 When I call readfile(... ... ...) api, it returns status as TRUE but ZERO bytes are read. 当我调用readfile(... ... ...) api时,它返回状态为TRUE,但读取了零字节。 I tried using API monitor software, which shows kernel api Ntreadfile(... ... ...) , returns error as STATUS_TIMEOUT" [0x00000102] . It is surprising, because write works but read doesn't although data is there on line. 我尝试使用API​​监控器软件,该软件显示内核api Ntreadfile(... ... ...) ,返回错误为STATUS_TIMEOUT" [0x00000102] 。令人惊讶的是,尽管存在数据,但写入仍然有效,但读取却没有线。

Data is on the line, because when I use normal hyper-terminal software, I am able to read the data correctly form controller and it is visible. 数据在线,因为当我使用常规的超级终端软件时,我能够从控制器正确读取数据并且可见。 [On controller side, it is all right because we can see data on hyper-terminal. [在控制器方面,这很好,因为我们可以在超级终端上看到数据。

I am not windows programmer, as I deal with micro-controllers. 我不是Windows程序员,因为我与微控制器打交道。 Therefore, some help in terms to pursue this issue would be of great help. 因此,在解决该问题方面会有一些帮助。

Best Regards, 最好的祝福,

-Varun -瓦伦

Here is a Reference 这是参考

Issue is solved. 问题已解决。 I had to add wait till InQueue > 0 (it means there is atleast 1 byte in receive buffer) or timeout (as safety exit) is over. 我必须添加等待,直到InQueue> 0(这意味着接收缓冲区中至少有1个字节)或超时(由于安全出口)结束。 it would be blocking call but it is OK for my application at the moment. 这将阻止呼叫,但目前对我的应用程序来说还可以。 waitComm() did not work well for me here. 在这里,waitComm()对我来说效果不佳。

sample snippet: 样本片段:

while(1)
    {
        ClearCommError((HANDLE)*h_drv, (LPDWORD)&Err, &CST);

        if((CST.cbInQue >0)||(count >1000000))
        break;

        count++;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM