vb 与 传感器通信问题?
Option Explicit
Dim strData As String
Dim strData1 As String
Dim sendData(3) As Byte
Private Sub Command1_Click()
sendData(0) = &HAA
sendData(1) = &H12
sendData(2) = &H34
sendData(3) = &H46
MSComm1。 Output = sendData
End Sub
Private Sub Form_Load()
MSComm1。Settings = "9600,n,8,1"
MSComm1。 RThres...全部
Option Explicit
Dim strData As String
Dim strData1 As String
Dim sendData(3) As Byte
Private Sub Command1_Click()
sendData(0) = &HAA
sendData(1) = &H12
sendData(2) = &H34
sendData(3) = &H46
MSComm1。
Output = sendData
End Sub
Private Sub Form_Load()
MSComm1。Settings = "9600,n,8,1"
MSComm1。
RThreshold = 8
MSComm1。PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Static i As Single
Dim iData() As Byte
Dim strChars As String
Dim dd As Boolean
Dim sTimer As Single
Dim lend As Integer
Dim intInputLen As Integer
Select Case MSComm1。
CommEvent
Case comEvReceive
MSComm1。InputMode = comInputModeBinary
intInputLen = MSComm1。
InBufferCount
ReDim iData(intInputLen)
'16进制
iData = MSComm1。
Input
Dim j As Integer
For j = 0 To UBound(iData)
If Len(Hex(iData(j))) = 1 Then
strData = strData & "0" & Hex(iData(j))
Else
strData = strData & Hex(iData(j))
End If
Next
If Mid(strData, 1, 2) = "AA" Then
strData1 = Mid(strData, 1, 16)
Text1 = strData1
'请插入数据检验和处理等代码
strData = ""
End If
End Select
End Sub
。
收起