请VB高手帮帮忙 非常急

2024-12-18 01:35:06
推荐回答(2个)
回答1:

Option Explicit
Dim byteInput() As Byte
Dim strdata, c, a() As String
Dim BytReceived() As Byte
Dim strBuff, b As String

Dim j As Integer, e As String

Private Sub Command1_Click()'向客户端发送的命令
'MSComm1.OutBufferCount = 0 '...清空输出寄存器
Dim a(0 To 3) As Byte
a(0) = &H44
a(1) = &H51
a(2) = &H44
a(3) = &HD
MSComm1.Output = a
End Sub

Private Sub Command13_Click()'清空按钮
Dim bbb As String
bbb = ""
strBuff = bbb
strdata = bbb
b = bbb
c = bbb
e = bbb
Text1.Text = ""
End Sub

Private Sub Command2_Click()'向客户端发送的命令
MSComm1.OutBufferCount = 0 '...清空输出寄存器
Dim a(0 To 3) As Byte
a(0) = &H44
a(1) = &H51
a(2) = &H48
a(3) = &HD

MSComm1.Output = a

End Sub

Private Sub Command3_Click()'向客户端发送的命令
MSComm1.OutBufferCount = 0 '...清空输出寄存器
Dim a(0 To 3) As Byte
a(0) = &H44
a(1) = &H51
a(2) = &H4D
a(3) = &HD
MSComm1.Output = a

End Sub

Private Sub Command4_Click()'向客户端发送的命令
MSComm1.OutBufferCount = 0 '...清空输出寄存器
Dim a(0 To 3) As Byte
a(0) = &H44
a(1) = &H51
a(2) = &H53
a(3) = &HD
MSComm1.Output = a

End Sub
Private Sub Form_Load() '窗体载入事件
'Timer1.Interval = 1000
'Timer1.Enabled = True

MSComm1.CommPort = 1 '...使用Com1口
MSComm1.InBufferSize = 1024 '"设置接收缓冲区的字节长度
MSComm1.InputMode = 1 '"输入模式为binary
MSComm1.RThreshold = 1 '"控件收到数据时将触发OnComm事件
MSComm1.Settings = "4800,n,8,1" '...设置通讯参数
MSComm1.InBufferSize = 1024 '"设置接收缓冲区的字节长度
' MSComm1.PortOpen = True '...打开串口
MSComm1.InputLen = 1 '"读取input接收缓冲区全部字节
End Sub

Private Sub MSComm1_OnComm() '有数据传送时触发
Dim strBuff, b As String

Dim j As Integer, e As String

Dim i As Integer

Select Case MSComm1.CommEvent

Case comEvReceive '...有接受事件发生

'indata = MSComm1.Input

'...注意!要通过MSComm控件发送或接收二进制数据必须用Variant类型的变量对二进

'...制Byte类型的变量进行转换!

'bte = AscB(indata)
MSComm1.InputLen = 0
strBuff = MSComm1.Input
BytReceived() = strBuff
jieshou

For i = 1 To Len(strdata) Step 2
b = b & Mid(strdata, i, 2) & " "
Next
c = Trim(b)
a = Split(c)
For j = LBound(a) To UBound(a)
e = e & Chr(CDec("&H" & a(j)))
Next

Text1.Text = vbCrLf & e
'Text1.Text = e
MSComm1.InBufferCount = 0 ' 清空接收缓冲区
End Select
End Sub

Public Function jieshou() '接收数据处理为16进制
Dim i As Integer

For i = 0 To UBound(BytReceived)

If Len(Hex(BytReceived(i))) = 1 Then

strdata = strdata & "0" & Hex(BytReceived(i))

Else

strdata = strdata & Hex(BytReceived(i))

End If

Next

End Function
这样改你试试看

回答2:

好象是GPS导航一类的,自己调式啦.光拼凑是不够的.
我看了一遍.