Android Question UsbSerial library 2.0 problem

mrossen

Active Member
Licensed User
Hi

When I set the baudrate to 115200 the "LastException.Message" in "AStreams_Error" gives me a "java.io.IOException: Expected at least 2 bytes".

With ex. a baudrate 57600 the is no error but of course the data is garbage.

Anyone tried the library with a baudrate of 115200.

I use a profilic 2303 usb to serial cable

my code :

B4X:
If usb.UsbPresent(1) = usb.USB_NONE Then
                Log("Msgbox - no device")
                Msgbox("No USB device or accessory detected!", "Error")
                Log("Msgbox - returned")
                Return
            End If
            
            Log("Checking permission")
            
            If (usb.HasPermission(1)) Then
                'Msgbox(usb.DeviceInfo(1), "Device Information")
                Dim dev As Int
                dev = usb.Open(115200, 1)
                If dev <> usb.USB_NONE Then
                    Log("Connected successfully!")
                    AStreams.Initialize(usb.GetInputStream, usb.GetOutputStream, "Astreams")
                Else
                    Log("Error opening USB port")
                End If
            Else
                usb.RequestPermission(1)
            End If
Mogens
 

mrossen

Active Member
Licensed User
Last edited:

mrossen

Active Member
Licensed User
The problem is that I receive chunks of 15872k byte. I need the receive event raised much faster. When I receive data from Wifi I receive data with 8 to 40 bytes.

If I can set the buffer to ex. 1500 byte that will be fine.

Mogens
 

Erel

Administrator
Staff member
Licensed User
Please try the attached jar. You should see a message in the logs about the buffer size. It is hard coded to 1500. I want to see whether it makes any difference.
 

Attachments

mrossen

Active Member
Licensed User
Hi Erel,

This works perfect. Now I recieve 1426 byte. Is it possible to add this to the library so it can be changed?

Mogens
 
Top