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,874

hdtvirl

Active Member
Licensed User
Longtime User
Update on using the PL2303 USB Driver with B4A.

I have now tested the driver with a RS232 source which transmit 27 characters every 10th of a second, I have tested it 9600/38400 baud no problems found, I am writing the RX Data out to a textbox, it goes a bit a skew ways displaying the data but I think this might have to do with way data is being displayed with no formating.

I am going to write a small app to 'Parse' the Data using regex and write a log file out with every line received on the Tablet, I can then check this out on an Application I have written on the PC to check such logs for missing data. As each line has a sequencial Index at the start.

I am using the Acer Iconia 500 with two USB ports one connected to the PC and the other to a USB to Serial Converter and have no problems here either.

It would be nice to do async streams with this data from the PL2303 Usb to Serial Converter.

It is very exciting to get the RS232 ports running as this now open the Android tablet to used for Data Logging, the only concern being powering the Converter from the Tablet, it will drain the abttery faster. I have used HP Ipaq's in the past for similar applications and used a Solar Panel to power them and trickle charge the batteries when the devices were asleep.

I will report back on my findings if anybody is interested.

Once again Andrew thanks for your great work on this.

Regards

BOB.
 

bitstra

Member
Licensed User
Longtime User
PL2303 USB GPS Stick working :)

Hi agraham,

thank you for the pahantastic work on this driver!

I've adopted your sources to make a NAVILOCK usb-GPS-stick working.
It's perfect setted on 38400 baud...

It's working really great on a POV MOBII under VeagICS!
By workin in prograss I've added a mock-location-server lib (self made java lib).
And made a switch-to-usb-host-mode-routine in addition.

Now I can use gps-connected apps on my device, having accurate locations.

So if you or anyone other is interested in further informations let me know it.

thanx for your great job

regards

bitstra
 

micro

Well-Known Member
Licensed User
Longtime User
PL2303 not recognized

Hio to all,
I have a C91 tablet with Android 4.0, I put a PL2303 device into the USB socket but is not recognized.
manager.GetDevice returns empty.
I have plugged into the USB socket where usually I insert pendrive, keyboard etc.. and everything works perfectly.
What can be?
Thanks
 

micro

Well-Known Member
Licensed User
Longtime User
but they are just the PL2303!
a question:
but if I have a keyboard connected into the USB socket, manager.GetDevice return a device connected?
Because manager.GetDevice return always empty, also if keyboard works fine.
 
  • Like
Reactions: Del

micro

Well-Known Member
Licensed User
Longtime User
certainly, but it is possible that four of pl2303 USB-adapter (different manufacturers) no one is recognized?
Any device connected is not recognized.
What can be?
 

AndyW999

Member
Licensed User
Longtime User
Missing 067b_2303 file?

Hi Andrew

Am trying your PL2303 USB driver on my Eken T02A Android 4 tablet.

Looking at the log when I connect my PL2303 and press the application Open button I get :-

event { 'add', '/devices/platform/sw_hcd_host0/usb1/1-1', 'usb', '', 189, 9 }
path : '/sys/devices/platform/sw_hcd_host0/usb1/1-1'
VID :size 5,vid_path '/sys/devices/platform/sw_hcd_host0/usb1/1-1/idVendor',VID '067b
'.
PID :size 5,Pid_path '/sys/devices/platform/sw_hcd_host0/usb1/1-1/idProduct',PID '2303
'.
cmd=/system/etc/usb_modeswitch.sh /system/etc/usb_modeswitch.d/067b_2303 &,
excute ret : 0,err:No such file or directory


As I do not seem to have a 067b_2303 file!

Do you have any suggestions?

Thanks

Andy.
 

AndyW999

Member
Licensed User
Longtime User
Looks to me that it gets the vendor and product ID of the device connected and then uses usb_modeswitch.sh to run a file [VID]_[PID]

Can you have a look on your machine and see if it does it the same and has a

/system/etc/usb_modeswitch.sh

which calls

/system/etc/usb_modeswitch.d/067b_2303

Thanks

Andy.
 

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
I continue to have problems with any usb device, no device is recognized.
I do not think is possible.
On the site of the Zenithink there is a folder to download "16R ADB and USB driver," they are needed during compilation?
Where should I put them in the pc?? ("C:\Android\.....??")

Thanks
 

agraham

Expert
Licensed User
Longtime User
That looks like the ADB files and USB driver for the PC from the Android SDK that lets the PC connect to the device for downloading. If you have the the Android SDK already and can connect the IDE to your device by USB are not required. They are not Android files and are nothing to do with host USB operation of the device. As I said before, there seems to be a bug in some devices that does not pass usb devices to the usbmanager, as I have also said before, it's likely that on your device UsbManager will not see any USB devices. You need to try another device if possible.
 

AndyW999

Member
Licensed User
Longtime User
Have been doing some more looking, usb_modeswitch is a utility for multi usb devices like 3G dongles so is irrelevant here.

The log when I plug the PL2303 in is :-

event { 'add', '/devices/platform/sw_hcd_host0/usb1/1-1', 'usb', '', 189, 9 }
path : '/sys/devices/platform/sw_hcd_host0/usb1/1-1'
VID :size 5,vid_path '/sys/devices/platform/sw_hcd_host0/usb1/1-1/idVendor',VID '067b
'.
PID :size 5,Pid_path '/sys/devices/platform/sw_hcd_host0/usb1/1-1/idProduct',PID '2303
'.
cmd=/system/etc/usb_modeswitch.sh /system/etc/usb_modeswitch.d/067b_2303 &,
excute ret : 0,err:No such file or directory

So the device information is actually being read, and the 1-1 directory created and filled, it seems that the B4A usb manager is not seeing it.

Any ideas where to look next?

Thanks

Andy.
 

wexican

Member
Licensed User
Longtime User
USB to Serial adapter

Hi Guys,

Firstly, some absolutely great work going on here, well done!
I see lots of fantastic work on the PL2303, Just wondering if there was any further developments on the FTDI device driver?

Thanks, Tom
 
Top