0

AndroidホストAPIを使用してUSB通信デバイスと通信する必要があります

これは私が使用しているデバイスの情報です。

lsusb -v -d PID:VID

バス 003 デバイス 007: ID PIDVID VOTI

デバイス記述子:

bLength                18
bDescriptorType         1
bcdUSB               1.01
bDeviceClass            2 Communications
bDeviceSubClass         0 
bDeviceProtocol         0 
bMaxPacketSize0         8
idVendor              PID VOTI
idProduct             VID 
bcdDevice            1.00
iManufacturer           1 
iProduct                2 
iSerial                 0 
bNumConfigurations      1
Configuration Descriptor:
bLength                 9
bDescriptorType         2
wTotalLength           67
bNumInterfaces          2
bConfigurationValue     1
iConfiguration          0 
bmAttributes         0x80
(Bus Powered)
MaxPower              100mA

インターフェイス記述子:

  bLength                 9
  bDescriptorType         4
  bInterfaceNumber        0
  bAlternateSetting       0
  bNumEndpoints           1
  bInterfaceClass         2 Communications
  bInterfaceSubClass      2 Abstract (modem)
  bInterfaceProtocol      1 AT-commands (v.25ter)
  iInterface              0 
  CDC Header:
    bcdCDC               1.10
  CDC ACM:
    bmCapabilities       0x02
      line coding and serial state
  CDC Union:
    bMasterInterface        0
    bSlaveInterface         1 
  CDC Call Management:
    bmCapabilities       0x03
      call management
      use DataInterface
    bDataInterface          1

エンドポイント記述子:

    bLength                 7
    bDescriptorType         5
    bEndpointAddress     0x83  EP 3 IN
    bmAttributes            3
      Transfer Type            Interrupt
      Synch Type               None
      Usage Type               Data
    wMaxPacketSize     0x0008  1x 8 bytes
    bInterval             100

インターフェイス記述子:

  bLength                 9
  bDescriptorType         4
  bInterfaceNumber        1
  bAlternateSetting       0
  bNumEndpoints           2
  bInterfaceClass        10 CDC Data
  bInterfaceSubClass      0 Unused
  bInterfaceProtocol      0 
  iInterface              0 

エンドポイント記述子:

    bLength                 7
    bDescriptorType         5
    bEndpointAddress     0x01  EP 1 OUT
    bmAttributes            2
      Transfer Type            Bulk
      Synch Type               None
      Usage Type               Data
    wMaxPacketSize     0x0006  1x 6 bytes
    bInterval               0

エンドポイント記述子:

    bLength                 7
    bDescriptorType         5
    bEndpointAddress     0x81  EP 1 IN
    bmAttributes            2
      Transfer Type            Bulk
      Synch Type               None
      Usage Type               Data
    wMaxPacketSize     0x0008  1x 8 bytes
    bInterval               0

これで、デバイスを検出し、デバイスと通信する許可を得ることができます。しかし、bulkTransfer() 関数を使用してデバイスと通信しようとすると、常に -1 が返されます。

ここにコードがあります

UsbDeviceConnection conn = mUsbManager.openDevice(mDevice);

conn.controlTransfer(33, 34, 0, 0, null, 0, 0);

byte[] buffer = new byte[]{ (byte) 0x80,0x25, 0x00, 0x00, 0x00, 0x00, 0x08 };

conn.controlTransfer(33, 32, 0, 0, buffer , 7, 0);  //8N1, 9600 baud

conn.bulkTransfer(epOUT, new byte[]{msData}, 1, 0);

UsbEndpoint epIN = null;

UsbEndpoint epOUT = null;

UsbInterface usbIf = mDevice.getInterface(1);

for (int i = 0; i < usbIf.getEndpointCount(); i++) {

if (usbIf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {

    if (usbIf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN)

        epIN = usbIf.getEndpoint(i);
    else
        epOUT = usbIf.getEndpoint(i);
}
}

for (;;) {// this is the main loop for transferring

synchronized (sSendLock) {//ok there should be a OUT queue
    try {
        sSendLock.wait();
    } catch (InterruptedException e) {
        if (mStop) {
            mConnectionHandler.onUsbStopped();
            return;
        }
        e.printStackTrace();
    }
}
conn.bulkTransfer(epOUT, new byte[] { mData }, 1, 0);

    if (mStop) {
        mConnectionHandler.onUsbStopped();
        return;
    }
}
4

1 に答える 1

0

最初にこれを行う必要があることを私が知っている限り、あなたは claimInterface() を呼び出すようには見えません。何らかの理由でデバイスを作成できない場合、要求インターフェイスは失敗することにも注意してください。ハンドセットで irda インターフェイスを適切に登録するのに問題がありました。これは、irda の電力需要が原因でした。当時の私の質問を参照してください] 1

于 2012-10-09T00:31:53.107 に答える