次のような多数の投稿を検索しました: Android を使用して USB HID デバイスと通信する
しかし、私はまだ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
ご協力いただきありがとうございます。