
Recieving data with MSComm1.Input
I have a device that sends streaming serial data in an ascii format.
The overall string is seperated by a carriage return and the fields in
that string are seperated by a space. I'm creating an application to
receive the data and sort it out. The problem I'm having is with the
routine that receives the data. Another routine I've got that
searches for serial ports then goes to this routine to see if what is
available at that port is the expected string type. What is happening
is that the initial data received from the input buffer appears to be
garbage. Then after awhile the data looks fine. Unfortunately the
data I have saved as the string is the one that contains the garbage.
What have I got hosed here. I'm icluding a copy of the routine.
Thanks in advance.
mike
Private Function ModemCommand(APEXSearch) As Integer
Dim strDataIn as String
strDataIn = ""
ModemCommand = 2 'initialize setting for error to FindComPort Routine
MSComm1.Settings = "38400,N,8,1"
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeText 'only want Ascii
'Try a brief pause to allow data to be received if on Comm 1
Sleep (500)
strDataIn = MSComm1.Input
'Search string for unique identifiers to the string
If (InStr(strDataIn, Chr(13))) And (InStr(strDataIn, strFirm)) Then
ModemCommand = 0 'no error, correct string
Else
ModemCommand = 1 'look to next port
EndIf
End Function