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

0

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

c++
windows
serial-port
usb
virtual-serial-port
asked on Stack Overflow Mar 5, 2014 by Varun Mishra • edited Mar 7, 2014 by dsolimano

1 Answer

0

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++;
    }
answered on Stack Overflow Apr 5, 2014 by Varun Mishra

User contributions licensed under CC BY-SA 3.0