阅读和作家通过USB端口的数据在Android 3.1端口、作家、数据、USB

2023-09-05 01:01:44 作者:萌心菇凉i

我想写一个Android应用程序读取和写入从Android平板电脑数据,我们的嵌入式设备。在平板电脑和嵌入式设备通过USB转串口转换器连接。是否有可能读取来自嵌入式设备的数据到我们的Andr​​oid平板电脑?任何样品code,我可以看看?

I am trying to write an android app to read and write data from android tablet to our embedded device. The tablet and embedded device are connected via usb to serial converter. Is it possible to read data from the embedded device into our android tablet? Any sample code that I can take a look at?

推荐答案

作为一个串行转换器是一款USB 设备,Android平板具有充当USB 主机 。此功能是由于Android 3.1提供。 API文档可从 Android开发者页面,包括$ C $ Ç例子。

As a serial converter is a USB device, the android tablet has to act as a USB host. This feature is available since Android 3.1. The API documentation is available on the android developer page and includes code examples.

要真正与转换器通信,则必须找出一点关于它的内部:有,别人都在用USB CDC设备类的市场,一些使用USB HID在许多不同的设备或甚至不符合任何类。而linux的的lsusb 的命令可能会有所帮助来获得设备/接口描述符。

To actually communicate with the converter you will have to find out a bit more about it's internals: There are many different devices on the market, some using USB HID, others are using USB CDC device class or do not even comply to any class. The linux lsusb command might be helpful to get the device/interface descriptors.

在一个典型的CDC设备,你将有两个批量端点交互,并可能使用一些界面相关的要求来设置波特率等见通信设备类规范上的 USB实施者论坛。

On a typical CDC device you will have to interact with two bulk endpoints and probably use some interface related requests to setup the baudrate, etc. See the Communication Device Class specification on USB implementers forum.

如果您的设备有且只有一个,一个OUT批量端点(控制端点旁),你可以尝试使用上OUT端点的UsbDeviceConnection.bulkTransfer()方法来写一些字节串行线路。有一个很好的机会,这只是工作,但是一个干净的实施,你应该坚持类规范。

If your device has only one IN and one OUT bulk endpoint (beside the control endpoint) you might try to use the UsbDeviceConnection.bulkTransfer() method on the OUT endpoint to write some bytes to the serial line. There is a good chance this will just work, however for a clean implementation you should stick to the class specification.