How do I send serial Hex/binary data

9 replies [Last post]
paulsbiz
Offline
Rugby, United Kingdom
Joined: 19 Apr 2012

Hi,

I'm writing a script to communicate with a serial device.

Using data=somedata in the XAP serial schema works as expected and I see "somedata" received on the serial port but I need to send hex/binary data. 

The XAP protocol suggests that ! in place of = would allow hexadecimal data to be sent so I've tried using data!0AB123F for example but this appears to get removed from the XAP message (or isn't displayed by the XFX message viewer) and no serial data is generated.

Is hex serial data not supported or am I missing something? 

Paul

brett
Offline
Providence, United States
Joined: 9 Jan 2010
I had to re-read the xAP

I had to re-read the xAP specification as I'd not run into the (!) character in this usage.

http://www.xapautomation.org/index.php?title=Protocol_definition#Message...

Wow what do you know this is part of the specification.  Well unfortunately the xaplib library that I wrote doesn't know how to do this.  As this is a quite a low level change I'd need to rework a few bits to enable this and make sure I don't break EVERYTHING in the process.

What you can do thou is use OCTAL just like you would in a C string to send binary data.

data=\027\177  etc..  this I've have coded for.

Unfortunately it does not have the HEX encoding but adding handling for \xFF and \x1B would not be too hard to do.  Certainly easier then putting in (!) exclamation mark support.  I'll add this too.

update: http://www.dbzoo.com/livebox/xap_serial?&#output_messages

I amended the wiki page to document this. 

Brett

brett
Offline
Providence, United States
Joined: 9 Jan 2010
I've added support for HEX in

I've added support for HEX in the data key for the xap-serial component this will be in the next release (build 307).  The sytnax will be like this

Serial.Send
{
port=/dev/ttyUSB0
data=\x7b\x42\x72\x65\x74\x74\x7d
}

Brett

paulsbiz
Offline
Rugby, United Kingdom
Joined: 19 Apr 2012
Thanks for the quick response

Thanks for the quick response Brett.

I tried using Octal as suggested (it brought back memories of the 70's which was the last time I used Octal on an 18 bit computer). This nearly works but appears to stop sending data after encountering a byte of zero value (/000). As the data I need to send includes some null bytes is there a way round this?

Paul

brett
Offline
Providence, United States
Joined: 9 Jan 2010
I knew that would happen -

I knew that would happen - there is no workaround I'd need to modify the internals to store the LENGTH of the data transmission instead of using the NUL terminator on the string.  *sigh*

UPDATE: I've just fixed the code I've uploaded BETA 306.2 for you to try out this will handle a NULL plus it has the HEX support that I mentioned in my earlier post.  Much easier than dealing with Octal.

Grab the beta and let me know how that goes for you.

# /etc_ro_fs/update-dev hah-beta.dbzoo.com

Brett

paulsbiz
Offline
Rugby, United Kingdom
Joined: 19 Apr 2012
I've uploaded the Beta and

I've uploaded the Beta and have some results.

The Octal handling is now OK with nulls so that provides a workable solution :-)

The Hex handling gives an 'odd' result unless it's me :-(

I'm using the following data=\x0D\x01\x02\x00\x10\xF0\xFF

The resulting data generated is 0D FA FB 00 00 00 0F

Paul

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Er yeah I screwed up a couple

Er yeah I screwed up a couple of things.   Fixed in 306.3 unless of course you are enjoying octal so much.

Brett

paulsbiz
Offline
Rugby, United Kingdom
Joined: 19 Apr 2012
Is 306.3 available yet as I

Is 306.3 available yet as I still see 306.2.

Let me know and I'll try it in Hex as I don't enjoy Octal that much :-)

Paul

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Paul 306.3 is now available -

Paul 306.3 is now available - that should get you out of your octal funk.

paulsbiz
Offline
Rugby, United Kingdom
Joined: 19 Apr 2012
I can confirm it works fine.I

I can confirm it works fine.

I can now get back to my normal mode of thinking in Hex :-)

Thanks for your great support. Much appreciated.

Paul

Hardware Info