UsbSerial library - Supports FTDI, Arduinos and other USB serial devices

Status
Not open for further replies.

yo3ggx

Active Member
Licensed User
Longtime User
FTDI still does not work for me...

Hi all,

I have tried several versions of the java library and still the same issue with FTDI. The number of received bytes is higher than the expected one.

I am the only one with this issue?
With small chunks of data (10-20 bytes to be received) everything seems to be ok.

Thank you,
Dan
 

agraham

Expert
Licensed User
Longtime User
Does this happen even with the filterModemStatus patch? If so it might be that the hardcoded mMaxPacketSize value of 64 is wrong. Can you run my
UsbDetails program http://www.b4x.com/forum/additional...updates/11290-usb-host-library.html#post63118 from the second post and tell me the EndPointMaxPacketSize for the USB_ENDPOINT_XFER_BULK with EndPointDirection of "In".

I am about to post a new UsbSerial library with CP120x, PL2303 and ADK support and the filterModemStatus patch so it would be nice to see if this was the reason. However I will change the library to properly detect mMaxPacketSize before I post it.
 

yo3ggx

Active Member
Licensed User
Longtime User
Hi,

To which specific patch are you reffering to?
I have tried with all available patches related to FTDI in usb-serial-for-android.

If I run your app (USB details) I get the following error when clicking o "Connect" button for the second time (first time ask for permissions).

B4X:
usbdetails_bytes0tostring (B4A line: 184)
Return str.SubString2(1, idx)
java.lang.StringIndexOutOfBoundsException: length=4; regionStart=1; regionLength=-2
   at java.lang.String.startEndAndLength(String.java:593)
   at java.lang.String.substring(String.java:1474)
   at anywheresoftware.b4a.agraham.usbdetails.usbdetails._bytes0tostring(usbdetails.java:59)
   at anywheresoftware.b4a.agraham.usbdetails.usbdetails._devicedetails(usbdetails.java:183)
   at anywheresoftware.b4a.agraham.usbdetails.main._btnconnect_click(main.java:314)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:155)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:151)
   at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:55)
   at android.view.View.performClick(View.java:3670)
   at android.view.View$PerformClick.run(View.java:14372)
   at android.os.Handler.handleCallback(Handler.java:605)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4513)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:974)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:741)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.StringIndexOutOfBoundsException: length=4; regionStart=1; regionLength=-2

Thank you,
Dan
 

yo3ggx

Active Member
Licensed User
Longtime User
Now it runs, but returns the following for "Device 0 details" (tried with two different FT232 based devices with the same result:

Manufacturer: not available
Product: not available
Serial: not available
 

agraham

Expert
Licensed User
Longtime User
Now it runs, but returns the following for "Device 0 details" (tried with two different FT232 based devices with the same result:

Manufacturer: not available
Product: not available
Serial: not available
That's expected, the other information that matters follows.
 

yo3ggx

Active Member
Licensed User
Longtime User
DeviceName: /dev/bus/usb/002/024
DeviceClass: USB_CLASS_PER_INTERFACE(per-interface basis)
DeviceSubClass: 0
Device ID: 7E8h
ProductId: 6001h
VendorId: 403h

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


This is all.

Thank you,
Dan
 

yo3ggx

Active Member
Licensed User
Longtime User
And the same thing with a CP2102 interface which works perfect with the library (only the differences):

DeviceName: /dev/bus/usb/002/025
Device ID: 7E9h
ProductId: EA60h
VendorId: 10C4h

InterfaceSubClass: 0
InterfaceProtocol: 0

EndpointNumber: 1 --> both are with EndPointNumber: 1
EndpointDirection: Out


Thank you,
Dan
 

yo3ggx

Active Member
Licensed User
Longtime User
Tried the new library with my app.

It seems to be a mistake in the parameteres order in SetParameters.

USBser.SetParameters(iBaudRate,USBser.DATABITS_8, USBser.STOPBITS_1,USBser.PARITY_NONE)

Return
"An errror...."
"...java.lang.IllegalArgumentException: Unknown stopBits value: 8

If I reverse Stop bits with Data bits then is ok.

The library is working better than the one used before with FT232.
For a 400 bytes data chunk everything is ok.

If I send a command which expects 4000 bytes in return, the driver just hangs and nothing received ater that (not even 'short' commands) till a full reinitialization of the app.

Is so close....

Thank you,
Dan
 

agraham

Expert
Licensed User
Longtime User
It seems to be a mistake in the parameteres order in SetParameters
Oops! I don't know why I didn't see that. I will post a new version tomorrow that will fix that. I'll also do a special version for you with some logging so I can see where it hangs. However if it manages 400 bytes, which is more than 6 64byte packets I can't see why it wouldn't manage 4000 bytes as there is an internal 16KB buffer used on reading.
 

yo3ggx

Active Member
Licensed User
Longtime User
Tried with different lengths and seems that maximum accepted without hang is around 800.
In version used by me before the data received was jusr longer than the one expected, even at 400 bytes, but now hangs for more than 800.

Thank you,
Dan
 

agraham

Expert
Licensed User
Longtime User
@yo3ggx
What baud rates are you using? I can't see anything I can do in the library but missing data smacks of buffer overruns to me. Download the latest version 2.1 and try the following if you can

1) If possible can you try lowering the baud rate and see if it makes any difference.

2) There is a new property, UsbTimeout. The default is 200mS. Try dramatically reducing this, even down to 1mS, and see if it makes any difference. If it does then work upwards to find a workable value as very low values will increase the CPU workload dramatically.
 

yo3ggx

Active Member
Licensed User
Longtime User
Hi,

@yo3ggx
What baud rates are you using?
115200.
I cannot lower the baudrate as this is fixed in the device firmware.

I will try the timeout later in the afternoon and be back with the result.

Thank you.
Dan
 

yo3ggx

Active Member
Licensed User
Longtime User
With a smaller timeout than default it does not work at all, but, surprise!
With a timeout of 1000 it works perfect.

I will further test it to see if everything is ok.

Thank you,
Dan
 

Dirk A

Member
Licensed User
Longtime User
Hi ,
I'm trying to use the usbserial library with an ftdi based usb-serial converter.
I have the d2xx.jar (ftdi driver) but how do I tell my tablet to use this driver ?
 
Status
Not open for further replies.
Top