Monday, 27 May 2013

VB6 uart app not reading correct port values

VB6 uart app not reading correct port values

for some reason my bytInputArray is only getting the values 255 and 254 when it should be grabbing a 0 - 255 range. basically i declare a buffer as a variant, then convert the individual variant values to bytes.
im thinking maybe its storing larger numbers, like multiple bytes, so when its converting to bytes its getting all 1's. the data stream is fine, so it must be something in the code.
heres my code which is executing on a 500ms timer.
Private Sub Timer1_Timer()

Dim BytesToRead As Integer
Dim bytInputArray(4) As Byte
Dim Buffer As Variant
Dim Count As Integer

'set # of bytes to read
BytesToRead = 4
MSComm1.InputLen = BytesToRead

'poll the input buffer
Do
DoEvents
Loop Until MSComm1.InBufferCount > BytesToRead

Buffer = MSComm1.Input

For Count = 0 To (LenB(Buffer) - 1)
bytInputArray(Count) = CByte(Buffer(Count))
Next Count

Text1.Text = bytInputArray(0)
Text2.Text = bytInputArray(1)
Text3.Text = bytInputArray(2)
Text4.Text = bytInputArray(3)

End Sub

No comments:

Post a Comment