4
votes

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?

1
Can you post the code where you tried a bulktransfer? It's tough to guess at this without more context.sarwar
@sarwar I have updated my codeuser427969
Assuming you got the endpoints right, I don't have much to add besides this; I've never had the integer value of a bulk transfer read or write be correct. Never. I have no idea why and now I don't trust it. Good luck. Check the docs for your device, look again to see if anyone has any working code for android anywhere on google; if not, have a beer and start again tomorrow.sarwar
Thanks as per my update, my code works fine. I am missing some sort of driver.user427969

1 Answers

0
votes

Prolific has developped Android SDK for PL2303. You may download and try from: https://play.google.com/store/apps/details?id=tw.com.prolific.app.pl2303terminal

You can also get support from Prolific's official website..