USB串行虚拟COM端口:读取不工作,但写作工作 [英] USB Serial Virtual COM Port : Read not working but write works

查看:238
本文介绍了USB串行虚拟COM端口:读取不工作,但写作工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用嵌入式硬件(通过TI:Piccolo Control Stick xxx69),它使用FTDI usb到串行转换器硬件。



在PC上,我有一个简单的VC ++应用程序通过虚拟COM端口(VCOM:通常为COM7)与硬件通信。




  • 我可以正确连接到端口。


  • p>我可以从应用程序/ PC发送数据到硬件,并且它被正确接收。 (因此,PC上的Tx工作正常),应用程序首先使用 createfile(... ... ...) API打开连接,然后使用 writefile(.. ... ..) windows apis直接写入端口。


  • 无法从串口读取到应用程序。当我调用 readfile(... ... ...) api时,它返回状态为TRUE,但是读取ZERO字节。我尝试使用API​​监视软件,它显示内核api Ntreadfile(... ... ...),返回错误为 STATUS_TIMEOUT[0x00000102 ]




数据在线,因为当我使用正常的超级终端软件时,我能够正确地读取控制器的数据,它是可见的[在控制器端,这是正确的,因为我们可以看到数据在超级终端上。



我不是Windows程序员,因为我处理微控制器。因此,一些帮助在追求这个问题将是很大的帮助。



最好的问候,



-Varun



这是一个参考

解决方案

问题已解决,等待InQueue> 0(这意味着接收缓冲区中至少有1个字节)或超时(作为安全出口)结束。它会阻塞调用,但它是我的应用程序在这一刻。



示例代码片段:

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

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

count ++;
}


I use embedded hardware (by TI : Piccolo Control Stick xxx69) which uses FTDI usb to serial converter hardware.

On PC, I have simple VC++ application which tries to communicate to hardware over Virtual COM port (VCOM : typically 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. (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.

  • 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. 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.

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. 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. it would be blocking call but it is OK for my application at the moment. waitComm() did not work well for me here.

sample snippet:

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

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

        count++;
    }

这篇关于USB串行虚拟COM端口:读取不工作,但写作工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆