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

sending packets over serial comms java(通过串行通信 java 发送数据包)

本文介绍了通过串行通信 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);

...还是我走远了?

如果这真的很基本,我很抱歉..我以前从未处理过任何此类东西 &几天之内我将无法使用该设备.

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.

推荐答案

你应该看看Serial Line 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.

参见:

  • 滑动:https://www.rfc-editor.org/rfc/rfc1055
  • SlipMux:https://datatracker.ietf.org/doc/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 发送数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:通过串行通信 java 发送数据包

基础教程推荐