Help with Serial Receive data

jeterry

Member
Licensed User
Longtime User
In my application I am trying to receive serial data and place it in a variable. I have tried the EnableOncom event, but it never fires. I tried the serial terminal example and the event fires there. I am using the serial2.dll. Here is the code:
Sub receivedata
Serial.BitRate = 9600 'baud rate
Serial.CommPort = 1
Serial.Timeout = 500
Serial.MaxInputLen = 40
Serial.PortOpen = True
Serial.EnableOnComm = True
Do Until Serial.InBufferCount <> 0 ' I did the loop to wait for data to be sent
Loop
Serial.PortOpen = False
reader.Close
Msgbox(dexesign)
End Sub

Sub Serial_OnCom 'Fires whenever the EnableOnComm is true and there is communication
dexesign = dexesign & Serial.InputString
Msgbox(dexesign)
End Sub

dexesign is a global variable

Can someone suggest a better way to accomplish capturing the data.
 

mjcoon

Well-Known Member
Licensed User
Have you copied the example? (I haven't looked it up.) Surely not! On the face of it you seem to loop until there is input and then close the port. It is expecting a bit much for the event to fire and capture the input while (sort of at the same time) closing the port.

How about taking a copy of the example and building it up to do what you want, checking it still works at each stage? (This is the cautious approach I have used in the past!)

HTH, Mike.
 

jeterry

Member
Licensed User
Longtime User
Got It Working. Moved the serial.port closed to another spot as suggested by mjcoon

Thanks again
 
Top