EmbeddedMan
10-11-2016, 04:53
If I have an Arduino Uno R3 plugged into my Windows 8 PC, on COM18, and run the following program:
Uses "Console"
Uses "COMM"
Dim hComm As Long
Dim nBytes As Long
Dim sBuffer As String
hComm = COMM_FreeFile
Console_WriteLine("Opening")
COMM_Open("\\.\COM18", hComm)
Console_WriteLine("Done with Err = " & Err)
COMM_Print(hComm, "V" + Chr$(13))
nBytes = COMM_Get(hComm, %COMM_RXQUE)
COMM_TRecv(hComm, nBytes, sBuffer, 1000)
Console_WriteLine("Pre print")
COMM_Print(hComm, "V" + Chr$(13))
Console_WriteLine("Post print")
COMM_Close(hComm)
Console_WriteLine("Press any key to exit.")
Console_WaitKey
then I get
Opening
Done with Err = 0
Pre print
and then it hangs there. I have to unplug the Arduino, at which time the program finishes properly.
I can do this same thing (print "V" + chr$(13) twice) to the Arduino using a terminal emulator just fine, without any hangs. Note that the Arduino is not sending anything back - nBytes is always zero.
Any ideas on how I can debug this further? Why would a COMM_Print() not ever return? Is there some type of COMM setting that I can change to try and help thing?
It's critical that I do two writes with a read between them, or the program doesn't hang. So there's something going on with this USB serial port that involves a writing, then a reading, then the next write never returning.
*Brian
Uses "Console"
Uses "COMM"
Dim hComm As Long
Dim nBytes As Long
Dim sBuffer As String
hComm = COMM_FreeFile
Console_WriteLine("Opening")
COMM_Open("\\.\COM18", hComm)
Console_WriteLine("Done with Err = " & Err)
COMM_Print(hComm, "V" + Chr$(13))
nBytes = COMM_Get(hComm, %COMM_RXQUE)
COMM_TRecv(hComm, nBytes, sBuffer, 1000)
Console_WriteLine("Pre print")
COMM_Print(hComm, "V" + Chr$(13))
Console_WriteLine("Post print")
COMM_Close(hComm)
Console_WriteLine("Press any key to exit.")
Console_WaitKey
then I get
Opening
Done with Err = 0
Pre print
and then it hangs there. I have to unplug the Arduino, at which time the program finishes properly.
I can do this same thing (print "V" + chr$(13) twice) to the Arduino using a terminal emulator just fine, without any hangs. Note that the Arduino is not sending anything back - nBytes is always zero.
Any ideas on how I can debug this further? Why would a COMM_Print() not ever return? Is there some type of COMM setting that I can change to try and help thing?
It's critical that I do two writes with a read between them, or the program doesn't hang. So there's something going on with this USB serial port that involves a writing, then a reading, then the next write never returning.
*Brian