B4A Library PL2303 USB to RS232 adaptor driver

This is a driver for PL2303 based USB to RS232 adaptors. The PL2303 is a chip produced by Prolific Technology Inc. of Taiwan and is a very common chip to find in such adaptors. The driver requires version 0.92 or later of the USB Host library and needs a Honeycomb 3.1 or later device with USB host support .

This driver is not up to the standard that I would normally expect of myself. However it is unavoidably crippled by problems with the Android implementation of USB support and has been produced by reverse engineering a Linux driver as Prolific only provide chip operation details to their OEMs and do not publish an operation manual. Erel has suggested that I post it anyway as it is probably usable in at least some situations.

The specific problems that beset the Android USB support concern data transfer. There are two ways to transfer data in and out, asynchronously by queueing Requests and synchronously using the BulkTransfer method. Of the four possibilities two are broken in Android. Asynchronous reads will transfer fixed length arrays of data but there is no way of telling you how many bytes of the returned arrays contain valid data! I have also found a problem with synchronous writes. BlockTransfer is supposed to return a value of how many bytes it has written, or a -ve number if a fault occurred. However I was getting return values of -1 even though the data has been successfully sent! So we have a USB implementation that can't tell you how many bytes you have received nor how many bytes you have sent! :(

This driver implementation therefore has to use asynchronous writes and synchronous reads invoked by a Timer in order to provide some semblance of functionality. The use of synchronous reads limits the data rates that can be reliably supported without dropping data. If you have a PL2303 based adaptor then have a play yourself.
 

Attachments

  • USBpl2303_1.0.zip
    12.2 KB · Views: 2,264

hdtvirl

Active Member
Licensed User
thanks for this Driver

Andrew thanks for this I have been looking for this for a while, would it be difficult to rewrite the driver for the FTdi. chip as they do provide documentation. I am sure you have seen this Linux C source Linux/drivers/usb/serial/pl2303.c - Linux Cross Reference - Free Electrons

Are all the issues you describe an Android problem or if you had the prolific documentation could the problems be overcome ?


Thanks and Regards


BOB
 

agraham

Expert
Licensed User
That Linux driver is the one I used as a reference and is the only documentation I could find on the PL2303.

The major issues are with the Android host mode USB implementation. I don't know about accessory mode support as I haven't tried that but it is very much simpler so maybe they got that right.

There is just one 2303 quirk that proper documentation might resolve. Because the 2303 status byte is only sent in response to a status change it requires DCD or CTS to change or an error to occur before the actual status is available. I don't know of a way to prod the 2303 to actually transmit the status in order to set the initial state, documentation might provide that.

I don't have anything with an FTDI chip. I know Erel has some hardware on order, maybe he will be looking at that.
 

hdtvirl

Active Member
Licensed User
Pl2303

Andrew, I have just been reading a blog about PL2303 drivers, from a guy who wrote a driver some time ago, he developed a DLL wedge to monitor the traffic between a USB device and the host (I assume a windows based PC).

He has posted his code also, my 'C' is a bit rusty now and I have not compared the two sources.

http://www.madingley.org/james/resources/pl2303/pl2303.c

There is a reference to RTS and CTS in the source.

I have some FTDI documentation somewhere which I could send to you.
I only used it to reveiw the FTDI capabilities in a hardware design in a piece of hardware we were looking to use.

Regards

BOB
 

msemih2011

Member
Licensed User
This is a driver for PL2303 based USB to RS232 adaptors. The PL2303 is a chip produced by Prolific Technology Inc. of Taiwan and is a very common chip to find in such adaptors. The driver requires version 0.92 or later of the USB Host library and needs a Honeycomb 3.1 or later device with USB host support .

This driver is not up to the standard that I would normally expect of myself. However it is unavoidably crippled by problems with the Android implementation of USB support and has been produced by reverse engineering a Linux driver as Prolific only provide chip operation details to their OEMs and do not publish an operation manual. Erel has suggested that I post it anyway as it is probably usable in at least some situations.

The specific problems that beset the Android USB support concern data transfer. There are two ways to transfer data in and out, asynchronously by queueing Requests and synchronously using the BulkTransfer method. Of the four possibilities two are broken in Android. Asynchronous reads will transfer fixed length arrays of data but there is no way of telling you how many bytes of the returned arrays contain valid data! I have also found a problem with synchronous writes. BlockTransfer is supposed to return a value of how many bytes it has written, or a -ve number if a fault occurred. However I was getting return values of -1 even though the data has been successfully sent! So we have a USB implementation that can't tell you how many bytes you have received nor how many bytes you have sent! :(

This driver implementation therefore has to use asynchronous writes and synchronous reads invoked by a Timer in order to provide some semblance of functionality. The use of synchronous reads limits the data rates that can be reliably supported without dropping data. If you have a PL2303 based adaptor then have a play yourself.

Compiling code. Error
Error parsing program.
Error description: Verilen anahtar sözlükte yoktu.
Occurred on line: 89
Sub SendIntRequest

?????
 

hdtvirl

Active Member
Licensed User
End of !

Andrew, no answer to that one !.

Thank you for the Library you have put so much work into.

Regards

BOB
 

agraham

Expert
Licensed User
Sorry, I felt a bit ratty last night and it showed. Apart from not being able to obtain the initial status the PL2303 part of the library is fine. The limitation is the Android implementation of USB host which does not properly handle asynchronous transfers forcing the library to do it synchronously and making it susceptible to data loss on higher speed lines. I can do nothing about that.
 

msemih2011

Member
Licensed User
Nice work but

Android 2.2 version I'm using a tablet, but I can not use a lower version, PL2303 driver What are my chances of finding a working driver.
 

hdtvirl

Active Member
Licensed User
which tablet

I have it running on the Acer iconia, it worked with Android 3.1 and also with 3.2 I have a USB GPS receiver which has the prolific chip as its serial port and it is working fine at 4800 baud, I am going to connect some equipment which output 16 chars + crlf every 100ms at 38400 Baud and it will be interesting to see if it will handle that baud speed I am going to let it run for a couple of hours and write out output to a text file which I can check on a PC to see if any data has been lost, I will let you know the results.

Regards

BOB
 
Top