UPDATE 2:
I have tested with FTDI chip by shorting its IN and OUT pins. The controlTransfer()
always returns 0, bulkTransfer() - Write
returns length of data sent and bulkTransfer() - Read
returns whatever data was sent.
Does anybody know how or where to find driver for Prolific?
UPDATE 1:
I did some more testing with Slick USB 2 and I think I have found my issue. It looks like I am missing some driver due to which the communication is not working.
I connect my board to Slick USB 2 and then tried to connect using my app and it printed "open device and claim: false, file = 45, test = null". I tried again and the communication started working. I was able to write and read data as expected. Also, when I reconnected the cable, the communication stopped working.
I guess, Slick USB 2 is installing some driver that is needed for communication.
Does anyone have any idea where or how can I find this driver?
I want my Android device (Galaxy Tab 2.0 7", version 4.0.3) to communicate with a custom board. For that, I am using OTG cable + USB to serial converter (Prolific).
I have tested the communication with Slick USB 2 app and everything works as expected.
Now, I am trying to create my own app using USB Host API. I have added intent-filter and when I connect my board, it is getting recognized as well. I am using the below code:
UsbDevice usbDevice; // contains device from intent-filter
Context context; // activity object
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
Toast.makeText(context, "usb device perm: " + manager.hasPermission(usbDevice), Toast.LENGTH_LONG).show();
UsbInterface interfaceUsb = usbDevice.getInterface(0);
UsbDeviceConnection connection = manager.openDevice(usbDevice);
boolean resClaim = connection.claimInterface(interfaceUsb, true);
Toast.makeText(context, "open device and claim: " + resClaim + ", file = " + connection.getFileDescriptor() + ", test = " + connection.getSerial(), Toast.LENGTH_LONG).show();
// Prints "open device and claim: true, file = 45, test = null"
int result = connection.controlTransfer(0x40, 0x03, 0x0034, 0, null, 0, 0); // set baudrate 57600
Toast.makeText(context, "result: " + result, Toast.LENGTH_LONG).show(); // returns -1
int resultWrite = connection.bulkTransfer(endpointUsbWrite, new byte[]{'a'}, 1, 1000);
byte[] bytesRead = new byte[64];
int resultRead = connection.bulkTransfer(endpointUsbRead, bytesRead, bytesRead.length, 1000);
// resultWrite returns 1, resultRead returns -1
The controlTransfer()
always returns -1. I have also tried bulkTransfer() - write
and that returns the length of the data sent but the board DOESN'T receive any data. bulkTransfer() - read
returns -1
I have done a test where I connected my board to my app and tried to connect in Slick USB 2 app and Slick USB 2 was able to connect to my board - this really shouldn't work. I think, I am not able to open the device properly.
What am I missing here? I have checked a number of threads but haven't been able to solve the issue. Can someone please suggest something?