Android Question The UsbSerialDemo code does'nt work on my phone

frederic

Member
Licensed User
Longtime User
Dear All,

I try to use the sample code : UsbSerialDemo as is.
The variable dev = usb.Open(9600) stay allways to 0.
I try a lot combinaizon without success.
First directly on my PC with Tera Term, don't work.
Second with an usb to serial converter from FTDI (it is a FT232), don't work also.
I connect or disconnect the device (PC or FTDI) no difference.
Anyway I do not understand, the code have permissions and are able to give DeviceInfo !?
I use with this experience a Galaxy S3 GT19300.
All I made will not working.
Maybe I have to link with some extras libraries? I do not knows?
Thank you for your replies.
Best regards.
Frédéric
 

Mark_Hugill

Member
Licensed User
Longtime User
Hello
I'm having a few issue myself.
I've tried all the demos and to the most part it works i.e. libraries and permissions loaded and will download and run but I cannot get it to open the port.

I'm using an FT230XQ chip and it lists the device information below:


usb2.DeviceInfo(2)

=====================================================
Manufacturer : FTD
Product : FT2
Serial : DN0

DeviceName : /dev/bus/usb/002/024
DeviceClass : USB_CLASS_PER_INTERFACE (per-interface basis)
DeviceSubClass : 0
Device ID : 0x7E8
ProductId : 0x6015
VendorId : 0x403

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
EndpointMa......


=====================================================


The error occurs at dev = usb2.Open(9600, 2) where dev returns '0' which will list the ("Error opening USB port 2")

Dim dev As Int
'dev = usb.Open(115200, 2) ' Ver_2.4
dev = usb2.Open(9600, 2) ' Ver_2.4
If dev <> usb2.USB_NONE Then
Log("Connected successfully! 2")
btnOpen2.Enabled = False
btnClose2.Enabled = True
btnSend2.Enabled = True
astreams2.Initialize(usb2.GetInputStream, usb2.GetOutputStream, "astreams2")
Else
Log("Error opening USB port 2")
End If

I not sure why it fails to open the port so any help would be appreciated

Not sure if it helps but I can use other Android terminals and they are all able to connect to the device and send and retrieve messages as expected.

Thanks,
Mark
 
Upvote 0

frederic

Member
Licensed User
Longtime User
What happens when you press on the Start button? Do you see any message?
Hello Erel,

He say the phone authorize for using the USB.
After the checking permission, I have

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Checking permission
Manufacturer : not available
Product : not available
Serial : not available
DeviceName : /dev/bus/usb/001/002
DeviceClass : USB_CLASS_COM (communication device)
DeviceSubClass : 0
Device ID : 0x3EA
ProductId : 0x20
VendorId :0x1519
B4aInterfaceNumber : 0
InterfaceClass : USB_CLASS_COM (communication device)
InterfaceSubClass : 2
InterfaceProtocol : 1
EndpointNumber : 5
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_INT (interrupt)
EndpointAttribute : 3
EndpointInterval : 4
EndpointMaxPacketSize : 64
B4aInterfaceNumber : 1
InterfaceClass : USB_CLASS_CDC_DATA(CDC device)
InterfaceSubClass : 0
InterfaceProtocol : 0
EndpointNumber : 1
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
EndpointAttribute : 2
EndpointInterval : 0
EndpointMaxPacketSize : 512
EndpointNumber : 1
EndpointDirection : out
EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
EndpointAttribute : 2
EndpointInterval : 0
EndpointMaxPacketSize : 512
B4aInterfaceNumber : 2
InterfaceClass : USB_CLASS_COM (communication device)
InterfaceSubClass : 2
InterfaceProtocol : 1
EndpointNumber : 6
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_INT (interrupt)
EndpointAttribute : 3
EndpointInterval : 4
EndpointMaxPacketSize : 64
B4aInterfaceNumber : 3
InterfaceClass : USB_CLASS_CDC_DATA(CDC device)
InterfaceSubClass : 0
InterfaceProtocol : 0
EndpointNumber : 2
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
EndpointAttribute : 2
EndpointInterval : 0
EndpointMaxPacketSize : 512
EndpointNumber : 2
EndpointDirection : out
EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
EndpointAttribute : 2
EndpointInterval : 0
EndpointMaxPacketSize : 512
B4aInterfaceNumber : 4
InterfaceClass : USB_CLASS_COM (communication device)
InterfaceSubClass : 2
InterfaceProtocol : 1
EndpointNumber : 7
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_INT (interrupt)
EndpointAttribute : 3
EndpointInterval : 4
EndpointMaxPacketSize : 64
B4aInterfaceNumber : 5
InterfaceClass : USB_CLASS_CDC_DATA(CDC device)
InterfaceSubClass : 0
InterfaceProtocol : 0
EndpointNumber : 3
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
EndpointAttribute : 2
EndpointInterval : 0
EndpointMaxPacketSize : 512
EndpointNumber : 3
EndpointDirection : out
EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
EndpointAttribute : 2
EndpointInterval : 0
EndpointMaxPacketSize : 512
B4aInterfaceNumber : 6
InterfaceClass : USB_CLASS_COM (communication device)
InterfaceSubClass : 2
InterfaceProtocol : 1
EndpointNumber : 8
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_INT (interrupt)
EndpointAttribute : 3
EndpointInterval : 4
EndpointMaxPacketSize : 64
B4aInterfaceNumber : 7
InterfaceClass : USB_CLASS_CDC_DATA(CDC device)
InterfaceSubClass : 0
InterfaceProtocol : 0
EndpointNumber : 4
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
EndpointAttribute : 2
EndpointInterval : 0
EndpointMaxPacketSize : 512
EndpointNumber : 4
EndpointDirection : out
EndpointType : USB_ENDPOINT_XFER_BULK (bulk)
EndpointAttribute : 2
EndpointInterval : 0
EndpointMaxPacketSize : 512

But it is the same Product Id and Vendor Id, same values if the FTDI or the PC are connected or nothing are connected on the android.
The "Stop" and "Send abcde" are not enabled.
The phone is seen as serial port com #8 by Tera Term, but nothing works because the variable dev = usb.Open(9600) is equal to 0.
Thank in advance for the reply.
frederic
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
But it is the same Product Id and Vendor Id, same values if the FTDI or the PC are connected or nothing are connected on the android.
Try to connect it to the FTDI chip.

Test it after you restart the device and before you connect anything.

UsbSerial v2.3 always tries to open the first USB adapter if finds. If your device reports multiple adapters then you will need to use v2.4 which allows you to choose the adapter.
 
Upvote 0

frederic

Member
Licensed User
Longtime User
Try to connect it to the FTDI chip.

Test it after you restart the device and before you connect anything.

UsbSerial v2.3 always tries to open the first USB adapter if finds. If your device reports multiple adapters then you will need to use v2.4 which allows you to choose the adapter.


Dear Erel,

I try the v2.4 example with her Library. Now I read the FTD enumerations like :

Checking permission 2
usb2.DeviceInfo(2)Manufacturer : FTD
Product : FT2
Serial : DBW
DeviceName : /dev/bus/usb/002/005
DeviceClass : USB_CLASS_PER_INTERFACE (per-interface basis)
DeviceSubClass : 0
Device ID : 0x7D5
ProductId : 0x6015
VendorId : 0x403
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

It will be better as first time, but no point when asking to open the port!
Can I add more code as previous one?
Thanks by advance.
Best regards.
frederic
 
Upvote 0

Mark_Hugill

Member
Licensed User
Longtime User
So I'm using the same FTDI chip as Frederick and have the issue when it comes to opening the connections

usb.Open(115200, 2)

which returns '0' and therefore Log("Error opening USB port 2")

Again my device is able to be read by other Google Play USB terminal apps so not sure why it can't be opened?

I've tried Android Studio and it opens the connection fine so i'm puzzled?

Thanks,
Mark
 
Upvote 0

frederic

Member
Licensed User
Longtime User
Hello,

I would like to knows how is managed the ..\path usbserial\driver\UsbSerialDriver.Java File, how it will be placed for linking with the
UsbSerialDemo . I suppose it will not linked with.
When you load UsbSerial Jar & XML libraries into Library folder, where are you putting src (source) path and all the files included.
What is the tree? There is some environments variables ?
Thank you .
frederic
 
Upvote 0

Mark_Hugill

Member
Licensed User
Longtime User
Should I start my own thread to get a reply? I posted here because we are using the same FDTI chip and having the same issue?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Should I start my own thread to get a reply?
Yes, it is better to start a new thread.

I would like to knows how is managed the ..\path usbserial\driver\UsbSerialDriver.Java File, how it will be placed for linking with the
UsbSerialDemo . I suppose it will not linked with.
You cannot include Java source files. The problem is not in the building step. It is possible that your device is not compatible with this library.
 
Upvote 0

frederic

Member
Licensed User
Longtime User
Yes, it is better to start a new thread.


You cannot include Java source files. The problem is not in the building step. It is possible that your device is not compatible with this library.
Hello Erel,

You are right.
I'm just finished to test 2 differents devices, but from the same foundry : FTDI.
The good one are FT232BQ_BL and the FT232R.
The code application works perfectly!
For the other Integrated circuits , I don't understand why. (maybe protocol, timing latency ??).
So for me the thread should be closed.
But anyway, the code or the drivers may be improving to run with the maximum of circuits.
Thank you for your support.
Best regards.
frédéric
 
Upvote 0

deantangNYP

Active Member
Licensed User
Longtime User
Please advise...

The variable dev = usb.Open(9600) always return 0. How to overcome this?
Please point me to the correct URL please.

Thanks/

I have set the Manifest and Device filter (device_filter on res/xml)
and the usb.DeviceInfo returns all the USB messages.

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" />)
 
Last edited:
Upvote 0

deantangNYP

Active Member
Licensed User
Longtime User
I have only 1 USB device, FTDI. I am using USBSerial2.3.
Device:
<!-- 0x0403 / 0x6015: FTDI 234XD UART -->
<usb-device vendor-id="1027" product-id="24597" />

These are the usb.deviceInfo that was captured:

Manufacturer : FTD
Product : FT2
Serial : DJ0
DeviceName : /dev/bus/usb/002/002
DeviceClass : USB_CLASS_PER_INTERFACE (per-interface basis)
DeviceSubClass : 0
Device ID : 0x7D2
ProductId : 0x6015
VendorId :0x403
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


Appreciate if there is a solution to this, coz the hardware is already fabricated.
Many Thanks.

Which USB device is connected?

Are you using UsbSerial v2.x ?
 
Last edited:
Upvote 0
Top