Home > Software engineering >  A vb program, used to implement with single-chip microcomputer serial port connection, and can displ
A vb program, used to implement with single-chip microcomputer serial port connection, and can displ

Time:09-28


A vb program, used to implement with single-chip microcomputer serial port connection, and can display and send real-time temperature and set the alarm temperature, but always failed when debugging, the red line of
Option Explicit
Dim Buffer As the Variant
Dim InString As String
Dim strData As the Variant
Dim strTemp As the Variant
Dim As Integer I

Private Sub Form_Load ()
MPort=9 MSComm1.Com
MSComm1. Settings="9600, N, 8, 1", "
MSComm1. An InputMode=comInputModeText
MSComm1. InBufferSize=1024
MSComm1. OutBufferSize=1024
MSComm1. InBufferCount=0
MSComm1. OutBufferCount=0
MSComm1. RThreshold=31
MSComm1. SThreshold=2
MSComm1. InputLen=0
MSComm1. PortOpen=True
TextTime. Text=""
TextTemp. Text=""
TextSend. Text=""
End Sub

Private Sub MSComm1_OnComm ()
Dim the Receive As String
Dim Receive0 As String
Dim Receive1 As String
Dim Receive2 As String
Dim Receive3 As String
Dim rec1 As String
Select Case mEvent MSComm1.Com
Case comEvReceive
The Receive=MSComm1. Input

Receive0=Mid (the Receive, InStr (1, Receive, "A"), 16)
Receive1=Mid (Receive0, 2, 8)
Receive3=Mid (Receive0, 10, 2)
Receive2=Mid (Receive0, 12, 4)
TextTime. Text=Receive1
TextTemp. Text=Receive2
TextWarn. Text=Receive3
Rec1=Mid (Receive0, 16, 1)
If rec1="!" Then
Picture1. BackColor=vbRed
The Else
Picture1. BackColor=vbGreen
End the If
The Receive=""
End the Select
MSComm1. InBufferCount=0
MSComm1. OutBufferCount=0

End Sub

Private Sub CommandSend_Click ()
Dim the Send As String
Dim Send1 As String
Dim Send2 As String
MSComm1. OutBufferCount=0
The Send=TextSend. Text
If Len (Send)=6 Then
Send1="aaaaaaaa
"Mid (Send1, 3, 6)=Send
MSComm1. The Output=Send1
End the If
If Len (Send)=2 Then
Send2="BBBBBBBB"
Mid (Send2, 7, 2)=Send
MSComm1. The Output=Send2
End the If

End Sub

CodePudding user response:

Look, what is when something goes wrong in the Receive,

CodePudding user response:

The Receive=MSComm1. Input
The Debug. Print the Receive
Receive0=Mid (the Receive, InStr (1, Receive, "A"), 16)

CodePudding user response:


Is displayed in this way, don't understand, according to the upstairs not changed

CodePudding user response:

The Debug. Print to Print out what content?
  • Related