【发布时间】:2014-06-23 20:18:43
【问题描述】:
我已经搜索过很多帖子,比如这个: Using Android to Communicate with a USB HID Device
但我仍然不知道您如何确定 controlTransfer 调用中的 requestType?
public int controlTransfer (int requestType, int request, int value, int index, byte[] buffer, int length, int timeout)
我需要为我的设备设置 EVEN 奇偶校验,但它似乎不起作用。 这是我的代码:
UsbDeviceConnection conn = mUsbManager.openDevice(mDevice);
l("Device opened...");
l("Trying to open interface on 0");
UsbInterface deviceInterface = mDevice.getInterface(0);
if (!conn.claimInterface(deviceInterface, true)) {
l("Could not claim interface on 0");
return;
}
int defaultDataBits = 8;
int config = defaultDataBits;
config |= (0x02 << 8); //even parity
config |= (0x00 << 11); //stop bits
conn.controlTransfer(0x40, 0, 0, 0, null, 0, 0);// reset
conn.controlTransfer(0x40, 0, 1, 0, null, 0, 0);// clear Rx
conn.controlTransfer(0x40, 0, 2, 0, null, 0, 0);// clear Tx
conn.controlTransfer(0x40, 0x04, config, 0, null, 0, 0);// set even parity
conn.controlTransfer(0x40, 0x03, 0x4138, 0, null, 0, 0);// set 9600 baud rate
requestType 0x40 对我来说没有任何意义,一些示例在 0x21 或 0x81 或 0xA1...
获得正确 requestType 的最佳方法是什么?
我还应该提到,我希望在 PC 上接收具有偶校验的数据,如果我将 PC 上的串行端口的奇偶校验设置为 NONE - 我会收到 预期的数据,所以我得出的结论是,我对设备进行的 controlTransfer 调用不起作用。
这是我尝试从 Android 配置的 USB 转串口设备:
Device Info
Device Path: /dev/bus/usb/001/002
Device Class: Use class information in the Interface Descriptors (0x0)
Vendor ID: 067b
Vendor Name: Prolific Technology, Inc.
Product ID: 03ea
Interfaces
Interface #0
Class: Vendor Specific (0xff)
Endpoint: #0
Address : 129 (10000001)
Number : 1
Direction : Inbound (0x80)
Type : Intrrupt (0x3)
Poll Interval : 1
Max Packet Size: 10
Attributes : 000000011
Endpoint: #1
Address : 2 (000000010)
Number : 2
Direction : Outbound (0x0)
Type : Bulk (0x2)
Poll Interval : 0
Max Packet Size: 64
Attributes : 000000010
Endpoint: #2
Address : 131 (10000011)
Number : 3
Direction : Inbound (0x80)
Type : Bulk (0x2)
Poll Interval : 0
Max Packet Size: 64
Attributes : 000000010
感谢您的帮助。
【问题讨论】:
标签: android serial-port usb usbserial parity