Home > Software engineering >  Using VB to write a serial port communication for help
Using VB to write a serial port communication for help

Time:09-17

Accept part every time can't complete the first data

Dim buffer As a String
Dim cando As Boolean
Do Until Len (MSComm1. Input) & gt; 0
Text2. Text="not detected data!"
DoEvents
Loop
Text2. Text="is receiving data, please wait... "
Do Until cando=True
Sleep 1000
If MSComm1. InBufferCount & lt;> 0 Then
Buffer=buffer + MSComm1. Input
The Else
Cando=True
Text2. Text="data reception over!"
End the If
Text1. Text=buffer
DoEvents
'Wend

Send part of the instrument can't receive the data

The Open CommonDialog2. The FileName For Input As # 5

Do Until EOF (5)
DoEvents
The Line Input # 5, you
Text2. Text=you
MSComm1. The Output=you
Sleep 100
Loop



For years, for help

CodePudding user response:

A serial port parameters setting on the no

CodePudding user response:

Parameter is set to

CodePudding user response:

Problem is more, lazy said, receiving part at least should also be written,
 
Private Sub MSComm1_OnComm ()
Dim As Long, C Data () As Byte
Select Case mEvent MSComm1.Com
Case comEvReceive
Do
C=MSComm1. InBufferCount
Sleep 10
Loop Until C=MSComm1. InBufferCount
Data=https://bbs.csdn.net/topics/MSComm1.Input
'generally receive code need such treatment, although you received is asc character, but had better use an array to receive, then converted to a string, ASCII value in 128 ~ 254 of symbols with a string it is possible to receive the missing
In Case the Else
End the Select
End Sub
  • Related