Home > Software engineering >  VB PC receives the MCU data
VB PC receives the MCU data

Time:09-21

Oncomm event how to write A program, microcontroller is to measure the resistance of the potentiometer and send data in ASCII format, such as the measured resistance is 15, then send A R ASCII, A 15 ASCII, A five ASCII, potentiometer rotation Angle of 30 degrees, at this time is to send an A ASCII code, A 3 ASCII, A 0 ASCII, VB how to receive and to distinguish these data? Is to define an array, by first ASCII to differentiate between the data type and then use the data behind the CRH function into characters and deposited in the corresponding text text box code? Ask for advice

CodePudding user response:

 Option Explicit 

Private Sub Form_Load ()
With MSComm1
. The CommPort=1
The Settings="9600, N, 8, 1"
. An InputMode=comInputModeText 'in character mode to accept'
. RThreshold=3 '3 characters full of trigger OnComm news'
. InputLen=3 read three characters' a '
. PortOpen=True
End With
End Sub

Private Sub MSComm1_OnComm ()
Dim sData As String

With MSComm1
If the CommEvent=comEvReceive Then
While the InBufferCount & gt;=3
SData=https://bbs.csdn.net/topics/.Input
The Debug. Print sData
Wend
End the If
End With
End Sub
  • Related