B4A Library UsbSerial library 2.0 - supports more devices

Ferraz71

Member
Licensed User
Longtime User
I would like to use comunication from usb port to control i2c peripherals, like ADC´s and GPIOS expanders, without external microcontrolers. The android apk, will do control trough a USB port, with only an FT232H IC or an MCP2221 IC like bridge. Is it possible with SerialUSB Library?
 

Creideiki

Active Member
Licensed User
Longtime User
The source is in the zip file...
I need the possibility to use ASyncStreams; felUsbSerial doesn't seem to use them.

I have an adapter with a FT232R, but it throws exceptions (e.g. java.lang.NullPointerException), so I have to figure out what happens.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I need the possibility to use ASyncStreams; felUsbSerial doesn't seem to use them.
felUsbSerial implements a similar solution internally. If you are using AsyncStreamsText then you can use the modified version that I posted (I will help you find it).

If you have the source code then you should be able to build it.
 

Creideiki

Active Member
Licensed User
Longtime User
The same code uses Bluetooth with AsyncStreams, so that should work with UsbSerial, too.

Is there a HowTo, how to make a B4A-library from java source code?
 

DonManfred

Expert
Licensed User
Longtime User

BarryW

Active Member
Licensed User
Longtime User
How to remove the message box after the connection is successfull.

I try to connect a arduino to my phone the executes the program. It works fine but there is a messagebox if the connection success.

Tnx.
 

slugger

Member
Licensed User
Longtime User
Hi,

I have been using this library in one of my apps for the last 2 years and it worked just fine in my old smartphone running Android 4.3.

Basically there is a foreground service which reads and writes from/to the USB to RS232 adapter and everything works Ok even when the screen turns off.

Now I am trying to run it on a new smartphone with Android 6.0.1 on it.

The very same APK stops working when the screen turns off.

At that point the USBPRESENT always returns no adapters even if I use a timer to periodically check for the presence of the USB-RS232 adapter.

When I turn the screen back on the adapter is found and the serial communication resumes.

The only solution I have found is to use the Phone library to keep the screen always on but although the backlight is dimmed it doesn't do too much good to the screen and the battery life.

Is it a new feature of Android 6 ?

Any workarounds?


Thank you in advance.
 

jahswant

Well-Known Member
Licensed User
Longtime User
Basically there is a foreground service which reads and writes from/to the USB to RS232 adapter and everything works Ok even when the screen turns off.
I think this is the best moment to pass either to a background service or use a different thread for the background task.
 

slugger

Member
Licensed User
Longtime User
Thanks for the replies.

I use the PhoneWakeState's PartialLock and KeepAlive to keep the screen ON and dimmed.

If I use only the PartialLock the screen goes OFF and then the library doesn't find the adapter anymore...when I turn the display back on I am greeted again with the Android's request to grant USB permission to the application and then the communication starts to work again.

The same APK installed in my old smartphone running Android 4.3 works perfectly even after the display turns off.

I guess there's something in Android 6 that deactivates the USB permission granted to the app as soon as the screen goes off.
 

rtek1000

Active Member
Licensed User
Longtime User


App example for test of USB Serial Port cable

Tested with FT232LR and PL2303 cables


(for personal non-commercial use only)

You can use this for test Arduino board, PIC (Microchip) and other systems!
 

Attachments

  • USBserial_example.zip
    10 KB · Views: 424
  • Online.png
    34.4 KB · Views: 387
  • Offline.png
    36.4 KB · Views: 376
Last edited:

GaNdAlF89

Active Member
Licensed User
Longtime User
Hi to all! I have an usb barcode reader but it is not detected from this library (usbReader.UsbPresent(1) is equal to usbReader.USB_NONE). I think the problem is that the device is like a keyboard (it needs the focus on an editText).
How can I solve the problem? Or, if the problem is the model of my usb barcode reader, how can I find a device to work correctly with this library? I need asynchronous reading. Thanks!
 
Last edited:

rtek1000

Active Member
Licensed User
Longtime User

Hello,

I believe a Serial USB library is not for your case if it's like a keyboard.

Well, if it's like a keyboard, try to see it in the Android Menu, Settings> Language and Input.

I believe that if you use a common keyboard, maybe you need to define a key function like F2, F6 etc, or by touchscreen to set the focus.

Does your scanner send initial string?
 

rtek1000

Active Member
Licensed User
Longtime User

I think you will need to start a new thread
 

drponciano

Member
Licensed User
Longtime User
Hello Krokiz! Did you get your program workin with FTDI? I have the exact same problem with the 2 bytes error. Any help?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…