Salve,
sto facendo un programmino che comunica con un dispositivo via porta seriale.
Funziona bene la trasmissione da e verso...
Ora mi sono bloccata su un punto, riesco a fare una richiesta al dispositivo ed esso correttamente mi risponde, ed ho in esadecimale: FE FE 00 AA 00 11 22 FD.codice:Private Sub SerialPort_DataReceived(...) Handles SerialPort1.DataReceived Dim bytes As Integer = SerialPort1.BytesToRead 'create a byte array to hold the awaiting data Dim comBuffer As Byte() = New Byte(bytes - 1) {} 'read the data and store it SerialPort1.Read(comBuffer, 0, bytes) 'display the data to the user RichTextBox1.AppendText(ByteToHex(comBuffer)) Private Function ByteToHex(comByte As Byte()) As String 'create a new StringBuilder object Dim builder As New StringBuilder(comByte.Length * 3) 'loop through each byte in the array For Each data As Byte In comByte 'convert the byte to a string and add to the stringbuilder builder.Append(Convert.ToString(data, 16).PadLeft(2, "0"c).PadRight(3, " "c)) Next 'return the converted value Return builder.ToString().ToUpper() End Function
Io dovrei prendere dall'array solo AA 00 11 22, come faccio?

Rispondi quotando