B4A Library UsbSerial library 2.0 - supports more devices

Discussion in 'Additional libraries, classes and official updates' started by agraham, Apr 9, 2013.

  1. Fabrice La

    Fabrice La Active Member Licensed User

    I use the cp2102 and I ahave reply form the USBSerial example:



    I am not a C programmer but I can connect to it :
    The SetParameters and UsbTimeout come from the C program :

    I read that you can't parameters the DTR/RTS ...

    My problem is I don't know what to send to be able to receive data (Attach the C program)
     

    Attached Files:

  2. agraham

    agraham Expert Licensed User

    1) No, you can't set DTR/RTS though it is possible you could hardwire them at the device if it needs them asserted.

    2) The UsbTimeout has nothing to do with the timeout in that code. Leave UsbTimeout as the default.

    3) I don't know what the device is, possibly a fingerprint or other biometric reader? To use it successfully you need more information than what is in the C code as that is just a low- level driver - and it looks like it is not complete.
     
  3. Fabrice La

    Fabrice La Active Member Licensed User

    The device is computer where data are strored.
    I have to send init to be able to have the data.
    The problem is I can't figure out what I have to send using astreams.Write

    I am not C programmer and the only doc I have is the c program.

    Attached the other C.

    Extrait :
     

    Attached Files:

    mczubel likes this.
  4. agraham

    agraham Expert Licensed User

    I'm afraid you are on your own here. It would take hours to try to go through that code to try and understand it and replicate it in B4A. Also you would need to know the meaning of some of the parameters to some of the functions, like "address" in "fabric_common_device_read".
     
  5. Fabrice La

    Fabrice La Active Member Licensed User

    Thank anyway to your job ...

    It's great works !!
     
  6. krokiz

    krokiz Member Licensed User

    I am in need to acquire a continuous stream of byte data from an Serial Device (that I made myself, although AVR MCU based,
    Using a FTDI chip in between the Android Tablet and the Device)
    The application should continuously receive bytes in range 0x00 to 0xF9, 0xFA is acting as a EOL mark, and draw graphics according to this data.
    The issue is the following:
    Since the device is sending bytes (data) continuously and might have been turned on prior the connecting to the Tablet,
    after the App connects to the external device (by plugging in the micro-B USB cable), The program (UsbSerialDemo) starts, I use the Start Button, the Stop and Send buttons become enabled and then it all goes immediately to the astreams_Error subroutine and displays the following error message:
    (IOException) java.io.IOException: Expected at least 2 bytes
    My question is: is there a workaround in order to solve this problem and achieve my goal:
    Reading the Serial data without ending up in this exception (only) indicating Subroutine (AStreams_Error) ?
    (Since I am a newbie in Android and BasicForAndroid, my wildguess is that AsyncStreams are using UTF8 and it expects 2 bytes for each character/byte (of the stream received)

    There is an aside question: How could one ignore/process such an exception, since Try..Catch..End Try does not apply here (the exception raises for its reasons, and I cannot trap it) ?


    I hope someone could help me out (pray)
     
  7. agraham

    agraham Expert Licensed User

    Which FTDI chip are you using? It looks to me as though that chip is not compatible with the driver in the library. Either it is not sending the expected two status bytes at the start of the data packet or the endpoints are reversed from what is expected.
     
  8. krokiz

    krokiz Member Licensed User

    When the external hardware is connected to the Android tablet, and the program connects with it, the application shows that the Manifacturer of the chip is EAS (I was expecting to see FTDI ?) I know that I am using FT232RL (I see it on the hardware's PCB) and it is working great when the device communicates with a PC (I am using my own PC (Delphi) program to acquire the incoming data, Teraterm works great, too)
    I think there is some encoding issue (UTF8 instead of ASCII ?), i.e., the Android/The application is expecting 2byte UTF8 encoding for each symbol, instead of 1-byte ASCII.

    Do you want me to post you the full report of usb.DeviceInfo ?

    Thanks for your quick respond, and I am sorry for my delay in posting this.

    Edit:
    Here is the full usb.DeviceInfo
    Manifacurer : EAS
    Product : EAS
    Serial : not available

    DeviceName :/dev/bus/usb/001/029
    DeviceClass: USB_CLASS_PER_INTERFACE (per-interface basis)
    DeviceSubClass : 0
    Device ID : 0x405
    ProductID : 0x6001
    VendorId: 0x403

    B4aInterfaceNumber : 0
    InterfaceClass : USB_CLASS_VENDOR_SPEC (vendor specific)
    InterfaceSubClass : 255
    InterfaceProtocol : 255

    EndpointNumber : 1
    EndpointDirection : In
    EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
    EndpointAttribute : 2
    EndpointInterval : 0
    EndpointMaxPacketSize : 64

    EndpointNumber : 2
    EndpointDirection : out
    EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
    EndpointAttribute : 2
    EndpointInterval : 0
    EndpointMaxPacketSize : 64


    Edit: I did some tests on the Android tablet it the application claimed this is a PROLIFIC Chip, though I am having FT232RL on the PCB of the external device. Here is my code snippet that I use:
    ....
    Dim devicename As String
    ....
    devicename = "UNKNOWN"
    If (usb.USB_DEVICE = usb.DRIVER_FTDI) Then devicename = "This is FTDI"
    If (usb.USB_DEVICE = usb.DRIVER_CDCACM) Then devicename = "This is CDCACM"
    If (usb.USB_DEVICE = usb.DRIVER_PROLIFIC) Then devicename = "This is PROLIFIC"
    If (usb.USB_DEVICE = usb.DRIVER_SILABS) Then devicename = "This is SILABS"
    Msgbox(devicename & " " & usb.DeviceInfo & " " , "Connection to COM Port: Connected successfuly on 115200 bps")
    ....
     
    Last edited: May 30, 2013
  9. agraham

    agraham Expert Licensed User

    There is no encoding issue, AsyncStreams is byte oriented.

    The Product and Vendor IDs show that this is an FTDI FT232 chip.

    Your test code is wrong, it is just comparing constants with constants. usb.USB_DEVICE is a constant that is returned by UsbPresent and Open to indicate that a slave USB device is connected. It does not indicate the type of that device.

    Every packet send by the FTDI chip is expected to be prefixed with 2 modem status bytes so the minimum packet size is expected to be at least two bytes. That error is thrown if a data packet contains less than two bytes. I am at a loss as to why that should be in your case. Other people are successfully using the library with FTDI chips.

    In case it is a startup problem you can try calling AsyncStreams.Close when that error occurs and then reinitialising your AsyncStreams object.
     
  10. krokiz

    krokiz Member Licensed User

    I switched from FT232RL to CP2102 and I am no longer having this workstopping error ((IOException) java.io.IOException: Expected at least 2 bytes) !
    Too bad I cannot say the same when I am using the FTDI chip. I am producing devices which are equipped with FTDI chips and I won't be able to use them with the Android app that I am creating, at least the sold ones will not work with the app. And this is too bad, because I want to impress/be helpful/give more flexibility/ with this app to my current clients (people who already bought devices) as well as the future ones :( :( Would you revise your thoughts about my problem?
    Have you ever come across with this error before? ((IOException) java.io.IOException: Expected at least 2 bytes) what could be the reason of it? I found on Google nothing about this, except on your forum (), but it does not help me at all.
    I hope you can help me.
     
  11. agraham

    agraham Expert Licensed User

    I'm sorry but I have no idea why you should have this problem. Other people have successfully used this library with FTDI chips and no-one has reported this error before. The reason for the error appears to be, as I have already said above, that the minimum packet size should be two bytes that contain status. The FTDI documentation states this so I am baffled as why you, and only you, seem to be suffering this problem
     
  12. clackl

    clackl New Member

    Hi guys,

    is it possible to download this new version of the library somewhere without shelving out 49 bucks for the development tool with i don't really need?

    Many thanks to he who can help me out.

    /Cheers
     
  13. Stulish

    Stulish Active Member Licensed User

    The Library is for B4A, if you don't need the development tool (B4A) then you shouldn't need the library????
     
  14. Marcob

    Marcob Member Licensed User

    Some issues related to FT232RL and FT230X

    Hello, I'm testing the program UsbSerialDemo on a Zopo C2 smartphone with two types of FTDI USB adapters; one uses FT232RL and the other uses FT230X.

    With FT232RL the Device Information shows:

    Code:
    Manifacturer : FTD
    Product : FT2
    Serial : A1S

    DeviceName :/dev/bus/usb/
    001/006
    DeviceClass: USB_CLASS_PER_INTERFACE (per-interface basis)
    DeviceSubClass : 
    0
    Device 
    ID : 0x3EE
    ProductID : 
    0x6001
    VendorId: 
    0x403

    B4aInterfaceNumber : 
    0
    InterfaceClass : USB_CLASS_VENDOR_SPEC (vendor specific)
    InterfaceSubClass : 
    255
    InterfaceProtocol : 
    255

    EndpointNumber : 
    1
    EndpointDirection : 
    In
    EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
    EndpointAttribute : 
    2
    EndpointInterval : 
    0
    EndpointMaxPacketSize : 
    64

    EndpointNumber : 
    2
    EndpointDirection : out
    EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
    EndpointAttribute : 
    2
    EndpointInterval : 
    0
    EndpointMaxPacketSize : 
    64
    With FT230X the Device Information shows:

    Code:
    Manifacturer : FTD
    Product : FT2
    Serial : DA0

    DeviceName :/dev/bus/usb/
    001/007
    DeviceClass: USB_CLASS_PER_INTERFACE (per-interface basis)
    DeviceSubClass : 
    0
    Device 
    ID : 0x3EF
    ProductID : 
    0x6015
    VendorId: 
    0x403

    B4aInterfaceNumber : 
    0
    InterfaceClass : USB_CLASS_VENDOR_SPEC (vendor specific)
    InterfaceSubClass : 
    255
    InterfaceProtocol : 
    255

    EndpointNumber : 
    1
    EndpointDirection : 
    In
    EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
    EndpointAttribute : 
    2
    EndpointInterval : 
    0
    EndpointMaxPacketSize : 
    64

    EndpointNumber : 
    2
    EndpointDirection : out
    EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
    EndpointAttribute : 
    2
    EndpointInterval : 
    0
    EndpointMaxPacketSize : 
    64

    The FT232RL works properly.
    Unfortunately with FT230X the program shows the message:

    "Error opening USB port"

    Any ideas on how to make the FT230X working ?

    Thanks in advance for the help that you can give me.

    PS
    I have added into the file device_filter.xml the following lines:

    <!-- 0x0403 / 0x6015: FTDI FT230X UART -->
    <usb-device vendor-id="1027" product-id="24597" />
     
  15. agraham

    agraham Expert Licensed User

    The UsbSerial library doesn't know about the FT230X - and neither do I. I don't know if it is progam compatible with the FT232 or not. You could try
    Code:
    Dim SerialLib as UsbSerial
    ...
    SerialLib.SetCustomDevice(SerialLib.DRIVER_FTDI, 
    0x4030x6015)
    Before trying to Open the device.
     
  16. Marcob

    Marcob Member Licensed User

    Thank agraham for your prompt reply.
    I tried your hint but it didn't work.

    Perhaps I could modify some locations in the internal EEPROM of FT230X so that it looks like for android similar to a FT232RL...
    I'm thinking to contact directly FTDI and ask them what is the difference between the two devices that could explain the malfunction and if there's a workaround, this could be interesting also for other developers.
    Do you have any suggestions on technical details to give to FTDI support about the android interfacing side ?
     
  17. agraham

    agraham Expert Licensed User

    If it doesn't work as a custom device then it is not program compatible with the FT2332 and the driver in UsbSerial will not be able to communicate with it. There is nothing you can do about that.
     
  18. jimTaylor

    jimTaylor Member Licensed User

    Newbie question: How do you install and run usbSerial 2.3?

    agraham,

    I appreciate you providing this package, but I am at a complete loss as to how to make it work. I can download and extract, but from that point forward the instructions might as well have been written in Martian.

    Can you provde a step-by-step that doesn't assume I know what I'm doing?

    JimT
     
  19. agraham

    agraham Expert Licensed User

    Not really because I assume that if you have an intended use for this library you must already know something about serial comms and adaptors.
     
  20. jimTaylor

    jimTaylor Member Licensed User

    Clarification

    I should have been clearer. I know how to do the serial thing on everything from micros to mainframes. What I can't do is make head or tail out of the install instructions for this software. Everyone else seems to have managed to get it running with great success. I can't even get it to a place where I can try to use it.
     
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