例如文本框里输入253chr(13)255chr(13),要求输出结果书“&HFD” "&HFF",看了好多算法,但是还是没有研究出来. 我自己做的结果如下 Private Sub Text2_KeyPress(KeyAscii As Integer) Dim tmp() As String Dim aa As String * 1 Dim rd As String Dim i As Integer Dim reload As Integer Dim response If pc_draw_flag = False Then MsgBox "请先选择路径规划功能,再进行路径规划!", vbOKOnly + vbInformation, "提示信息!" End If aa = Chr$(KeyAscii) If aa = Chr(13) And pc_draw_flag = True Then tmp = Split(Text2.Text, Chr(13)) '把目标数组按分隔符chr(13)分割 For i = 0 To UBound(tmp) 'UBound()取数组内元素的个数 rd = getnum(CStr(tmp(i))) Next i route(route_num) = "&H" & Hex(Val(rd)) route_num = route_num + 1Text8.Text = route_numIf route_num = 20 Then response = MsgBox("路径存储已达上限!是否重新规划?", vbYesNo + vbDefaultButton2 + vbInformation, "提示信息!") If response = vbYes Then route_num = 0 Else MsgBox "路径存储已完成,请点击发送按钮!", vbOKOnly + vbInformation, "提示信息!" End If End If ' MSComm1.Output = test End If End Sub 发送的 Private Sub CmdSend_Click() Dim bt(0 To 4) As Byte bt(0) = "&H" & "10" bt(1) = "&H" & "11" bt(2) = "&H" & "12" bt(3) = "&H" & "13" bt(4) = "&H" & "F6" If MSComm1.PortOpen = True Then If pc_draw_flag = True And OptSendHex.Value = True Then ' For i = 0 To 19 ' MSComm1.Output = "&H" & StrConv(Hex(route(i)), vbUpperCase) ' MSComm1.Output = bt MSComm1.Output = route(0) send_num = send_num + 1 Text7.Text = send_num ' Next i End If If Text2.Text = "" Or pc_draw_flag = False Then MsgBox "发送数据不能为空,请进行路径规划或输入字符!", vbOKOnly + vbInformation, "提示信息!" Else If OptSendHex.Value = True Then MSComm1.InputMode = comInputModeBinary MSComm1.InputLen = 0 Else MSComm1.InputMode = comInputModeText MSComm1.InputLen = 1 End If ' MSComm1.Output = Trim(Val(Text2.Text)) End If Else MsgBox "串口没有打开,请打开串口!", vbOKOnly + vbInformation, "提示信息!" End If route_num = 0 If pc_draw_flag = True And MSComm1.PortOpen = True And Text2.Text <> "" Then For i = 0 To 19 Text2.Text = Text2.Text & route(i) & " " If i = 19 Then Text2.Text = Text2.Text & Chr(13) & Chr(10) End If Next i End If End Sub 诸如此类形式的 bt(4) = "&H" & "F6"可以发送成功,检测也是好的,但是为什么我的生成的字符串 如输入255,显示的字符串&HFF,但是发送过去后不对,是把那个转换成了& H F F四个字符的ascii吗。。这是什么鬼。。 收起 | | | 0
If aa = Chr(13) And pc_draw_flag = True Then tmp = Split(Text2.Text, Chr(13)) '把目标数组按分隔符chr(13)分割 For i = 0 To UBound(tmp) 'UBound()取数组内元素的个数 rd = getnum(CStr(tmp(i))) Next i route(route_num) = "&H" & Hex(Val(rd)) route_num = route_num + 1 。。。。。。。 If MSComm1.PortOpen = True Then If pc_draw_flag = True And OptSendHex.Value = True Then ' For i = 0 To 19 ' MSComm1.Output = "&H" & StrConv(Hex(route(i)), vbUpperCase) ' MSComm1.Output = bt MSComm1.Output = route(0) send_num = send_num + 1 Text7.Text = send_num