Visual Basic MSComm receive data

F

Thread Starter

fabianuat

Hello,

I'm using the MSComm to send and receive binary data to a video server. The sending part
works fine, but when it receive more than 8 bytes, the input variable only keeps the bytes
over the eighth byte. Please, can someone tell me where I'm wrong??? These are the settings and the OnComm part:

MSComm1.CommPort = 1
MSComm1.Settings = "38400,O,8,1"
MSComm1.InputMode = 1
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.DTREnable = True
MSComm1.RTSEnable = True
MSComm1.NullDiscard = False
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If



Private Sub MSComm1_OnComm()
Dim buffer As Variant
Dim Arr() As Byte
Dim i As Integer
Dim iTemp As Integer
Dim sTemp As String
Dim strINPUT As String

Select Case MSComm1.CommEvent
Case comEvReceive
Do While MSComm1.InBufferCount > 0
buffer = MSComm1.Input
Arr = buffer

For i = LBound(Arr) To UBound(Arr)
iTemp = Asc(Chr$(Arr(i)))
sTemp = Hex$(iTemp)

If Len(sTemp) = 1 Then 'For display in a text box
strINPUT = strINPUT & "0" & sTemp & " "
Else
strINPUT = strINPUT & sTemp & " "
End If

Text1.Text = strINPUT

Next
Loop
 
J
Replace

buffer = MSComm1.Input

with

buffer = buffer & MSComm1.Input

Note: You will need to reinitialize buffer to nothing when you are done processing.
 
Top