发表于:2008/12/29 22:37:00
#0楼
Private Sub Command1_Click()
Dim a!(8), b!(8)
num = MSComm1.InBufferCount '取输入缓冲区字节个数
instring = MSComm1.Input '把输入缓冲区数据送给数组
For i = 0 To num - 1
a(i) = i
b(i) = instring(i)
Graph1.Cls
If i = 1 Then
Graph1.PSet (a(i), b(i))
Else
Graph1.Line -(a(i), b(i)) '将数组数据给绘图函数
End If
Next i
End Sub
Private Sub Command2_Click()
Dim instring As String
instring = MSComm1.Input
MSComm1.Output = Text1.Text + Chr$(13)
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 20
instring = MSComm1.Input
Text1.Text = ""
Text1.Text = instring
End Sub
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text1.SetFocus
End Sub
Private Sub Command4_Click()
MSComm1.PortOpen = False
End
End Sub
Private Sub Command5_Click()
Text2.Text = Text1.Text / 3.92
End Sub
Private Sub Form_Load()
MSComm1.PortOpen = True
Timer1.Interval = 1000 '定时器时间间隔为1000ms
Timer1.Enabled = True
MSComm1.CommPort = 2 '选择通讯口2
MSComm1.Settings = "9600,n,8,1" '波特率9600,无奇偶校验,8个数据位,一个停止位
MSComm1.InputMode = 1 '通过input属性以二进制形式取回数据
MSComm1.InputLen = 0 '读取接收缓冲区全部内容
MSComm1.RThreshold = 1 '每收到一个字符位引发oncomm事件
Graph1.Scale (0, 1000)-(0, 8) '定制坐标
Grahp1.ForeColor = RGB(0, 0, 255)
End Sub
Dim a!(8), b!(8)
num = MSComm1.InBufferCount '取输入缓冲区字节个数
instring = MSComm1.Input '把输入缓冲区数据送给数组
For i = 0 To num - 1
a(i) = i
b(i) = instring(i)
Graph1.Cls
If i = 1 Then
Graph1.PSet (a(i), b(i))
Else
Graph1.Line -(a(i), b(i)) '将数组数据给绘图函数
End If
Next i
End Sub
Private Sub Command2_Click()
Dim instring As String
instring = MSComm1.Input
MSComm1.Output = Text1.Text + Chr$(13)
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 20
instring = MSComm1.Input
Text1.Text = ""
Text1.Text = instring
End Sub
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text1.SetFocus
End Sub
Private Sub Command4_Click()
MSComm1.PortOpen = False
End
End Sub
Private Sub Command5_Click()
Text2.Text = Text1.Text / 3.92
End Sub
Private Sub Form_Load()
MSComm1.PortOpen = True
Timer1.Interval = 1000 '定时器时间间隔为1000ms
Timer1.Enabled = True
MSComm1.CommPort = 2 '选择通讯口2
MSComm1.Settings = "9600,n,8,1" '波特率9600,无奇偶校验,8个数据位,一个停止位
MSComm1.InputMode = 1 '通过input属性以二进制形式取回数据
MSComm1.InputLen = 0 '读取接收缓冲区全部内容
MSComm1.RThreshold = 1 '每收到一个字符位引发oncomm事件
Graph1.Scale (0, 1000)-(0, 8) '定制坐标
Grahp1.ForeColor = RGB(0, 0, 255)
End Sub