回复 4楼 风吹过b
这是我们写的代码,能帮我们看看吗?
Private Sub Command1_Click()
MSComm1.Settings = "2400,N,8,1"
'设置波特率4800,无校验位,8位数据位,一位停止位
= 4
'设定串口端口
MSComm1.InBufferSize = 64
'设置接收缓冲区大小
MSComm1.OutBufferSize = 64
'设置发送缓冲区大小
MSComm1.RThreshold = 1
'设置并返回产生oncomm事件的字符数
MSComm1.SThreshold = 0
MSComm1.InputLen = 0
'读取整个缓冲区
MSComm1.InputMode = comInputModeText
'以文本方式接收
MSComm1.InBufferCount = 0
'清空接收缓冲区
MSComm1.OutBufferCount = 0
'清空发送缓冲区
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
End Sub
斌吊 2015/7/6 15:20:36
Private Sub MSComm1_OnComm()
Dim i1 As Variant
Select Case
Case comEvReceive
' '当串口无效时候显示R th resho ld 时引起O nComm 事件
i1 = MSComm1.Input
If i Mod 2 = 0 Then
LabelTempShow.Caption = i1
Picture1.PSet (jishu1 * 5, Val(i1)), vbRed
jishu1 = jishu1 + 1
a1(jishu1 - 1) = Val(i1)
Else
If i1 > 60 Then
warningtime = warningtime + 1
LabelWarningT.Caption = warningtime
List1.AddItem "当前湿度为:" + " " + i1
End If
LabelHumShow.Caption = i1
Picture1.PSet (jishu2 * 5, Val(i1)), vbbule
jishu2 = jishu2 + 1
a2(jishu2 - 1) = Val(i1)
End If
i = i + 1
LabelTempShow.Caption = LabelTempShow.Caption + "℃"
LabelHumShow.Caption = LabelHumShow.Caption + "RH"
If jishu1 >= 2 Then
Picture1.Line ((jishu1 - 1) * 5, a1(jishu1 - 2))-((jishu1) * 5, a1(jishu1 - 1)), vbRed
End If
If jishu2 >= 2 Then
Picture1.Line ((jishu2 - 1) * 5, a1(jishu2 - 2))-((jishu2) * 5, a1(jishu2 - 1)), vbbule
End If
MSComm1.InBufferCount = 0 '清空接收缓冲器
End Select
End Sub