B4A Library felUsbSerial - Alternative Usb Serial library

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jan 10, 2016.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    USB host feature is not implemented perfectly on all devices. Which USB device are you connecting to the Android?
     
  2. red30

    red30 Active Member Licensed User

    "I connect to the microcontroller PIC18F14K50, which operates in USB CDC mode.everything works ok on all devices that work with OTG, but the tablet RoverPad Sky Glory S7 did not see the connected device. I did as written here (https://www.b4x.com/android/forum/t...rs232-adaptor-driver.11449/page-3#post-121125), - it works. I plugged the other tablet (Explay Scream 3G), made everything as the link still does not see the connected device. But the "USB Host Controller" software sees the device! You understand?"
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    I understand but I'm afraid that I don't see what you can do if the OS doesn't recognize the USB device.
     
  4. miguelcleman

    miguelcleman Member Licensed User

    It´s possible make a usb serial connection has fixed or permanent permission? (whitout msgbox confirmation?)

    sory, my english is very bad!
     
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. drponciano

    drponciano Member Licensed User

    Hello: When I try to complie the example I get the following error:

    usbserial.Initialize(\
    javac 1.8.0_102
    src\b4a\example\main.java:375: error: package android.hardware.usb does not exist
    _usbserial.Initialize("serial",(android.hardware.usb.UsbDevice)(_device.getObject()),(int) (-1));

    Seems like it has to do with USBMANAGER. Any idea what am I doing wrong?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Are you running it on Android 4+ device?
     
  8. rtek1000

    rtek1000 Active Member Licensed User

    Hi @Erel,

    You know one user has a problem with the other library, and you suggested this one, but I tested it and they both do not work.

    If the connected device (such as Arduino) sends data quickly without a space (pause) between transmissions, this library and the other one stops.

    But the official FTDI app works great, (up to 921600 bauds, flow ctrl: none) and your surce code is available at:
    Http://www.ftdichip.com/Support/SoftwareExamples/Android/J2xx_HyperTerm.zip
    Http://www.ftdichip.com/Android.htm
    Https://play.google.com/store/apps/details?id=com.ftdi.j2xx.hyperterm

    Make sure that you or your team can make a new library, or update one, with FTDI source.

    Thank you very much!
     
  9. drponciano

    drponciano Member Licensed User

    Yes, all the devices I'm using are 4+
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    You need to use a newer version of android.jar (Tools - Configure Paths).
     
  11. drponciano

    drponciano Member Licensed User

    Thanks Erel. I had a very old android.jar and now, with the new one, I don't have the compiler error. Using felUSBSerial library the problem gets worse as AsyncStream is called every 15Kbytes instead of the 8k bytes with UBSSerial library. Quite an interesting situation, no?
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    (this has nothing to do with AsyncStreams)

    Try to add these two lines in Service_Create of the starter service:
    Code:
    Dim jo As JavaObject
    jo.InitializeStatic(
    "com.felhr.usbserial.SerialBuffer").SetField("DEFAULT_READ_BUFFER_SIZE"2048)
     
  13. drponciano

    drponciano Member Licensed User

    Thanks Erele. That is, sureley, what I'm looking for and will solve my problem but, at run time, I get the following error in line

    jo.InitializeStatic("com.felhr.usbserial.SerialBuffer").SetField("DEFAULT_READ_BUFFER_SIZE", 2048)


    ** Activity (main) Pause, UserClosed = false **
    ** Service (starter) Create **
    Error occurred on line: 16 (Starter)
    java.lang.IllegalAccessException: field is marked 'final'
    at java.lang.reflect.Field.setField(Native Method)
    at java.lang.reflect.Field.set(Field.java:585)
    at anywheresoftware.b4j.object.JavaObject.SetField(JavaObject.java:174)
    at java.lang.reflect.Method.invokeNative(Native Method)

    ...

    ** Service (starter) Start **
    ** Activity (main) Resume **

    Any chance a similar solution using USBSERIAL 2.4?

    Sorry for taking so much of your time but appreciate your help.
     
    Last edited: Dec 15, 2016
  14. Erel

    Erel Administrator Staff Member Licensed User

    You need to use Reflection library:
    Code:
    Dim r As Reflector
    r.SetStaticField(
    "com.felhr.usbserial.SerialBuffer""DEFAULT_READ_BUFFER_SIZE"2048"java.lang.int")
     
  15. drponciano

    drponciano Member Licensed User

    Thanks Erel. Done with reflector. Still chuncks of 15782 bytes with felusbserial as before. Using USBSerial 2.4 the packet is 7936 bytes or about 1.5 seconds of data.
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    The native library doesn't provide an API to change the buffer size. You will need to use UsbSerial library for now.
     
  17. drponciano

    drponciano Member Licensed User

    Thanx for your patience Erel. I'll do that for the moment.
     
  18. Beja

    Beja Expert Licensed User

    Hi Erel,
    Start reading as I understand is for reading INTO the phone or Android device (like reading sensor values...etc).. Is it also possible to write to the outside world with this library? In other words, I want to use a smartphone with an app with this library to access and control a machine by connecting the smartphone's usb with the target machine's usb port.

    Thanks
     
  19. Beja

    Beja Expert Licensed User

    Another question:
    Today I tried to run the app but there's no response from the "Connect" button.. it's enabled and can be pressed and raised but there's no action.. even when I disconnected the device, it didn't give me the error msg that now device is connected.
    I hope there will be some suggestions or a solution to this.
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    Yes. You can use felUsbSerial.Write to write data.

    Which device have you connected to the USB port?
     
    Beja likes this.
Thread Status:
Not open for further replies.
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