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

纵饮孤独 提交于 2019-12-11 19:52:12

问题


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


回答1:


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++;
    }


来源:https://stackoverflow.com/questions/22193437/usb-serial-virtual-com-port-read-not-working-but-write-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!