获取两个定界符之间的所有数据-字节

时间:2019-01-10 09:30:31

标签: vb.net

我正在尝试从串行口RS232读取数据,来自外部计算机的数据是分批接收的。一个完整的帧由带有[STX] [DLE] [.. Message ..] [ETX] [DLE]的消息组成。每秒发送一个完整的帧。我能够收集所有数据,但是现在我需要找到一种拆分和形成框架的方法,最终读取[STX] [DLE] ....之间的消息,以便我对其进行处理。请帮助。

Dim PortDataByte As New List(Of Byte)()      


Private Sub CommReceive(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles COMPort.DataReceived

    Dim SerialPort1 As SerialPort = CType(sender, SerialPort)

    Dim dataLength As Integer = SerialPort1.BytesToRead

    Dim data(dataLength) As Byte

    Dim nbrDataRead As Integer = SerialPort1.Read(data, 0, dataLength)


    PortDataByte.AddRange(data)

 end sub

0 个答案:

没有答案