B4A Library UsbSerial library 2.0 - supports more devices

D

Deleted member 103

Guest
Then is the problem on the device and not on the Android version?
 

CPS

New Member
Licensed User
Longtime 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
 

Attachments

  • basicforandroid.txt
    8.7 KB · Views: 365

nosaj66au

Member
Licensed User
Longtime 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
 

nosaj66au

Member
Licensed User
Longtime 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
 

RichardHirst

Member
Licensed User
Longtime 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
 

RichardHirst

Member
Licensed User
Longtime 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.
 

agraham

Expert
Licensed User
Longtime User
HI.
If there a method to select which interface is use..?
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.
 

biometrics

Active Member
Licensed User
Longtime 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:

B4X:
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:


B4X:
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').
 

biometrics

Active Member
Licensed User
Longtime User
Above post solved ... for some unknown reason this file went missing!

Then copy device_filter.xml from the demo in the attached archive to: <your project>\objects\res\xml and mark it as read-only. Note that this is an expanded version of the original device_filter.xml file.
 

TR Shearer

New Member
Licensed User
Longtime 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)
 

agraham

Expert
Licensed User
Longtime 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
 

christian91

New Member
Licensed User
Longtime 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
 

Opa

New Member
Licensed User
Longtime 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 ;-)
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…