串口通讯 绘制实时曲线
Option ExplicitDim inputdata As String
Dim DataFromCom As Integer
Dim DataFromComLast As Integer
Dim TimeCount As Integer
Private Sub Check1_Click()
If Check1.Value = 1 Then
MSComm1.InBufferSize = 1024
MSComm1.InBufferCount = 0
MSComm1.InputMode = 1
= 3
MSComm1.Settings = "9600,N,8,1"
Check2.Enabled = False
End If
If Check1.Value = 0 Then
Timer1.Enabled = False
Check2.Enabled = True
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
MSComm1.InBufferSize = 1
MSComm1.InBufferCount = 0
MSComm1.InputMode = comInputModeText
= 2
MSComm1.Settings = "9600,N,8,1"
Check1.Enabled = False
End If
If Check2.Value = 0 Then
Timer1.Enabled = False
Check1.Enabled = True
End If
End Sub
Private Sub Command1_Click(Index As Integer)
'Timer1.Enabled = True
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
End Sub
Private Sub Command2_Click(Index As Integer)
Timer1.Enabled = False
MSComm1.PortOpen = False
End Sub
Private Sub Command3_Click()
Unload Form1
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub
Private Sub Form_Load()
Timer1.Interval = 1
Timer1.Enabled = False
PicScale pic
End Sub
Private Sub PicScale(picX As PictureBox)
picX.Scale (0, 8750)-(picX.ScaleWidth, -1400)
End Sub
Private Sub DrawRealLine(picX As PictureBox, TimeCountX As Integer, DataFromComX As Integer, DataFromComLastX As Integer)
If TimeCountX - 1 > 0 And (TimeCountX - 1) * 15 < pic.Width Then
picX.Line ((TimeCountX - 1) * 15, DataFromComLastX)-(TimeCountX * 15, DataFromComX), vbBlue
End If
If (TimeCountX - 1) * 15 > pic.Width Then
TimeCount = 0
pic.Cls
End If
End Sub
Private Sub MSComm1_OnComm()
Dim byte1() As Byte
Dim i As Integer
If MSComm1.InBufferCount > 0 Then
byte1 = MSComm1.Input
For i = 0 To UBound(byte1)
inputdata = inputdata & Str(byte1(i)) & " "
Text1.Text = Val(byte1(i))
Next i
Text2.Text = inputdata
DataFromCom = Text1
DataFromComLast = DataFromCom
TimeCount = TimeCount + 1
DrawRealLine pic, TimeCount, DataFromCom, DataFromComLast
'Text1.Text = Asc(MSComm1.Input)
'Text2.Text = Text2.Text & " " & Str(byte1(0)) & Str(byte1(1))
'DataFromCom = Text1
'Debug.Print DataFromCom
End If
End Sub
我原来INPUTMODE选的是文本形式,现在改成二进制形式,就怎么也用不了drawrealline这个函数了 ,请问大神们,ONCOMM这里哪里错了 还是其他什么地方错了?