如何获取没有代码的字符串ascii

时间:2017-05-01 13:45:39

标签: vb.net serial-port

关于上面的图片我在机器中设置第一个变量“hello”  (SerialPort.Write()

  

02“0A”14“01hello”03

图片 *

然后我请求机器中的第一个变量(SerialPort.ReadExisting()

  

02“0B01”03

图片 *

输出

  

9୫1 A9୫01 hello9୫9୫2 A9୫01 hello9୫9୫3 A9୫01 hello9୫....

如果我点击按钮请求,在A之前编号,总是改变并按顺序排列,直到数字9

如何获得所需的字符串结果只是你好?

* 我无法发布图片,因为我需要至少10个声望来发布图片。

我使用的一些代码

Private Sub readMemoryButton_Click(sender As Object, e As EventArgs) Handles readMemoryButton.Click
    'copy
    'Received.AppendText("TX" & vbCrLf)        ' Switch to a new line after every transmission
    'SpaceCount = 0
    Dim TextString As String
    Dim TXArray(2047) As Byte
    Dim I As Integer
    Dim J As Integer = 0
    Dim Ascii As Boolean = False
    Dim Quote As Boolean = False
    Dim Temp As Boolean
    Dim Second As Boolean = False
    Dim TXByte As Byte = 0
    Dim CharByte As Byte
    If COMPort.IsOpen Then
        TextString = Received.Text
        For I = 0 To TextString.Length - 1
            CharByte = Asc(TextString.Chars(I))
            If CharByte = 34 Then ' If " Then
                Temp = Ascii
                Ascii = Ascii Or Quote
                Quote = Not (Temp And Quote)
            Else
                Ascii = Ascii Xor Quote
                Quote = False
            End If
            If Not Quote Then
                If Ascii Then
                    TXArray(J) = CharByte
                    J = J + 1
                Else
                    If (CharByte <> 32) And (CharByte <> 10) And (CharByte <> 13) Then ' Skip spaces, LF and CR
                        CharByte = (CharByte - 48) And 31 ' And 31 makes it case insensitive
                        If CharByte > 16 Then
                            CharByte = CharByte - 7
                        End If
                        If Second Then
                            TXArray(J) = TXByte + CharByte
                            Second = False
                            J = J + 1
                        Else
                            TXByte = CharByte << 4
                            Second = True
                        End If
                    End If
                End If
            End If
        Next
        Try
            COMPort.Write(TXArray, 0, J)
            Dim vLabelMemory As String = COMPort.ReadExisting()
            labelMemory.Text = vLabelMemory
        Catch ex As Exception
            MsgBox(ex.Message & "  Check CTS signal or set Flow Control to None.")
        End Try
    Else
        MsgBox("COM port is closed. Please select a COM port")
    End If

End Sub

0 个答案:

没有答案