给你个 ,自己慢慢琢磨,
Dim i As Integer
Dim SMBusData(5) As Byte
Dim inbytes() As Byte
Dim MS_Data As Double
Dim LS_Data As Double
ReceiveDataWord = 0
SMBusData(0) = &HAA
SMBusData(1) = &H50
SMBusData(2) = SubCmd
SMBusData(3) = &H0
SMBusData(4) = &H0
For i = 1 To 5
MSComm1.Output = SMBusData
ChkInBuffCountCOM1 (1)
If MSComm1.InBufferCount <> 5 Then
Return = 1
Exit Function
End If
MSComm1.InputLen = 5
inbytes = MSComm1.Input
If inbytes(1) = &H80 And inbytes(2) = &H3 Then
Return= 1
Else
Return = 0
LS_Data = inbytes(3)
Exit For
End If
Next i
SMBusData(0) = &HAA
SMBusData(1) = &H50
SMBusData(2) = SubCmd + 1 ' NEXT ADDRESS
SMBusData(3) = &H0
SMBusData(4) = &H0
For i = 1 To 5
MSComm1.Output = SMBusData
ChkInBuffCountCOM1 (1)
If MSComm1.InBufferCount <> 5 Then
Return = 1
Exit For
End If
MSComm1.InputLen = 5
inbytes = MSComm1.Input
If inbytes(1) = &H80 And inbytes(2) = &H3 Then
Return = 1
Else
Return = 0
MS_Data = inbytes(3)
ReceiveDataWord = MS_Data * &H100& + LS_Data
Exit For
End If
Next i
Public Function ChkInBuffCountCOM1(Length As Long)
Dim i As Integer
Dim FinishTime As Double
FinishTime = GetTickCount + 500 ' unit ms
MSComm1.InBufferCount = 0 ' single step execute can't run this line
Do
DoEvents
Loop Until MSComm1.InBufferCount >= Length Or GetTickCount > FinishTime
If GetTickCount > FinishTime Then
CanNotReadFlag = True
If CorePackFlag = True Then
MsgBox ("can't Read() , Error Code = C201")
Else
MsgBox ("can't Read() , Error Code = F201")
End If
End If
End Function