6842

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

Question:

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

<ul><li>

I am able to connect to port properly.

</li> <li>

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.

</li> <li>

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.

</li> </ul>

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 <a href="http://social.msdn.microsoft.com/Forums/en-US/b65e4ff9-a7ce-4818-8e36-9db75fe8f49f/usb-serial-virtual-com-port-read-not-working?forum=vcgeneral" rel="nofollow">Reference</a>

Answer1:

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

Recommend

  • How to write incrementally to a text file and flush output
  • How to use StreamWriter.WriteAsync and catch exceptions?
  • Calling python function with an unknown number of arguments [duplicate]
  • How to append a file with a newline using %%writefile -a command in jupyter?
  • How to create file with help of P/Invoke to read boot sector and display .MBR?
  • C++(Serial Communicatio using the ) - How can i find out before hand, how many characters will be re
  • How does file creation work in Java
  • Write to the client returns EWOULDBLOCK when server is slow
  • Relationship between vectors and matrices in R? [closed]
  • Calling a JS function from HTML IFRAME (both web resources)
  • Getters and Setters in Eclipse for Hungarian Style Members
  • RS-232 communication using an Arduino Duemilanove and the Cutedigi RS-232 interface
  • Aspect not executed in Spring
  • pure javascript dom dynamic insert, update and delete
  • Where are files stored on an Android emulator?
  • Get rendered html code in Backing Component from Composite Component
  • record audio in HTML / js without Flash?
  • Implement JwtBearer Authentication in NSwag SwaggerUi
  • Access user's phone number on iOS 7
  • Spring: No transaction manager has been configured
  • How to attach a node.js readable stream to a Sendgrid email?
  • Email format validation in mvc3 view
  • Jenkins: How To Build multiple projects from a TFS repository?
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Sony Xperia Z Tablet not found by adb
  • How to add date and time under each post in guestbook in google app engine
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Javascript convert timezone issue
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Hazelcast - OperationTimeoutException
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • How can I estimate amount of memory left with calling System.gc()?
  • RestKit - RKRequestDelegate does not exist
  • Matrix multiplication with MKL
  • Revoking OAuth Access Token Results in 404 Not Found
  • Hits per day in Google Big Query
  • How do you join a server to an Active Directory (domain)?
  • coudnt use logback because of log4j
  • File not found error Google Drive API
  • Converting MP3 duration time