android设备rs232数据格式,如何通过rs232 android进行串口通讯?(How to do serial communication via rs232 android?)...

如何通过rs232 android进行串口通讯?(How to do serial communication via rs232 android?)

我有一个Android设备'Micronet A317',它有rs232 44针串口。 我还有另一种设备,即具有9针D-pad连接器的读卡器。 我已经使用一些转换器将两个设备(Android和读卡器)相互连接。 现在我的任务是在这两个设备之间进行串行通信。 请建议我这样做。

I have an android device 'Micronet A317' which has rs232 44 pins serial port. I have also another device i.e a card reader which has 9 pin D-pad connector. I have connected both device(Android & Card Reader) with each other by using some converter. Now my task is to make serial communication between these two device. Please suggest me to do it.

原文:https://stackoverflow.com/questions/29633860

更新时间:2020-01-03 23:20

最满意答案

你可以使用usb-serial-for-android库通过Android上的串口传输数据。 我已经使用插入Nexus 7 USB端口的USB转串口适配器+ USB主机线测试了这个库。

您的RS232端口应在内部表示为USB设备,否则此库将无法工作。

您还需要知道您的串行适配器类型(FTDI / Prolific / CdcAcm)并将USB设备VID / PID添加到相应的驱动程序文件以运行getSupportedDevices()。

您可以通过从设备上的root shell运行cat /proc/kmsg ,或通过检查目录/sys/class/tty来找到您的串行适配器类型和VID / PID

You can use usb-serial-for-android library to transfer data via serial port on Android. I've tested this library with USB-to-serial adapter + USB-host cable plugged into Nexus 7 USB port.

Your RS232 port should be represented as USB device internally, otherwise this library won't work.

You will also need to know your serial adapter type (FTDI/Prolific/CdcAcm) and add USB device VID/PID to the appropriate driver file to function getSupportedDevices().

You can find out your serial adapter type and VID/PID by running cat /proc/kmsg from root shell on your device, or by inspecting directory /sys/class/tty

2015-04-14

相关问答

看看线条学科 。 您可以使用它将tty设备附加到内核空间中定义的某些读写例程,从而使用串行线写入驱动程序。 行规则从用户空间附加到它,内核将完成所有其余工作。 一个很好的例子是slcan (drivers / net / can / slcan.c)。 可以在can-utils( https://gitorious.org/linux-can/can-utils )中找到处理此问题的libc调用的示例。 如果您更喜欢按照本书第18章的方式工作,那么Linux设备驱动程序将提供良好的第一步: htt

...

如果您正在开发Windows,则com0com项目可能是您正在寻找的。 它提供了通过nullmodem连接链接的虚拟COM端口对。 然后,您可以使用您喜爱的终端应用程序或任何您喜欢的数据发送到一个COM端口,并从另一个COM端口接收。 编辑: 正如托马斯指出,该项目缺乏一个签名的驱动程序,这在某些Windows版本(例如Windows 7 x64)上特别有问题。 有几个非官方的com0com版本,包含一个签名的驱动程序。 最近的一个版本(3.0.0.0)可以从这里下载。 If you are de

...

Android 2.2 API没有USB主机功能。 在Android 3.1之前,主机功能尚未提供。 这意味着您无法在v2.2手机上编写可控制USB通信的Android程序。 我也猜测即使您确实更新了操作系统,手机也没有为总线供电所需的USB-A端口。 Android 2.2 API does not have USB host capabilities. Host capabilities was not made available until Android 3.1. This means

...

我用了几天,但我认为这只是一个30天的版本,所以你将不得不购买更长时间的使用... 然而,对我而言,不同的选择似乎相当不错,特别是因为你有不同的观点,取决于你想深入沟通的深度。 I used this for a couple of days, but I think it is only a 30 day version, so you would have to purchase it for longer use... However, the different options seeme

...

问题是RTS和DTR线的默认设置是高,所以我需要使用另一个setParams方法,并根据设备的需要将RTS线设置为false。 解: serialPort.setParams(9600, 8, 1, 0, false, true);

The problem was that the default setting of RTS and DTR line is High so i need to use another setParams method and set the RTS line t

...

你可以使用usb-serial-for-android库通过Android上的串口传输数据。 我已经使用插入Nexus 7 USB端口的USB转串口适配器+ USB主机线测试了这个库。 您的RS232端口应在内部表示为USB设备,否则此库将无法工作。 您还需要知道您的串行适配器类型(FTDI / Prolific / CdcAcm)并将USB设备VID / PID添加到相应的驱动程序文件以运行getSupportedDevices()。 您可以通过从设备上的root shell运行cat /pro

...

在意识到“Prolific和FTDI是竞争对手”后,我购买了Ftdi US232R-10 ,这是一款基于FT232R的设备,并规定了1 MBd的传输速率。 使用这个适配器,我成功通过传输一些GiB数据而无任何错误(包括使用Rts / Cts硬件流量控制),以1 MBd测试通信。 使用stty配置此设备,如下所示: $ stty -F /dev/ttyUSB0 1000000 raw

成功运作。 After the realization that »Prolific and FTDI are c

...

我们没有太多要继续下去,因为我们没有您正在与之通信的设备的文档,所以我们无法检查串口设置,或者您写入端口的4字节数据是要发送给它的正确消息。 由于您将握手设置为无,因此您可能希望将DtrEnable和RtsEnable设置为要发送的设备的真实典型设置。 检查可能是一个问题的另一件事是数据的“终结性”。 如果您发送的数据包含多字节值且一个设备是big-endian而另一个设备是little-endian,那么发送字节的顺序很重要,请参阅以下更详细的说明 。 不幸的是,它通常归结为尝试设置,甚至使用H

...

是的,waitForBytesWritten()不会解决这个问题。 只有你可以做的其他事情是在等待调用后休眠一段时间,从而给设备一些时间来处理你刚才写的命令。 究竟睡多长时间当然是盲目猜测,它不一定是常数。 首先关注启用握手,通常会经常忽略。 QSerialPort :: setFlowControl()函数。 一个不错的设备将使用其RTS信号关闭您的CTS输入(清除发送),当它还没有准备好接收任何东西时。 Qt支持CTS / RTS握手,您使用QSerialPort :: HardwareCon

...

您必须使用硬件解决方案。 像这样的东西。 鉴于它非常昂贵,您可以考虑使用Rasperry PI或甚至基于Arduino的解决方案。 You must use hardware solution. Something like this. Given it's quite expensive, you may consider looking at Rasperry PI or even Arduino-based solution.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值