I have a UI based TB app which presents the user with a pull-down menu of all of the available COM ports on their PC to pick from. I then open the port they choose and use it to communicate.
Everything works fine unless they pick the wrong port. Some PCs (Lenovo laptops in this case) have a COM port which comes up as an 'available' com port in the list but is actually internal to the PC and is used to communicate with "Intel(R) Active Management Technology", whatever the heck that is.
Here's the problem: If the user picks the "Intel Active Management Technology" port by accident, TB will open up that COM port just fine, but will hang on the first COMM_Send() call.
Here's a short program demonstrating the problem:
Uses "console"
Uses "COMM"
Function TBMain() As Long
Local hComm As Long
Console_WriteLine("Starting test")
hComm = COMM_FreeFile
If COMM_Open("\\.\COM3", hComm) = 0 Then
If Err = 0 Then
COMM_Send(hComm, "A")
Else
Console_WriteLine("Err not zero")
End If
Else
Console_WriteLine("Failed to open port")
End If
Console_WriteLine("Ending test")
WaitKey
End Function
Now, on my machine, COM3 happens to be this 'special' (and evil) COM port. On other people's PCs it is different.
If I run the above test program on my machine, I get "Starting test" in the console, and then nothing else. The program hangs at COMM_Send(). I can ctrl-C out of it in this console based version.
If I change the com port to COM2 in the above code and run it (my PC does not have a COM2), then I get "Starting test", then "Failed to open port", then "Ending test".
If I change the com port to COM4 in the above code and run it (my PC has a USB to serial adapter in COM4), then I get "Starting test" then "Ending test".
If I open up COM4 with another application first, then run the above program on COM4 (to test what happens if TB tries to open a COM port that's already open) I get "Starting test" and that's it - program hangs.
So I'm pretty sure what's going on here is that the list of COM ports doesn't exclude ones that are already opened by another application. So if the user tries to open one that's already open in another application, the COMM_Open() call doesn't fail (shouldn't it??), and when we get to the COMM_Send(), we get the hang.
Would it be possible to:
A) Make COMM_Open() fail if another app is already using the port?
or
B) Make COMM_Send() return an error code or something in this case rather than just hanging?
Either would be preferable to what it does now.
Thanks!
*Brian
Bookmarks