sending packets over serial comms java
Asked Answered
S

1

1

I'm writing a java application that communicates with an external device over a serial port.

I think I can connect to the device & send/receive data ok (I don't have access to the device at the moment..I'm using an emulator)

I just need some advice on how I should format the data I'm sending.

The spec says it should be sent in byte format..So if I have something like the following packet to send

AA|0D|07|09|0A|0B|03|01|02|03|04|CSM|CSM

is this the type of thing I should be doing

outputStream.write((byte)0xAA);
outputStream.write((byte)0x0D);
outputStream.write((byte)0x07);

...or am I way off?

I'm sorry if this is really basic..I've never dealt with any of this type stuff before & I won't be getting my hands on the device for a few days.

Sectarianism answered 12/2, 2015 at 1:52 Comment(1)
This is OK. You don't need the (byte) casts.Seventieth
S
1

You should take a look into "Serial Line IP" (SLIP) and to send different packet types than IP have a look at SLIPMUX, the latter is just a backward compatible extension to SLIP.

See:

Both are very easy to implement. Even it's not Java I like to link one Implementation I recently wrote: https://github.com/Lobaro/slip

Hope it helps.

Sotted answered 24/1, 2017 at 8:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.