[Development issues] usb-serial-for-android

Cannot read the USB device again after the program restarts

  • Plug in the USB device, the program runs, everything is normal. Close the program and open it again, the device and port can be obtained until an Port.open(connection)error occurs
  • Using RK3188 5.1 system
  • The sensor is a body temperature sensor, use this open source CH34 to USB
/MainActivity: connection: android.hardware.usb.UsbDeviceConnection@3b3b49f1
/UsbDeviceConnectionJNI: close
/MainActivity: 打开端口失败

java.io.IOException: Expected 0xff bytes, but get 0x9f [init #6]
    at com.hoho.android.usbserial.driver.Ch34xSerialDriver$Ch340SerialPort.checkState(Ch34xSerialDriver.java:158)
    at com.hoho.android.usbserial.driver.Ch34xSerialDriver$Ch340SerialPort.initialize(Ch34xSerialDriver.java:184)
    at com.hoho.android.usbserial.driver.Ch34xSerialDriver$Ch340SerialPort.openInt(Ch34xSerialDriver.java:113)
    at com.hoho.android.usbserial.driver.CommonUsbSerialPort.open(CommonUsbSerialPort.java:116)
    at com.example.tempermodular.TemperMoudle$1.onReceive(TemperMoudle.java:103)
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:866)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5258)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:940)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:735)
  • After downloading and running the code on GITHUB , the same problem occurs .

answer

  • Since my sensor is used when receiving data setRTS(true), this can cause such problems, so I just need to first shut down the port setRTS(false). It's a bit pitted.

Guess you like

Origin blog.csdn.net/qq_36881363/article/details/104861952