首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

怎么用mscomm控件发送长度超过128字节的16进制数据(串口)

2012-01-03 
如何用mscomm控件发送长度超过128字节的16进制数据(串口)请问如何用mscomm控件发送长度超过128字节的16进

如何用mscomm控件发送长度超过128字节的16进制数据(串口)
请问如何用mscomm控件发送长度超过128字节的16进制数据(串口),如以下:

68 A1 A1 68 02 00 5C 32 03 00 00 00 01 00 02 00 90 00 00 1B 00 00 8C 00 FB 70 70 00 00 13 0B 00 00 00 00 00 8C 00 00 00 00 02 9F C2 EC 23 A9 02 9F 80 D0 23 A9 00 00 00 00 00 00 00 68 04 03 00 02 0E 06 00 00 10 02 10 00 00 01 84 00 00 00 0E 06 01 00 10 02 00 00 00 01 84 00 00 00 0E 06 02 00 10 1F 00 20 00 00 1F 00 00 00 0E 06 03 00 10 1F 00 20 00 00 1F 00 00 40 0E 06 04 00 10 1E 00 80 00 00 1E 00 00 00 0E 06 05 00 10 02 00 12 00 00 83 00 00 70 04 0E 66 66 0C 0F 40 03 9B 98 02 06 9D 9A 00 08 15 16 

共167个字节,在使用mscomm控件发送以上字节后返回的数据不对,其它小于128个字节的则可正常接收,我用的是vb编程,请教各位高手该如何发送。

[解决办法]

VB code
Option Explicit    Dim strData As String    Dim byteSEnd() As Byte    Dim strHex As StringPrivate Sub Command1_Click()    Dim i As Integer    strHex = "68 A1 A1 68 02 00 5C 32 03 00 00 00 01 00 02 00 90 00 00 1B 00 00 8C 00 FB 70 70 00 00 13 0B 00 00 00 00 00 8C 00 00 00 00 02 9F C2 EC 23 A9 02 9F 80 D0 23 A9 00 00 00 00 00 00 00 68 04 03 00 02 0E 06 00 00 10 02 10 00 00 01 84 00 00 00 0E 06 01 00 10 02 00 00 00 01 84 00 00 00 0E 06 02 00 10 1F 00 20 00 00 1F 00 00 00 0E 06 03 00 10 1F 00 20 00 00 1F 00 00 40 0E 06 04 00 10 1E 00 80 00 00 1E 00 00 00 0E 06 05 00 10 02 00 12 00 00 83 00 00 70 04 0E 66 66 0C 0F 40 03 9B 98 02 06 9D 9A 00 08 15 16 "    ReDim byteSEnd(Len(strHex) \ 3)    Text1 = Len(strHex)    For i = 1 To Len(strHex) Step 3        byteSEnd((i - 2) / 3) = Val("&H" & Mid(strHex, i, 3))    Next    MSComm1.Output = byteSEndEnd SubPrivate Sub Form_Load()    MSComm1.CommPort = 1    MSComm1.Settings = "9600,n,8,1"    MSComm1.InBufferCount = 0    MSComm1.InputLen = 0    MSComm1.RThreshold = 1    MSComm1.InputMode = comInputModeBinary '以2进制接收    MSComm1.PortOpen = TrueEnd SubPrivate Sub MSComm1_OnComm()    Dim inByte() As Byte    Dim i As Integer    Select Case MSComm1.CommEvent        Case comEvReceive        inByte = MSComm1.Input        For i = 0 To UBound(inByte)        If Len(Hex(inByte(i))) = 1 Then            strData = strData & "0" & Hex(inByte(i))        Else            strData = strData & Hex(inByte(i))        End If        Next        Text1.Text = strData        '以下写符合通信协议规定的判断代码处理接收数据     End SelectEnd Sub 

热点排行