Reply
Posts: 28
Registered: ‎04-27-2015

Cp2110 android controltransfer

[ Edited ]

Hello

I am developing an App fro cp2110

as i am using Android usb ControlTransfer to communicate with cp2110

in Get Version Information' with following details

bRequestType:0xA1 //10100001, Interface/Class/Device-to-host
bRequest:0x01 //GET_REPORT
wValue:0x0346 //Report type=Feature, and Report ID=IN
wIndex:0x0000 //Interface Number, 0
wLength:64 //Request the length required for the specified report, 64

i got 'F' from device

 

now can you tell me these values are correct or not

now i want to send command to Tx and receive  data from Rx

as requirement

bRequestType:0xA1 //10100001, Interface/Class/Device-to-host
bRequest:0x01 //GET_REPORT
wValue:0x01//Report type=Feature, and Report ID=IN
wIndex:0x21

wLength:64

 

 

i have read the HID1_11pdf but can't find the wValue and windex value for request

Posts: 28
Registered: ‎04-27-2015

cp2110 android controltransfer

Hello

I am developing an App fro cp2110

as i am using Android usb ControlTransfer to communicate with cp2110

in Get Version Information' with following details

bRequestType:0xA1 //10100001, Interface/Class/Device-to-host
bRequest:0x01 //GET_REPORT
wValue:0x0346 //Report type=Feature, and Report ID=IN
wIndex:0x0000 //Interface Number, 0
wLength:64 //Request the length required for the specified report, 64

i got 'F' from device

 

now can you tell me these values are correct or not

now i want to send command to Tx and receive  data from Rx

as requirement

bRequestType:0xA1 //10100001, Interface/Class/Device-to-host
bRequest:0x01 //GET_REPORT
wValue:0x01//Report type=Feature, and Report ID=IN
wIndex:0x21

wLength:64

 

 

and these values

Posts: 487
Registered: ‎02-04-2013

Re: cp2110 android controltransfer

Hi,

 

Your control transfer setup packet looks ok for the get version get feature report.  However, wLength should probably be 3 since you're expecting the report ID and two bytes back, although I believe you can specify a bigger value and return less data than requested.  0xF doesn't make sense as a response.  You should get report ID = 0x46 part number = 0xA and version = 0x1 (or higher if your device is newer).

 

See HID1_11 Section 7.2.1 Get_Report Request for setup packet values.

 

TX and RX reports are done over the interrupt IN/OUT endpoints, not control transfers.  You have to use a different function for transferring data via interrupt.

 

Best regards,

ChrisM

Posts: 28
Registered: ‎04-27-2015

Re: cp2110 android controltransfer

thanks for your  reply i am using
this-  
 int f= writeConnection.controlTransfer(0xA1, 0x01, 0x346, 0x0000, buffer2, 64, 0);
and i received 3 in variable 'f' and following
string str="reset="+f+" data="+new String(buffer2);
results in :-    reset=3 data=F (and next line feed)
Posts: 487
Registered: ‎02-04-2013

Re: cp2110 android controltransfer

Hi,

 

Yes, that makes sense.

 

According to controlTransfer() documentation:

http://developer.android.com/reference/android/hardware/usb/UsbDeviceConnection.html#controlTransfer... int, int, int, byte[], int, int)

 

The return value 3 is the number of bytes transferred (read 3).

 

buffer2 should contain the data.

 

'F' is 0x46, which is your report ID.  You can't convert an array of unsigned char to a string as most values are not ASCII.

 

Best regards,

ChrisM

Posts: 28
Registered: ‎04-27-2015

Re: cp2110 android controltransfer

thanks for your reply

i am using following command to transfer command

UsbInterface writeIntf = _usbDevice.getInterface(0);
UsbEndpoint writeEp = writeIntf.getEndpoint(1);
byte[] buffer = new String("x").getBytes() ;
 if (writeEp.getDirection() == UsbConstants.USB_DIR_OUT) {
  int r = writeConnection.bulkTransfer(writeEp, buffer, buffer.length, 1000);
}

this command return value 1 in variable 'r'

but when i am trying to read with following command i got nothing

 byte[] buffer1 = new byte[238];
 
	UsbEndpoint	readEp = writeIntf.getEndpoint(0);
        int byteCount = writeConnection.bulkTransfer(readEp, buffer1, buffer1.length, 1000);
Posts: 487
Registered: ‎02-04-2013

Re: cp2110 android controltransfer

According to this link:
http://developer.android.com/reference/android/hardware/usb/UsbRequest.html
 
"UsbRequests can be used to transfer data on bulk and interrupt endpoints. Requests on bulk endpoints can be sent synchronously via bulkTransfer(UsbEndpoint, byte[], int, int) or asynchronously via queue(ByteBuffer, int) and requestWait(). Requests on interrupt endpoints are only send and received asynchronously."
 
CP2110 transfers data via interrupt endpoints, not bulk endpoints.  You can't use bulkTransfer().
 
See this link for some ideas:
http://stackoverflow.com/questions/12345953/android-usb-host-asynchronous-interrupt-transfer
 
Best regards,
ChrisM

Highlighted
Posts: 28
Registered: ‎04-27-2015

Re: cp2110 android controltransfer

 public byte[] read(UsbRequest outRequest) throws UsbException {
        if (mUsbDeviceConnection == null) {
            throw new UsbException("no connection available");
        }
//
        ByteBuffer buffer = ByteBuffer.allocate(MAX_PACKAGE_SIZE);
//
//        // Receive data from device
//        if (outRequest.equals(mUsbDeviceConnection.requestWait())) {
            UsbRequest inRequest = new UsbRequest();
            inRequest.initialize(mUsbDeviceConnection, epIN);
            if (inRequest.queue(buffer, MAX_PACKAGE_SIZE)) {
                mUsbDeviceConnection.requestWait();
                return buffer.array();
            }
//        }
        return null;
    }

    
    public UsbRequest write(byte[] command) throws UsbException {
        if (mUsbDeviceConnection == null) {
            throw new UsbException("no connection available");
        }

        ByteBuffer buffer = ByteBuffer.allocate(MAX_PACKAGE_SIZE);

        UsbRequest outRequest = new UsbRequest();
        outRequest.initialize(mUsbDeviceConnection, epOUT);

        buffer.put(command);
        outRequest.queue(buffer, MAX_PACKAGE_SIZE);

        return outRequest;
    }

    /**
     * http://stackoverflow.com/questions/12345953/android-usb-host-asynchronous-interrupt-transfer
     *
     * Wrapper for CareLinkUsb.write() and CareLinkUsb.read()
     * @param command Byte[] containing the opcode for the command.
     * @return Returns a reference to the UsbRequest put in the output queue.
     * @throws UsbException
     */
    public byte[] sendCommand(byte[] command) throws UsbException {
 
        UsbRequest request = write(command);
        _textInfo.setText(_textInfo.getText()+"\n" +request );
        return read(request);
    }

while i am trying to get

outRequest.equals(mUsbDeviceConnection.requestWait())

 in read function application dosen't respond

otherwise i am received a blank array

following, how i am calling these function

byte b=(byte)'x';
            byte command[] = {b};

 byte[] result=   hidBr.sendCommand(command);
                 for(int i = 0; i < result.length; i++) {
                        log.append("buffer["+i+"] " + result[i]+"\n");
                    }
                textInfo.setText(textInfo.getText()+"\n "+result.length);
                 String result3 = new String(result, "US-ASCII");
                  textInfo.setText(textInfo.getText()+"\n "+result.toString()+"\n"+result3+"n");

please tell what is the mistake i am doing