MSComm problems
-
Hi Guys, I have a baffling problem with the MSComm control in a VB6 app I'm writing. I'm trying to send a binary command out the serial port, then read a binary response. The command is 6 bytes and the response is 17. When I single-step over the .Output statement, everything works just fine. But if I set the breakpoint after the .Output statement, i.e. I'm executing at full throttle through the .Output, the received data is mostly lost. I do wait until .OutBufferCount goes to zero and DoEvents to make sure any messages are getting processed. Another strange symptom is that I'm not seeing any OnComm events. I've set .RThreshold = 1 to try to catch the response data byte by byte, but not a blip from the OnComm event handler. Here's the snippet of initialization code I'm using:
With MSComm1 .CommPort = Port .Settings = Baud & "," & Parity & "," \_ & DataBits & "," & StopBits .RTSEnable = True .DTREnable = True 'read entire buffer when Input is used. .InputLen = 0 'we're dealing with binary data .InputMode = comInputModeBinary .RThreshold = 1 .PortOpen = True End With
And here's what I'm doing in the command/response code:
'everything works fine if I put a breakpoint on the following 'line and single-step over the .Output statement MSComm1.Output = cmdGetData Do Until MSComm1.OutBufferCount = 0 DoEvents Loop 'this hangs because we never get the full 17 bytes of data While MSComm1.InBufferCount < 17 DoEvents Wend
Lastly, everything seems fine when using ASCII (string) data, so I'm wondering if there's something peculiar about binary. Thanks in advance for any insights. -- Dave QRZ? de WAØTTN