UsbSerial icon indicating copy to clipboard operation
UsbSerial copied to clipboard

Could not read the data after connected long time.

Open williamtran1988 opened this issue 9 years ago • 1 comments

Hi All,

I have a USB connected to Android device for days, It was working properly but sometimes i could not read the USB data. When i unplug and plugged USB again, it works normally.

Can somebody know how to resolve this? is it I/O exception or something like that, Can we trigger an event?

Thank you very much!

williamtran1988 avatar Sep 22 '17 07:09 williamtran1988

Hi williams, i have problem too same to your but mine i cant get the response data, how did u do to get the repsonse bytes from the terminal?

here is my code

```

public void openDevice(UsbDevice device, int setBaundrate, SerialCommuncationListener.OpenDeviceListener listener) { UsbSerialDevice serialDevice; UsbDeviceConnection connection = usbManager.openDevice(device); serialDevice = UsbSerialDevice.createUsbSerialDevice(device, connection); if (serialDevice != null) { if (serialDevice.open()) { serialDevice.setBaudRate(setBaundrate); serialDevice.setDataBits(UsbSerialInterface.DATA_BITS_8); serialDevice.setStopBits(UsbSerialInterface.STOP_BITS_1); serialDevice.setParity(UsbSerialInterface.PARITY_NONE); serialDevice.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF); serialDevice.read(deviceRespond); listener.onConnectDeviceSuccess(serialDevice); } else { listener.onConnectDeviceFailure("Device can not open"); } } else { listener.onConnectDeviceFailure("Serial is null"); } }

public void sendCommandData(String id ,UsbSerialDevice usbSerialDevice,String data) { this.id = id; usbSerialDevice.write(data.getBytes()); usbSerialDevice.read(deviceRespond); }

// this ting not working private UsbSerialInterface.UsbReadCallback deviceRespond = new UsbSerialInterface.UsbReadCallback() { @Override public void onReceivedData(byte[] arg0) { Toast.makeText(mContext,"RESPONSE TERMINAL: "+arg0,Toast.LENGTH_LONG ).show(); mCallback.onDeviceResponse(id,arg0); }

};

JudeBautista avatar Oct 01 '18 11:10 JudeBautista