通过串行通讯java发送数据包 [英] sending packets over serial comms java

查看:111
本文介绍了通过串行通讯java发送数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个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

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

这是我应该做的事情

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.

推荐答案

您应该查看串行IP"(SLIP),并发送不同于IP的数据包类型,请查看SLIPMUX,后者只是一个向后兼容的SLIP扩展.

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.

请参阅:

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

两者都很容易实现.即使不是Java,我也喜欢链接一个我最近写的实现: https://github.com/Lobaro/slip

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

希望有帮助.

这篇关于通过串行通讯java发送数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆