Now can only collect a number of great god and there is no single chip microcomputer communication program o are added to improve the
Dim T As the Variant
Dim As the Variant c
Dim Y As Integer
Dim Y1 As Integer
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'API, delay to implement in Sleep
'the time delay function
The Function delay (number)
Call Sleep (number)
DoEvents
End the Function
Private Sub Combo1_Click () 'choose port
If Combo1. Text="COM1" Then
MPort=1
MSComm1.ComElseIf Combo1. Text="COM2" Then
MPort=2
MSComm1.ComElseIf Combo1. Text="COM3" Then
MPort=3
MSComm1.ComElseIf Combo1. Text="COM4" Then
MPort=4
MSComm1.ComElseIf Combo1. Text="COM5" Then
MPort=5 MSComm1.Com
ElseIf Combo1. Text="COM6" Then
MPort=6 MSComm1.Com
ElseIf Combo1. Text="COM7" Then
MPort=7 MSComm1.Com
The Else
MPort=8
MSComm1.ComEnd the If
End Sub
Private Sub Command3_Click () 'stop collection
Timer2. Enabled=False
MSComm1. PortOpen=False
Command2. Caption="open the serial port"
End Sub
Private Sub Form_Load initialization () '
MSComm1. Settings="9600, N, 8, 1" 'the default value is "9600, N, 8, 1," meaning "the rate of 9600 serial communication baud, no check, each data to 8 Bit, stop Bit is a Bit",
MSComm1. An InputMode=0 'said in text (ASCII) way to retrieve data
MSComm1. RThreshold=1 'each receive 1 byte produces a OnComm events (events)
MSComm1. SThreshold=0 'data transfer won't produce OnComm events (send)
MSComm1. InBufferSize receive buffer size=1024 '
MSComm1. OutBufferSize send buffer size
=512 'MSComm1. InBufferCount=0 'empty the receive buffer
MSComm1. OutBufferCount=0 'empty send buffer
Combo1. AddItem "COM1"
Combo1. AddItem "COM2
"Combo1. AddItem "COM3
"Combo1. AddItem "COM4
"Combo1. AddItem "COM5
"Combo1. AddItem "COM6
"Combo1. AddItem "COM7
"Combo1. AddItem "COM8
"
Picture1. Scale (- 50, 1150) - (1150-80)
Command1. Caption="data" named
'Command2. Caption="open the serial port"
Timer1. Interval=1000 'collection of real-time clock frequency Interval
Timer2. Interval=25 '
Timer2. Enabled=False 'stop Timer2
End Sub
Private Sub Command2_Click ()
If Command2. Caption="open the serial port" Then
MSComm1. PortOpen=True
Command2. Caption="close serial port"
ElseIf Command2. Caption="close serial port" Then
MSComm1. PortOpen=False
Command2. Caption="open the serial port"
End the If
End Sub
Private Sub MSComm1_OnComm triggers
() 'If MSComm1. InBufferCount & gt; 0 Then
Text3. Text=MSComm1. Input 'return from the buffer and delete characters, will register the serial Input data readout, and eliminate has read the data in the register,
C=Val (Text3. Text)
Delay (50)
End the If
End Sub
Private Sub the draw ()
Picture1. FontSize="15" 'set the font size
Picture1. DrawWidth=3
Picture1. ForeColor=QBColor (0)
Picture1. Cls
Picture1. Line (0, 0) - (0, 1024) 'ordinate
Picture1. Line (10, 1012) - (0, 1024) 'the vertical arrows and y value
The Picture1. Line (10, 1012) - (0, 1024)
Picture1. PSet (10, 1024)
Picture1. Print "heat"
Picture1. Line (0, 0) - (1024, 0) 'abscissa
Picture1. Line (1012, 10) - (1024, 0) 'horizontal arrows and x
Picture1. Line (1012-10) - (1024, 0)
Picture1. PSet (1024-10)
Picture1. Print "time", "
Picture1. DrawWidth=4
Picture1. FontSize=8
For Y=0 To 8 '1024 Step input sampling Step on the horizontal axis value
Next Y
For Y1=0 To 1024 Step 50 'on the vertical axis shows Step value of the text
Picture1. PSet (0, Y1)
Picture1. Print (Y1)
Next Y1
T=0
Timer2. Enabled=True
End Sub
Private Sub Picture1_MouseDOWN (Button As an Integer, Shift the As an Integer, B As in use, As A Single) '" cursor line reading "
Text1. Text=B
Text2. Text=A
End Sub
Private Sub Command1_Click began collecting
() 'Call the draw
End Sub
Private Sub Text1_Change ()
End Sub
Private Sub Timer2_Timer draw () '
Picture1. DrawWidth=2
Picture1. PSet (T, c), QBColor (13) 'PSet paint pixel in the picture box, and specify the color, n
T=T + 5 'step on the horizontal axis value
If the T & gt; Then 1024 'if pixels on the horizontal axis is greater than 1024, is to start drawing
Call the draw
End the If
End Sub
Private Sub Timer1_Timer () 'show time
Text4. Text=CStr (Time $())
End Sub
CodePudding user response:
No communication protocol to protect the communication data, communication quality is very bad, the program will occasionally make a mistake
Private Sub MSComm1_OnComm triggers
() 'If MSComm1. InBufferCount & gt; 0 Then
Text3. Text=MSComm1. Input 'return from the buffer and delete characters, will register the serial Input data readout, and eliminate has read the data in the register,
C=Val (Text3. Text)
Delay (50) '& lt;==this delay function in addition to slow down the speed of computer, completely pointless
End the If
End Sub
'=================================
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
Text3. Text=strconv (Data, vbUnicode) '& lt;=receive such can be directly transformed into string, actually less among an array of processing, the need to grasp,
In Case the Else
End the Select
End Sub
CodePudding user response:
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull