Receiving HEX strings over TCP

Hi all.

I’m working on a project where I’m trying to interface an audio deck with Dashboard, and even though I’ve succeded on some parts there are still some issues which I cant manage to get my head around.

The deck transmitts commands as 16 byte HEX strings over TCP, and this little snippet show me that the memory buffer has received a command, and that there is data available to work on:

var bytes = event.getBytes(); // (data is beeing parsed further down the code)

ogscript.debug(bytes);

This works all fine with a command like this:

0X 03001102 00000020 10000000 00000000.

While a message like this: 0X 04001103 00000002 007A0000 00000000, will not be received or recognized.

Any ideas and hints would be highly appreciated!

Just want to be clear on this.

You’re saying your command is sending 16-byte HEX Strings over TCP. So, in your message below, you’re sending the ASCII Code for ‘0’, not the number 0?

So, in your above example, you would be encoding 16 bytes of data in 32 bytes of ASCII text?

If so, when you get your message from your listener (which should have a sync word of 3058 to sync on ‘0X’ and a fixed length delimiter with a length of 32 - assuming no spaces are actually sent), you should be able to get your message as a String with event.getBytesAsString() and parse each 2-byte pair as a single byte with parseInt([two characters from your string], 16);

Of course, it’s also entirely possible that I misinterpreted your encoding - so feel free to correct me/clarify.

James

#DashBoard

Hi James.

Oi. I realize now that the word “String” maybe was not the best.

What I’m sending is 16 bytes of data as HEX, so no ASCII encoding here, and no sync words.

A message like this will be accepted - and shown by Dashboard:

03001102000000201000000000000000

While a message like this will not:

0400110300000002007A000000000000

By using Wireshark I can confirm that the network card receives the command, but it’s will not appear in Dashboard.

Hopefully this will clarify a bit.

Regards, Ketil

#DashBoard

What are your settings for your listener tag?

#DashBoard

Try a backtick (beside the ‘1’ on a keyboard).

That will keep the form from hiding your code.

``

#DashBoard

  • Connect as client

  • Delimiter type: Fixed length

  • Delimiter Value: 16 byte pr. message

Edit: Need to experiment a little how to insert code…

Best/Ketil.

#DashBoard

DId this work?

`

}`

#DashBoard

Yup. That should work with the scenario you describe.

I just created a simple listener:

`

if (event.isMessageEvent())

{

var bytes = event.getBytes();

for (var i = 0; i < bytes.length; i++)

{

ogscript.debug('Byte ’ + i + ': ’ + bytes[i]);

}

}

`
And then two buttons to send your examples:

`

rosstalk.sendAsBytes(‘localhost’, 5445, ‘03 00 11 02 00 00 00 20 10 00 00 00 00 00 00 00’, null);

`

and

`

rosstalk.sendAsBytes(‘localhost’, 5445, ‘04 00 11 03 00 00 00 02 00 7A 00 00 00 00 00 00’, null);

`
Both messages were received and had their bytes written to the debug view.

#DashBoard

Just got your response.

Here is my same example and a server set up to do the same thing. Once again, 2 messages are received. There must be something else going wrong in your listener.

`

if (event.isMessageEvent())

{

var bytes = event.getBytes();

for (var i = 0; i < bytes.length; i++)

{

ogscript.debug('Byte ’ + i + ': ’ + bytes[i]);

}

}

if (event.isConnectEvent())

{

ogscript.debug(‘SEND MESSAGE 1’);

this.writeAsBytes(‘03 00 11 02 00 00 00 20 10 00 00 00 00 00 00 00’);

ogscript.debug(‘SEND MESSAGE 2’);

this.writeAsBytes(‘04 00 11 03 00 00 00 02 00 7A 00 00 00 00 00 00’);

}
`
#DashBoard

Many thanks James.

I will do some tests during the weekend.

#DashBoard