Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

sending packets over serial comms java

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...