Delays in serial port comunication with visual basic


Thread Starter



I have a problem with the delay when I'm working with the serial port in visual basic.

When I click on the button (i.d. when I send "M") i receive the values from the port always late. can you help me?

The "M" "T" and "C" commands are pre-programmed in the device which is connected to the serial port.


my code is like below:

Private Sub Command1_Click()
MSComm1.Output = "M"
Label1 = Val(MSComm1.Input)
End Sub

Private Sub Command2_Click()
MSComm1.Output = "T"
End Sub

Private Sub Command3_Click()
MSComm1.Output = "C"
MsgBox "Erased"
End Sub

Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,E,7,1"
On Local Error GoTo error
MSComm1.PortOpen = True
Exit Sub
MsgBox ("Port can not be open" & Error)
Exit Sub
End Sub

Curt Wuollet

I'm pretty sure that only the folks in Redmond know what's going on under the covers. This is one of my major aggravations working with a closed system. There's no way to see what's going on. About all you can do is get a test case down to as little code as possible and see which statement (call) you are spending the time in.

You might try any other means to read the port and see if it's better. And you might see if there is a way to change how the port is handled as we have in *nix. Raw mode, cooked mode, return each character, return after x time, etc.

It would help to know what kind of device is on the receiving end. I'm going out on a limb here - I noticed that you're not sending a carriage return after each "M", "T", or "C" character. The receiver is likely waiting several charatcer intervals for more data before it responds. It would also help to know how long the delay is that you are experiencing. Try this...

Instead of just sending the character:

Try sending a carriage return after the character and see if you get a faster response: ="M"+CHR$(13)

Hopefully that will work for you. If you need additional RS-232/422/485 serial ports, try Sealevel Systems ( They include all kinds of code samples for C++ and VB on the software CD that ships with their products. Good luck!