Android:与Android设备的RS232串行通信

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26464320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:32:01  来源:igfitidea点击:

Android: RS232 Serial Communication with android device

androidserial-portusbserialusb-hostcontroller

提问by ishan jain

I have a MR400s taximeterhardware. I want to communicate with this taximeter using RS232 cable and I have already achieved this connection and communication in windows. But I wanted to make connection using android device.

我有一个MR400s 计价器硬件。我想使用 RS232 电缆与此计价器通信,并且我已经在 Windows 中实现了这种连接和通信。但我想使用 android 设备建立连接。

How can I achieve this?

我怎样才能做到这一点?

Thanks Ishan jain

谢谢伊山·贾恩

回答by Frank D.

I use the USB to serial library, you can find it here: USB Serial for Android.It doesn't require any root access. You'll need to check if your Android device supports USB host mode. Then, using a usb OTG cable and a USB to serial adapter cable you can start communicating with your serial device via RS232. There are code examples to get you started on the Github page of the USB to Serial library.

我使用 USB 转串口库,你可以在这里找到它:USB Serial for Android。它不需要任何根访问权限。您需要检查您的 Android 设备是否支持 USB 主机模式。然后,使用 USB OTG 电缆和 USB 转串行适配器电缆,您可以开始通过 RS232 与串行设备通信。在 USB 转串口库的 Github 页面上有一些代码示例可以帮助您入门。

回答by tanius

An alternative to a cable connection to the Android device (using the "USB Serial for Android" library, see the other answer) is a converter from RS232 to Bluetooth.

电缆连接到 Android 设备的替代方法(使用“USB Serial for Android”库,请参阅另一个答案)是从 RS232 到蓝牙转换器

Such a converter will use the serial connection profile of Bluetooth, and ways access such a connection in Android are discussed in this question.

这样的转换器将使用蓝牙的串行连接配置文件,本问题讨论了在 Android 中访问此类连接的方法。

You can build such a converter based on an Arduino by adding a Bluetooth shield and simple code that converts incoming data from the serial port to outgoing data on the Bluetooth connection. (I could not find detailed instructions for this right now.) When you want to connect the Arduino's serial port to a RS232 device you would need another shield for logic level conversion (RS232 is ±12 V, Arduino is 5 V or 3.3 V).

您可以通过添加蓝牙扩展板和简单的代码来构建基于 Arduino 的转换器,该代码将来自串行端口的传入数据转换为蓝牙连接上的传出数据。(我现在找不到详细说明。)当您想将 Arduino 的串行端口连接到 RS232 设备时,您需要另一个用于逻辑电平转换的屏蔽(RS232 为 ±12 V,Arduino 为 5 V 或 3.3 V) .

There is also a commercial product implementing this Photologic Text Streamer(ca. 265 USD !!!). It seems that this provides a read-only connection for Android (not totally sure about that, though). A read-only connection is still ok for cases where you only want to read sensor values.

还有一个商业产品实现了这个Photologic Text Streamer(大约 265 美元!!!)。似乎这为 Android 提供了只读连接(不过并不完全确定)。对于您只想读取传感器值的情况,只读连接仍然可以。

Finally, you could do a similar thing using an Arduino and a wifi shield.

最后,您可以使用 Arduino 和 wifi 扩展板做类似的事情。