sending packets over serial comms java

我是研究僧i 提交于 2019-11-28 11:28:39

问题


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.


回答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:

  • Slip: https://tools.ietf.org/html/rfc1055
  • SlipMux: https://tools.ietf.org/html/draft-bormann-t2trg-slipmux-00

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.



来源:https://stackoverflow.com/questions/28467950/sending-packets-over-serial-comms-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!