mik3y / usb-serial-for-android

Android USB host serial driver library for CDC, FTDI, Arduino and other devices.
MIT License
4.9k stars 1.59k forks source link

I get "Error writing 20 bytes at offset 0 of total 20" suddenly at runtime at random times. I am unable to figure out the reason for this. Could you help? #426

Closed KeaganFerrao closed 1 year ago

KeaganFerrao commented 2 years ago

Full stack trace: java.io.IOException: Error writing 20 bytes at offset 0 of total 20 at com.hoho.android.usbserial.driver.CommonUsbSerialPort.write(CommonUsbSerialPort.java:248) at in.xtrememedia.controller.serialmanager.SerialCommand.fireSerialCommand(SerialCommand.java:634) at in.xtrememedia.controller.LEDMonitoringService.fireSerialCommand(LEDMonitoringService.java:532) at in.xtrememedia.controller.LEDMonitoringService.fireNextCommand(LEDMonitoringService.java:389) at in.xtrememedia.controller.LEDMonitoringService$1.run(LEDMonitoringService.java:412) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

kai-morich commented 2 years ago

do you get the same issue with the sample app or https://play.google.com/store/apps/details?id=de.kai_morich.serial_usb_terminal?

b2256334 commented 2 years ago

Hello! I also have the same problem, and i use the sample app which you say ( https://play.google.com/store/apps/details?id=de.kai_morich.serial_usb_terminal?) ,also get the same problem. how can i do? thanks~

kai-morich commented 2 years ago

which device are you using?

NinjaRat84 commented 2 years ago

I've got this same issue. Randomly loses connection somehow and receives the same error. When trying with the sample app I receive no response. Trying to sen BREAK results in "BREAK failed: controlTransfer failed".

Any suggestions? :)

kai-morich commented 2 years ago

which device are you using?

NinjaRat84 commented 2 years ago

I'm using a Pixel 6 Pro

kai-morich commented 2 years ago

which USB device type are you using?

NinjaRat84 commented 2 years ago

I'm using USB-C on both ends.

kai-morich commented 2 years ago

which device type (ftdi, pl2303, cdc, ...) are you using?

NinjaRat84 commented 2 years ago

Ohh, sorry... It's CDC :)

kai-morich commented 2 years ago

does your CDC device read the data you write? I observed timeout errors, when data cannot be written, very likely due to some buffer being full on recieving side.

NinjaRat84 commented 2 years ago

I doesn't seem lite the write succeeds, only that IOException is thrown. I've verified that the connection is available with proper port, but it fails during write.

Often this issue is resolved by killing the app and re-connect together with starting the app again. (but not always)

NinjaRat84 commented 2 years ago

The issue seems to occur when jumping between FTDI and CDC... :/

kai-morich commented 2 years ago

do you have connected FTDI and CDC devices at the same time, or does it work with FTDI without issues, and only when you change to CDC device you observe the issues?

NinjaRat84 commented 2 years ago

No, switching between CDC and FTDI.. When using FTDI, https://ftdichip.com/drivers/d2xx-drivers/ is used with custom handling.

Switching cable to use CDC makes it sometimes throwing this error :/

kai-morich commented 2 years ago

does the issue also happen with FTDI and usb-serial-for-android library?