Sending Hex to serial port

I am trying to send a hex packet via serially, program looks like this

dim SerDataOut As String
SerDataOut = SendTextField1.Text

SendTextField1 is an text box that will be used to input the hex message.
I think using EncodeHex is just taking the hex number and converting it to a hex string.
As an example this hex message (54 03 01 00 00 00 00 00 A8) will turn on a LED on my demo board.
I know that the hex string is correct as I can use cool terminal and send hex and the light turns on.

When I run the code, the light does not light up.


Can you run in the debugger with this code?

dim SerDataOut As String
SerDataOut = SendTextField1.Text
dim data as string = DecodeHex(SerDataOut)) 
SerialConnection1.Write(data)  // set a breakpoint here in the debugger

In the debugger, inspect the value of ‘data’ - the Xojo debugger lets you view strings as strings or as raw byte data, which will let you confirm the data format is correct.

Edit to add:

You might also neeed
to make sure the data is actually sent?

You might also need an EndOfLine after the data.

Will give suggestions a try when I get time, as this is a side project that I wanted to do.

Couldn’t wait to test the flush command, it worked.

1 Like