0

I hope my question will not be strange or something like that but I started a project concerning dialog between an android terminal (currently a Samsung galaxy S2 but that may change) and an embedded-Linux based card (armadeus apf51-dev but maybe a raspberry pi in the future). Actually, I have an application on the android terminal that display the speed send by the Linux-embedded card via wireless connexion. The main objective is to change this wifi connexion by an USB connexion. My principal problem is to implement the android side of the pipe. I found this answer by FabianCook ( Transferring data USB ) :

UsbDevice dev = sDevice;
        if (dev == null)
            return;
        UsbManager usbm = (UsbManager) getSystemService(USB_SERVICE);
        UsbDeviceConnection conn = usbm.openDevice(dev);
        l("Interface Count: " + dev.getInterfaceCount());
        l("Using "
                + String.format("%04X:%04X", sDevice.getVendorId(),
                        sDevice.getProductId()));

        if (!conn.claimInterface(dev.getInterface(0), true))
            return;

        conn.controlTransfer(0x40, 0, 0, 0, null, 0, 0);// reset
                                                        // mConnection.controlTransfer(0×40,
                                                        // 0, 1, 0, null, 0,
                                                        // 0);//clear Rx
        conn.controlTransfer(0x40, 0, 2, 0, null, 0, 0);// clear Tx
        conn.controlTransfer(0x40, 0x02, 0x0000, 0, null, 0, 0);// flow
                                                                // control
                                                                // none
        conn.controlTransfer(0x40, 0x03, 0x0034, 0, null, 0, 0);// baudrate
                                                                // 57600
        conn.controlTransfer(0x40, 0x04, 0x0008, 0, null, 0, 0);// data bit
                                                                // 8, parity
                                                                // none,
                                                                // stop bit
                                                                // 1, tx off

        UsbEndpoint epIN = null;
        UsbEndpoint epOUT = null;

        byte counter = 0;

        UsbInterface usbIf = dev.getInterface(0);
        for (int i = 0; i < usbIf.getEndpointCount(); i++) {
            l("EP: "
                    + String.format("0x%02X", usbIf.getEndpoint(i)
                            .getAddress()));
            if (usbIf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
                l("Bulk Endpoint");
                if (usbIf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN)
                    epIN = usbIf.getEndpoint(i);
                else
                    epOUT = usbIf.getEndpoint(i);
            } else {
                l("Not Bulk");
            }
        }

This is very helpful but I don't understand what is the "sDevice" variable (line 1). I suppose it's an UsbDevice class instance but I don't know how this variable is instantiated. Maybe someone can indicate me the good way ?

Community
  • 1
  • 1
globox
  • 1

1 Answers1

0

To me it looks like sDevice may have been assigned somewhere else to be made available here, but the original assignment isn't in the sample code in the original thread - I'm not sure where that would have been instantiated but it should simply represent some connected device as the UsbDevice object.

sDevice would have originated from the UsbManager where you can get a list of connected devices with the getDeviceList() function

http://developer.android.com/reference/android/hardware/usb/UsbManager.html#getDeviceList()

Preston
  • 2,543
  • 1
  • 17
  • 26