Home > Software engineering >  VB to write a serial port, a receiving area can't display
VB to write a serial port, a receiving area can't display

Time:09-25


 Private Sub hexReceive () 

On Error GoTo Err
Dim ReceiveArr () As Byte 'receiving data array
Dim receiveData As String 'data staging
Dim Counter As an Integer number Counter
'receiving dataDim the I loop variables As Integer '

If (MSComm InBufferCount & gt; 0) Then
Counter=MSComm. Receives the data read InBufferCount 'number
receiveDatahttps://bbs.csdn.net/topics/=", "qing buffer

ReceiveArr=MSComm. Input data into an array '

For I=0 To (Counter - 1) Step 1 'data format processing

If (ReceiveArr (I) & lt; 16) Then
ReceiveData=https://bbs.csdn.net/topics/receiveData & "0" + Hex (ReceiveArr (I)) & amp; Space (1) 'is less than 16, adding 0
The Else
ReceiveData=https://bbs.csdn.net/topics/receiveData & Hex (ReceiveArr (I)) and Space (1) the 'add Spaces according to
End the If

Next I

TxtReceive. Text=TxtReceive. Text + receiveData 'shows receive hexadecimal data
TxtReceive. SelStart=Len (TxtReceive. Text) 'display the cursor position
End the If

ReceiveCount=ReceiveCount + Counter 'receiving count
TxtRXCount. Text="RX:" & amp; ReceiveCount 'receive bytes according to

If ChkAutoClear. Value=https://bbs.csdn.net/topics/1 Then 'automatic emptying judgment
If ReceiveCount & gt; Then=65535
TxtReceive. Text=""
End the If
End the If
Err:

End Sub

Hexadecimal send, debugging ReceiveArr=MSComm. Input without execution, and hexadecimal send is normal, show caught a serial port tool to send and receive, is receiving area did not show, why is this?

CodePudding user response:

TxtReceive. Refresh
TxtRXCount. Refresh

CodePudding user response:

Counter=MSComm. Receives the data read InBufferCount 'number
receiveDatahttps://bbs.csdn.net/topics/=", "qing buffer

ReceiveArr=MSComm. Input data into an array '


MSComm1. InputLen=0

CodePudding user response:

Just press the wrong to write a
Counter=MSComm. Receives the data read InBufferCount 'number
receiveDatahttps://bbs.csdn.net/topics/=", "qing buffer

ReceiveArr=MSComm. Input data into an array '
In the middle add
Try MSComm1. InputLen=0, probably like this
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
Counter=MSComm. Receives the data read InBufferCount 'number
receiveDatahttps://bbs.csdn.net/topics/=", "qing buffer
MSComm1. InputLen=0
ReceiveArr=MSComm. Input data into an array

CodePudding user response:

MsComm control RThreshold attribute set is not equal to zero?
If Rthreshold attribute is set to 0 (the default), do not produce OnComm event,
  •  Tags:  
  • VBA
  • Related