如题。
十六进制数0xab对应的十进制数是171
超出了128。
我想叫对方的串口助手收到HEX显示的ab
应该怎么发送啊
MSComm1.Output = Chr("171")
这样不对。
好着急啊,请大家帮忙!

解决方案 »

  1.   

    用数组
    dim A(0) as Byte
    A(0)=&HAB
    MSComm1.Output=A
      

  2.   

    Option Explicit
        Dim sendHex() As BytePrivate Sub Command1_Click()
        ReDim sendHex(0)
        sendHex(0) = &HAB
        MSComm1.Output = sendHex
    End SubPrivate Sub Form_Load()
        MSComm1.CommPort = 1
        MSComm1.Settings = "9600,n.8,1"
        MSComm1.PortOpen = True
    End Sub或者:
    Option Explicit
        Dim sendHex() As BytePrivate Sub Command1_Click()
        ReDim sendHex(0)
        sendHex(0) = 171
        MSComm1.Output = sendHex
    End SubPrivate Sub Form_Load()
        MSComm1.CommPort = 1
        MSComm1.Settings = "9600,n.8,1"
        MSComm1.PortOpen = True
    End Sub
      

  3.   

    谢谢了。
    要是我要发一串呢
    AB 01 01 00 00 00 00 BA
    不会要定义那么多个变量吧
      

  4.   

    Option Explicit
        Dim sendHex() As BytePrivate Sub Command1_Click()
        ReDim sendHex(1 to 8)
        sendHex(1) = &HAB
        sendHex(2) = &H1
        sendHex(3) = &H0
        sendHex(4) = &H0
        sendHex(5) = &H0
        sendHex(6) = &H0
        sendHex(7) = &H0
        sendHex(8) = &HBA
        MSComm1.Output = sendHex
    End SubPrivate Sub Form_Load()
        MSComm1.CommPort = 1
        MSComm1.Settings = "9600,n.8,1"
        MSComm1.PortOpen = True
    End Sub
      

  5.   

    错了1字节,修正:
    Option Explicit
        Dim sendHex() As BytePrivate Sub Command1_Click()
        ReDim sendHex(1 to 8)
        sendHex(1) = &HAB
        sendHex(2) = &H1
        sendHex(3) = &H1
        sendHex(4) = &H0
        sendHex(5) = &H0
        sendHex(6) = &H0
        sendHex(7) = &H0
        sendHex(8) = &HBA
        MSComm1.Output = sendHex
    End SubPrivate Sub Form_Load()
        MSComm1.CommPort = 1
        MSComm1.Settings = "9600,n.8,1"
        MSComm1.PortOpen = True
    End Sub