B4A Library PL2303 USB to RS232 adaptor driver

Discussion in 'Additional libraries, classes and official updates' started by agraham, Sep 12, 2011.

  1. agraham

    agraham Expert 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.
     

    Attached Files:

    hcan, eva12345 and potduang like this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Thank you for sharing this. I know that it was a huge effort to implement it.

    I hope that future versions of Android will make it simpler and more reliable.
     
  3. hdtvirl

    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
     
  4. agraham

    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.
     
  5. hdtvirl

    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
     
  6. agraham

    agraham Expert Licensed User

    I've seen that source from madingley.org but it contributes nothing. It looks like an incomplete copy of the Linux driver.

    As I said, I have nothing with an FTDI device so the documentation would be of no use to me.
     
  7. msemih2011

    msemih2011 Member Licensed User

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

    ?????
     
  8. agraham

    agraham Expert Licensed User

    I've just downloaded it again to check and it compiles OK for me.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

  10. msemih2011

    msemih2011 Member Licensed User

    my verison 1.6 latest and registered
     
  11. hdtvirl

    hdtvirl Active Member Licensed User

  12. agraham

    agraham Expert Licensed User

    Why do you keep going on about this? I've done a driver as best as I can - the end!
     
  13. hdtvirl

    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
     
  14. agraham

    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.
     
  15. hdtvirl

    hdtvirl Active Member Licensed User

    Thanks

    Regards

    BOB
     
  16. msemih2011

    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.
     
  17. agraham

    agraham Expert Licensed User

    None! Your table is most unlikely to support USB host mode in either software or hardware.
     
  18. msemih2011

    msemih2011 Member Licensed User

    Tablet that provides support for the USB HOST
     
  19. hdtvirl

    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
     
  20. msemih2011

    msemih2011 Member Licensed User

    My tablet Android 2.1 vers
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice