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

2024-08-24Java开发问题
0

本文介绍了通过串行通信 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 发送数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13