Home > Software engineering >  VB serial port receive less than data
VB serial port receive less than data

Time:10-01

'send data
Private Sub senddata_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles senddata publishes the event. Click
Dim strincoming As String
Dim xx As String
Dim yy As String
Try
SerialPort1. Write (senddata publishes the event. The Text, 0, 4)
Threading. Thread.sleep (1000)
If SerialPort1. BytesToRead & gt; 0 Then
Threading. Thread.sleep (100) 'add delay
Strincoming=SerialPort1. ReadExisting. ToString 'data in a read buffer
SerialPort1. DiscardInBuffer ()
RXbox. Text=strincoming

End the If

Catch the ex As Exception
MessageBox. Show (ex. Message)
End the Try
End Sub

Procedure as above senddata publishes the event to send data, RXbox for receiving data frame, a serial port has been opened, use a serial port assistant debug can transmit and receive, your program of senddata publishes the event enter 1 to receive RXbox are empty inside, please teach the master

CodePudding user response:

Reference: http://download.csdn.net/detail/zdingyun/1070246

CodePudding user response:

Whether can set wrong, check it

CodePudding user response:

Use a serial port to monitor, the data you send in the past?

CodePudding user response:

The
refer to the original poster xidandan621 response:
'to send data
Private Sub senddata_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles senddata publishes the event. Click
Dim strincoming As String
Dim xx As String
Dim yy As String
Try
SerialPort1. Write (senddata publishes the event. The Text, 0, 4)
Threading. Thread.sleep (1000)
If SerialPort1. BytesToRead & gt; 0 Then
Threading. Thread.sleep (100) 'add delay
Strincoming=SerialPort1. ReadExisting. ToString 'data in a read buffer
SerialPort1. DiscardInBuffer ()
RXbox. Text=strincoming

End the If

Catch the ex As Exception
MessageBox. Show (ex. Message)
End the Try
End Sub

Procedure as above senddata publishes the event to send data, RXbox for receiving data frame, a serial port has been opened, use a serial port assistant debug can transmit and receive, your program of senddata publishes the event enter 1 to receive RXbox are empty inside, please master teach



Suggest using http://www.onlinedown.net/soft/119517.htm debugged

CodePudding user response:

If you use a SerialPort controls, please pick up a serial port receives the data in SerialPort_DataReceived events

If you use a SerialPort class, you can refer to
The inside of the http://blog.csdn.net/citybird/article/details/44229025 code, just need to add in the Form of two TextBox and a Button
  •  Tags:  
  • VBA
  • Related