B4A Library UsbSerial library 2.0 - supports more devices

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

  1. Erel

    Erel Administrator Staff Member Licensed User

  2. Filippo

    Filippo Expert Licensed User

    Then is the problem on the device and not on the Android version?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Yes. Unfortunately USB host is not supported properly on many devices.
     
  4. CPS

    CPS New Member Licensed User

    Hi - great library, thanks.

    Attached is a proposal (and all the java src required) for adding RS232 'break' function to the library - this is really actually a Android USB host serial driver library addition for Mike but as it would be great to get it merged into this library as well, so I thought I'd post it here for Andrew at the same time. It's a bit long winded so attached as a text file.

    Thanks, Clive
     

    Attached Files:

  5. nosaj66au

    nosaj66au Member Licensed User

    Hi - agree great libary!!!
    can anyone confirm if the libary supports parity detection, it appears to support parity set already. I have an older bus protocol which can be read / written to via a USB RS232 port and I have writen a windows driver for it in the past and I look to port to Android. The requirment is to detect Char's with parity of either Mark , Space or None as these are used to indicate the Start, End and Data within a message packet.

    Thanks in advance
    Jason
     
  6. agraham

    agraham Expert Licensed User

    No, parity detection is not available unless you can do it yourself by sending 7 data bits + parity and receiving it as a 8 data bits + no parity and masking the parity bit out yourself.
     
    Erel likes this.
  7. nosaj66au

    nosaj66au Member Licensed User

    Thanks for your fast responses Agraham, however the protocol is already defined and is 8 data bits + parity. I have written a drivers for both AVR micros and windows and have basically had to bit bang or extract from raw uart data. Anybody have any suggestions.

    Jason
     
  8. RichardHirst

    RichardHirst Member Licensed User

    HI.

    I have a FTDI 2232D, this is a dual port device.

    The info returns: B4aInterfaceNumber: 0 and B4aInterfaceNumber: 1

    If there a method to select which interface is use..?

    Thanks

    RicHard
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    What happens when you you call Open? Does it connect?
     
  10. RichardHirst

    RichardHirst Member Licensed User

    No.. I get - "Error opening USB port"

    The info returns all the correct endpoints etc for both interface numbers.

    The demo code works ok when you attached a single FTDI device.

    Richard.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that currently it is possible to choose which interface point will be used. Maybe agraham can provide more information.
     
  12. agraham

    agraham Expert Licensed User

    Unfortunately no, it uses the first it finds. However the source code is available in the posted archive so if you are set up to make libraries you could try modifying to suit your needs.
     
  13. biometrics

    biometrics Active Member Licensed User

    Hi,

    An app that uses the USB Serial library suddenly stopped compiling for some reason and I can't figure out why ... can anyone help?

    I have this in the manifest as before:

    Code:
    AddActivityText(main, <intent-filter>
    <action android:name=
    "android.hardware.usb.action.USB_DEVICE_ATTACHED" />
    </
    intent-filter>
    <meta-data android:name=
    "android.hardware.usb.action.USB_DEVICE_ATTACHED"
    android:resource=
    "@xml/device_filter" />)

    But the compiler now complains with this error message:


    Code:
    Parsing code.  0.05
    Compiling code.  
    0.06
    Compiling layouts code.  
    0.02
    Generating R 
    file.  Error
    AndroidManifest.xml:
    43: error: Error: No resource found that matches the given name (at 'resource' with value '@xml/device_filter').
     
  14. biometrics

    biometrics Active Member Licensed User

    Above post solved ... for some unknown reason this file went missing!

     
  15. TR Shearer

    TR Shearer New Member Licensed User

    I'm trying to run the UsbSerial demo on a rooted Nook Simple Touch. Eventually I want to read NMEA (GPS) data via a USB2Serial adaptor and display the info on the daylight-readable e-ink screen. I have an app that can do this (TopHat Soaring) so I know the hardware is capable of it but the demo keeps crashing at the first library call - see the log below.

    The ReadMe for the library says the JAR and XML files should go in the "Additional Libraries" folder - where is this? I've put them in "C:\Program Files\Anywhere Software\Basic4android\Libraries" and the demo compiles correctly.

    Any ideas?

    Thanks,
    Bob

    The log says...

    main_btnopen_click (B4A line: 41)
    If usb.UsbPresent = usb.USB_NONE Then
    java.lang.NoClassDefFoundError: android.hardware.usb.UsbManager
    at anywheresoftware.b4a.objects.UsbSerial.UsbPresent(UsbSerial.java:345)
    at b4a.example1.main._btnopen_click(main.java:438)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:63)
    at android.view.View.performClick(View.java:2373)
    at android.view.View.onTouchEvent(View.java:4197)
    at android.widget.TextView.onTouchEvent(TextView.java:6618)
    at android.view.View.dispatchTouchEvent(View.java:3727)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:904)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:904)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:904)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:904)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1105)
    at android.app.Activity.dispatchTouchEvent(Activity.java:2078)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4363)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)
     
  16. agraham

    agraham Expert Licensed User

    Your device seems to be missing the UsbManager class which is used by UsbSerial2. This was added to Android in version 3.1. As the Nook seems to be based on Android 2.1 this would explain why it is not present.

    Define your additional libraries folder by Tools -> Configure Paths
     
    TR Shearer likes this.
  17. christian91

    christian91 New Member Licensed User

    Hi
    I have custom interface FT232R with my own PID C7F0.

    in the USBSerialDemo2.3, i add
    usb.SetCustomDevice(usb.DRIVER_FTDI, 0x0403, 0xC7F0)
    before
    usb.HasPermission
    I can read usb.DeviceInfo
    but usb.open() return usb.USB_NONE

    Set with Mprog FDTI :
    USB VID=0403, USB PID=C7F0
    Manufacturer=SCAN, Product=USB ScanST
    Bus Powered=1, Max Bus Power=100
    High Current I/O=1, Load D2XX Driver=1

    Any help?
    Thx, Christian
     
  18. agraham

    agraham Expert Licensed User

    It looks like the usb.DRIVER_FTDI constant may not return the correct value (0 instead of 4). Try
    Code:
    usb.SetCustomDevice(40x04030xC7F0)
     
  19. christian91

    christian91 New Member Licensed User

    Thanks you, agraham. It works perfectly
     
  20. Opa

    Opa New Member Licensed User

    Communicating with data coming from a PIC18F252 microcontroller and an FTDI 232 usb to serial converter at 115.2 K, I had the
    same annoying error over and over again ( IOException java.io.IOException: expected at least 2 bytes ).
    However in my case the solution was easy by using a greater timeout. So after the line
    astreams.Initialize(usb.GetInputStream, usb.GetOutputStream, "astreams")
    I putted
    usb.UsbTimeout=1000 ' default was 200
    Hope this helps for you also, if you didn't find this solution already in the meantime ;-)
     
    Erel likes this.
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