发布网友 发布时间:2024-10-07 06:52
共1个回答
热心网友 时间:2024-11-03 04:16
Option Explicit追答回复追问:
Option Explicit
Dim TTemp As Long
Dim Temp As Single
Private Sub Form_Load()
With MSComm1
.CommPort = 4 '选择COM4口
.Settings = "9600,N,8,1" '波特率为9600,无奇偶校验,8位数据位,1位停止位
.RThreshold = 2 '允许接收事件
.InputMode = 1 '=comInputModeBinary
.InputLen = 0
.PortOpen = True '打开通信端
End With
End Sub
Private Sub MSComm1_OnComm()
Dim buffer As Variant
Dim Data() As Byte
With MSComm1
Select Case .CommEvent
Case comEvReceive
buffer = .Input
Data = buffer
TTemp = 256& * Data(1) + Data(0)
Temp = TTemp * 0.0625
Lab01.Caption = Temp
End Select
End With
End Sub
以上代码在WIN7,VB6调试通过.