通过串行通讯java发送数据包

编程入门 行业动态 更新时间:2024-10-25 11:20:28
本文介绍了通过串行通讯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.

请参阅:

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

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

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

希望有帮助.

更多推荐

通过串行通讯java发送数据包

本文发布于:2023-08-07 10:37:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1318660.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据包   通讯   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!