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

marcomilazzo

Member
Licensed User
Longtime User
ft311d

Hi
i made the sw for the ft311d
it works but i needs ti be better.Maybe Erel can make a lib!
Now i'm trying to use the usbserial library and i have some question
1)i need to "Enable USB-Host Controller on any Android
i can't write the line in that directory! wich is the best apk or other way to write this line?
2) how did you connect the ft232r to a phone? i tried with an adaptor from the micro usb to the normal usb but obviously there is no vcc....
ciao
marco
 

marcomilazzo

Member
Licensed User
Longtime User
ft311d ftdi usb chip

Sorry!
i will do it.
the ft311d works fine !
But i would like to use your serial library .
It's a very simple hw!
I tried to use it but first i need to make the change in the xml and after i need a correct way to connect the chip to my samsung phone

marco
 

viriato

Member
Licensed User
Longtime User
edit "handheld_core_hardware.xml" file

HI
I am trying to use USB on Samsumg Note with FT232 serial com chip
According this post It looks like I need to modify on " /system/etc/permissions"
file - "handheld_core_hardware.xml"
with <feature name="android.hardware.usb.host"> this line it is not in the file

I am able to edit the file directly on the device ,but I can't save it , it is protected file !! is this protected file ?
Any suggestion to change or modify the file ?

Thanks
 

EduardoElias

Well-Known Member
Licensed User
Longtime User
HI
I am trying to use USB on Samsumg Note with FT232 serial com chip
According this post It looks like I need to modify on " /system/etc/permissions"
file - "handheld_core_hardware.xml"
with <feature name="android.hardware.usb.host"> this line it is not in the file

I am able to edit the file directly on the device ,but I can't save it , it is protected file !! is this protected file ?
Any suggestion to change or modify the file ?

Thanks

you need to have root access. Samsumg commonly are not rooted devices. But you need to google for more information.

These files are "protected", read-only. You need to enter in super user mode of the core linux OS of your device, change the permission (chmod) and make the changes.

But it only works in devices that are rooted, that permit you to do that. You can find on google play store tools that will tell you (like "Root Checker") if you are rooted. After that you need to search for the other steps there are plenty of tutorials over internet for that.
 

viriato

Member
Licensed User
Longtime User
eelias ,
Thanks for the info , so if I understand correctly if I create a program and somebody else would like to use in no " routed " it do not work..
Merci
 

EduardoElias

Well-Known Member
Licensed User
Longtime User
eelias ,
Thanks for the info , so if I understand correctly if I create a program and somebody else would like to use in no " routed " it do not work..
Merci

You are right. If the device do not have the USB HOST mode already configured you will need to have the device rooted.

I see that some newer devices are already configured, I hope this is going to be common for new releases.

I am working in a project that need that, and for our case we needed to make clear to the customer which tablets to buy. Some already configured and others that is factory rooted and can be configured. However even if you configure there are some that this does not work. But seems to be only those very cheap chinese ones.
 

marcomilazzo

Member
Licensed User
Longtime User
Hi Elias
i have a samsung galaxy chat bt5330
It's not rooted
the phone has the correct xml
it works with a cable otg and reads memory cards
But no way it works with the serial lib
with the usb host controller it shows the ft232r
but i can't acess it!!
any suggestion?
if i root the phone should it work?
thank's
marco
 

EduardoElias

Well-Known Member
Licensed User
Longtime User
Hi Elias
i have a samsung galaxy chat bt5330
It's not rooted
the phone has the correct xml
it works with a cable otg and reads memory cards
But no way it works with the serial lib
with the usb host controller it shows the ft232r
but i can't acess it!!
any suggestion?
if i root the phone should it work?
thank's
marco

Not sure how much I can help you, let me give you some toughts:

I came up finding B4A because this pl2303 library. I needed to send and receive data from rs232 devices.

My only experience was with a Genesis 7220S tablet, that I was lucky to be factory rooted and could then change the configuration.

All that I know is that I found in many articles about this stuff, you only need to root your android if you need to change the configuration file. This is about to have the SuperUser access and the rights to change the files read-only access.

I am not an expert on that at all. Just followed some tutorials to learn each details.

The fact is that USB host mode depends on having the right hardware and configuration working together. Linux kernel already have support for that, when any kind of USB is already enabled. If USB hosting is not enabled then is a fact of making the config change.

However your hardware also needs to be capable of doing that. What I read was that there are some androids that does not come with the hardware for that. What is done is a fake Host mode, powering the USB (power only should come from Host Mode capable devices) but using the USB accessory mode. Maybe this is a way to have less cost on production, I dont know.

I believe you should google for it, and get some hours of searching... :(

I saw that there some tutorials for galaxy phones but I could not find for your specific model, that is pretty new. That is important because the hardware can be totally different.

If you have everything in place the PL2302 library + Prolific USb-RS232 cable + android 3.* or newer + and USB host working, it works just fine. I am using it in a regular basis and works just fine.

For a commercial application you need to carefull, because few will have this combination, and asking make the configuration too complex for the overall users. In my case I sell the tablet with the software already configured and working. I dont sell it on play store.

Also, your model of phone is not a powerfull one from Samsung. It was created for overall public, not for power user.

good luck!
 

marcomilazzo

Member
Licensed User
Longtime User
Hi
Thank's for answering me.
What is strange is that the phone reads external usb sticks .
it also works with the ft311 chip as accessory!
It sees the ft232 but doesn't want to connect!!
I think at this point that there is some driver in the kernel missing
It's getting complicated.
as you said it is for working reason that i need this serial
ciao
marco
 

yo3ggx

Active Member
Licensed User
Longtime User
PL2303 ANdroid driver from Prolific

Hi all,

If you look into this document:

http://prolificusa.com/files/PL2303 Android USB Host Solution Application Note.pdf

there is a PL2303 Android Java Driver Library (pl2303driver.jar) available from Prolific. Is not freely downloadable, but there is a simple test application available here:
http://www.prolific.com.tw/UserFiles/files/ap_PL2303HXDSimpleTest.zip

Anybody tries to use this in a B4A application? I was not able to connect to my device using this test app.

Thank you,
Dan
 

yo3ggx

Active Member
Licensed User
Longtime User
I know that.
It does not work at all for me, most probable because of another type of PL2303 chip. I've tried to write to Prolific to ask for the availability of java library, but no answer so far.

Your driver is working for me (tested the demo). I will give it a try to see if can be used in one of my apps which now is using Serial over Bluetooth only.

Thank you,
Dan
 

alexhi

Member
Licensed User
Longtime User
Hello! How do I write to port 255 for exampleUSBpl2303.WriteData (???

Hello! How do I write to port 255 for example USBpl2303.WriteData (???
 

qsrtech

Active Member
Licensed User
Longtime User
HL340 chipset interface

Hi, Thank you for your contribution to using pl2303 usb to 232 units. I also have units that are "HL340", which seem to be much cheaper (90%) to buy. productID=29987, VendorID=6790. I'm using them to connect to a serial thermal printer.

I'm having difficulty getting them to send data correctly. I used your code and just modified the ID's. Everything does seem to connect. I've tried the cable with "Slick USB" app and everything seems to work correctly with their app, so unless they've specifically added this model to their app, there must be a generic way of communicating with this device.

Can anyone pls help with this?

Btw, I've tried USB and USBSerial w/o succcess.
 
Top