×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

visual basic 6 MSComm receive data problem

visual basic 6 MSComm receive data problem

visual basic 6 MSComm receive data problem

(OP)
Hello

Im using the MSComm to send and receive binary data to a video server, the sending part
works fine, but when a receive more than 8 byets, the input variable only keeps the bytes
over the eighth byte. ...Please some can some one tell me where im 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

RE: visual basic 6 MSComm receive data problem

Check/define the size of the receive buffer predifined with a size
buf = space$(256)

RE: visual basic 6 MSComm receive data problem

Fabian, do not declare the receive buffer as variant.  And change the inputmode property to comInputModeText.

CODE

Private Sub Form_Load()

MSComm1.CommPort = 1
MSComm1.Settings = "38400,O,8,1"
MSComm1.InputMode = 0 'comInputModeText
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

End Sub


Private Sub MSComm1_OnComm()

Dim strBuffer As String
Dim i As Integer
Dim sTemp As String
Dim strINPUT As String

Select Case MSComm1.CommEvent
  Case comEvReceive
    strBuffer = MSComm1.Input

    For i = 1 To len(Buffer)
      sTemp = Right("0" & Hex(Asc(Mid(strBuffer, i, 1))), 2)
      strINPUT = strINPUT & sTemp & " "
      Text1.Text = strINPUT
    Next
End Select

End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources