Home > Software engineering >  VB to continue to read the data in the serial port
VB to continue to read the data in the serial port

Time:09-21

Via a serial port assistant reading display data is normal, when shown as "03 01, 02,"
But using VB to read serial display garbled estimate I write VB program has a problem, certainly, ask everybody to help! (baud rate setting not wrong, an inputmode=0, were tried all the code=1)
 Private Sub Form_Load () 
MPort=3
MSComm1.ComMSComm1. Settings="4800, n, 8, 1", "
MSComm1. An InputMode=1
MSComm1. An InputMode=comInputModeText
MSComm1. PortOpen=True


End Sub

Private Sub Timer1_Timer ()
Dim buf $
Buf=Trim (MSComm1. Input)
If Len (buf) & lt;> 0 Then
Text1. Text=Text1. Text + CRH (13) + CRH (10) + buf
End the If
End Sub

Private Sub cmdquit_click ()
MSComm1. PortOpen=False
Unload Me
End Sub

CodePudding user response:

What do you read? Try:

Text1. Text=Text1. Text & amp; VbCrLf & amp; buf

CodePudding user response:

Is the output data into system

CodePudding user response:

If not, try again:
 Dim As Long I 
If Len (buf) & gt; 0 Then
Text1. Text=Text1. Text & amp; CRH (13) & amp; CRH (10)
For I=0 To Len (buf) - 1
Text1. Text=Text1. Text & amp; Right (" 0 "& amp; Hex (buf (I)), 2)
Next I
End the If

CodePudding user response:

The
reference 3 floor of123 response:
if not, try again:
 Dim As Long I 
If Len (buf) & gt; 0 Then
Text1. Text=Text1. Text & amp; CRH (13) & amp; CRH (10)
For I=0 To Len (buf) - 1
Text1. Text=Text1. Text & amp; Right (" 0 "& amp; Hex (buf (I)), 2)
Next I
End the If

Or not, I send a serial port MCU is a best figures, such as 123, a serial port assistant read data is to display "00 00 7 b" is 123 hexadecimal display,
But using VB to read a serial port, it is stil, specific performance is: in the serial data is below 300, what also don't show; Is more than 300, showed that starting from 9 and increasing

CodePudding user response:

refer to the second floor YC3354 response:
is not output data base problems

I send a serial port MCU is a best figures, such as 123, a serial port assistant read data is to display "00 00 7 b" is 123 hexadecimal display,
But using VB to read a serial port, it is stil, specific performance is: in the serial data is below 300, what also don't show; Is more than 300, showed that starting from 9 and increasing

CodePudding user response:

Oh no, it should be said that:
I send a serial port MCU is a best figures, such as 123, a serial port assistant read data is to display "00 00 7 b" is 123 hexadecimal display,
But using VB to read a serial port, it is stil, specific performance is: in the serial data is below 300, what also don't show; Is more than 300, will only display the data of single digits, ten and one hundred display space

CodePudding user response:

 
Private Sub Form_Load ()
MPort=3
MSComm1.ComMSComm1. Settings="4800, n, 8, 1", "
MSComm1. An InputMode=1
MSComm1. An InputMode=comInputModeText
MSComm1. PortOpen=True


End Sub

Private Sub Timer1_Timer ()
Dim buf () As Byte, I As an Integer
Buf=MSComm1. Input
Text1. Text=Text1. Text & amp; VbCrlf
For I=0 to Ubound (buf)
Text1. Text=Text1. Text & amp; Right (" 0 "& amp; Hex (buf (I)), 2) & amp; CRH (32)
End the If
Text1. Text=Text1. Text & amp; VbCrlf
End Sub

Private Sub cmdquit_click ()
MSComm1. PortOpen=False
Unload Me
End Sub

I changed the Timer function, run it, see the effect in said

CodePudding user response:

Is not string data, you also use the string data to receive, VB ASCII string is more than 127 will become 0, want to use the array receiving

CodePudding user response:

 
Private Sub Form_Load ()
MPort=3
MSComm1.ComMSComm1. Settings="4800, n, 8, 1", "
MSComm1. An InputMode=1
MSComm1. An InputMode=comInputModeText
MSComm1. PortOpen=True
End Sub

Private Sub Timer1_Timer ()
Dim buf () As Byte, I As an Integer
If MSComm1. InputLen> 0 then
Buf=MSComm1. Input
Text1. Text=Text1. Text & amp; VbCrlf
For I=0 to Ubound (buf)
Text1. Text=Text1. Text & amp; Right (" 0 "& amp; Hex (buf (I)), 2) & amp; CRH (32)
Next
Text1. Text=Text1. Text & amp; VbCrlf
End the if
End Sub

Private Sub cmdquit_click ()
MSComm1. PortOpen=False
Unload Me
End Sub

CodePudding user response:

The
stupid dog fly response: first, 9/f, reference
 
Private Sub Form_Load ()
MPort=3
MSComm1.ComMSComm1. Settings="4800, n, 8, 1", "
MSComm1. An InputMode=1
MSComm1. An InputMode=comInputModeText
MSComm1. PortOpen=True
End Sub

Private Sub Timer1_Timer ()
Dim buf () As Byte, I As an Integer
If MSComm1. InputLen> 0 then
Buf=MSComm1. Input
Text1. Text=Text1. Text & amp; VbCrlf
For I=0 to Ubound (buf)
Text1. Text=Text1. Text & amp; Right (" 0 "& amp; Hex (buf (I)), 2) & amp; CRH (32)
Next
Text1. Text=Text1. Text & amp; VbCrlf
End the if
End Sub

Private Sub cmdquit_click ()
MSComm1. PortOpen=False
Unload Me
End Sub
you said this seemed very reasonable! I got up to try!

CodePudding user response:

references 9 f bakw response:
 
Private Sub Form_Load ()
MPort=3
MSComm1.ComMSComm1. Settings="4800, n, 8, 1", "
MSComm1. An InputMode=1
MSComm1. An InputMode=comInputModeText
MSComm1. PortOpen=True
End Sub

Private Sub Timer1_Timer ()
Dim buf () As Byte, I As an Integer
If MSComm1. InputLen> 0 then
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related