mik3y / usb-serial-for-android

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

write long data Fail #379

Closed boraylog closed 3 years ago

boraylog commented 3 years ago

try { val data: ByteArray? = HexUtils.toByteArray(address) usbSerialPort.write(data, 5000) } catch (e: Exception) { ToastUtils.showShort("fail message!-->${e.message}") } fail message!--> length=1000;index=1000 thanks

kai-morich commented 3 years ago

Very likely your write timeout is to short for the amount of data. See https://github.com/mik3y/usb-serial-for-android/wiki/FAQ#How_to_set_timeout_in_codereadcodecodewritecode_methods

kai-morich commented 3 years ago

What is your baud rate, data length and device type? Please provide full exception including call stack.

kai-morich commented 3 years ago

You pasted a code snippet, but not the exception type + callstack. You can print to logcat with e.printStackTrace(); or if you don't catch it at all, it will be shown after app crash in Android Studio logcat window.

What is your device type? Should be something like CH340, FT232, ...

boraylog commented 3 years ago

thank you very much. I found that the set array is out of bounds. thanks again.