Code: Select all
Public Function Com3GetString(ByRef inbuf as String, _
ByVal endflag as Byte) as byte
'this function gets a string from Com3. If the subroutine times out before
'receiving the endflag character then the function returns 0 else it
'returns the number of bytes read from the receive queue. The string inbuf
'will contain all data in queue up to and including the endflag.
'NOTE: If function times out then inbuf is returned empty.
Dim timeout as Single
Dim ct as Byte
Dim i as Byte
Dim data as Byte
ct = 0 'assume failure
data = 0
inbuf = "" 'start with empty string
If StatusQueue(rq3) Then 'something to get?
timeout = Timer + 0.2 'adjust as needed for length of messages
ct = 1
Do While StatusQueue(rq3) 'as long as there is something to get
Call GetQueue(rq3, data, 1)
If Timer > timeout Then
Exit Do
End If
inbuf = inbuf & Chr(data) 'plunk into string
If data = endflag Then 'end of data in queue
Exit Do
End If
ct = ct + 1 'get next byte
Loop
End If
If data = endflag Then
Com3GetString = ct 'return actual byte count
Else
Com3GetString = 0 'return error flag
End If
End Function 'Com3GetString
Any enlightenment will be appreciated.
Vic