kechankrisna / flutter_usb_printer

GNU General Public License v3.0
6 stars 50 forks source link

Not able to connect printer after disconnecting and re-connecting #14

Open arbile26 opened 2 years ago

arbile26 commented 2 years ago

When I print for the first time it works fine, but if the printer disconnects, whether the electricity is cut off or the cable is disconnected anyhow, the flutter app cannot connect to the printer anymore. It prints an error elaborating that the USB port is not available or restricted (already in use). I don't know how to free the USB port from use. I have tried the close() function in FlutterUsbPrinter but it didn't work.

arbile26 commented 2 years ago

Any updates?

arbile26 commented 2 years ago

V/Flutter USB Printer(17117): start to print raw data [B@32e3114
E/UsbManager(17117): exception in UsbManager.openDevice
E/UsbManager(17117): java.lang.IllegalArgumentException: device /dev/bus/usb/001/066 does not exist or is restricted
E/UsbManager(17117):    at android.os.Parcel.createExceptionOrNull(Parcel.java:2389)
E/UsbManager(17117):    at android.os.Parcel.createException(Parcel.java:2369)
E/UsbManager(17117):    at android.os.Parcel.readException(Parcel.java:2352)
E/UsbManager(17117):    at android.os.Parcel.readException(Parcel.java:2294)
E/UsbManager(17117):    at android.hardware.usb.IUsbManager$Stub$Proxy.openDevice(IUsbManager.java:1132)
E/UsbManager(17117):    at android.hardware.usb.UsbManager.openDevice(UsbManager.java:871)
E/UsbManager(17117):    at app.mylekha.client.flutter_usb_printer.adapter.USBPrinterAdapter.openConnection(USBPrinterAdapter.kt:145)
E/UsbManager(17117):    at app.mylekha.client.flutter_usb_printer.adapter.USBPrinterAdapter.write(USBPrinterAdapter.kt:203)
E/UsbManager(17117):    at app.mylekha.client.flutter_usb_printer.FlutterUsbPrinterPlugin.write(FlutterUsbPrinterPlugin.kt:117)
E/UsbManager(17117):    at app.mylekha.client.flutter_usb_printer.FlutterUsbPrinterPlugin.onMethodCall(FlutterUsbPrinterPlugin.kt:59)
E/UsbManager(17117):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/UsbManager(17117):    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/UsbManager(17117):    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/UsbManager(17117):    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/UsbManager(17117):    at android.os.Handler.handleCallback(Handler.java:938)
E/UsbManager(17117):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/UsbManager(17117):    at android.os.Looper.loop(Looper.java:247)
E/UsbManager(17117):    at android.app.ActivityThread.main(ActivityThread.java:8676)
E/UsbManager(17117):    at java.lang.reflect.Method.invoke(Native Method)
E/UsbManager(17117):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
E/UsbManager(17117):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
E/UsbManager(17117): Caused by: android.os.RemoteException: Remote stack trace:
E/UsbManager(17117):    at com.android.server.usb.UsbHostManager.openDevice(UsbHostManager.java:535)
E/UsbManager(17117):    at com.android.server.usb.UsbService.openDevice(UsbService.java:376)
E/UsbManager(17117):    at android.hardware.usb.IUsbManager$Stub.onTransact(IUsbManager.java:480)
E/UsbManager(17117):    at android.os.Binder.execTransactInternal(Binder.java:1190)
E/UsbManager(17117):    at android.os.Binder.execTransact(Binder.java:1159)
E/UsbManager(17117):
E/Flutter USB Printer(17117): failed to open USB Connection
V/Flutter USB Printer(17117): failed to connected to device
DowsingUK commented 1 year ago

I'm having the same issue any update?

vetri2592 commented 1 year ago

https://github.com/kechankrisna/flutter_usb_printer/pull/18 Chech the pull that will help you to solve it

ksabill commented 1 year ago

I have the same problem. Is there a solution?

crushman1 commented 10 months ago

Im having the same issue. closing the connection doesn't help. nothing seems to solve it.

ksabill commented 10 months ago

if (mUsbDevice != null) { mUsbDevice = null; Toast.makeText(context, "USB device has been turned off", Toast.LENGTH_LONG) .show() closeConnectionIfExists() }

//========================== I solved the problem using mUsbDevice = null; In class USBPrinterAdapter As shown in the code above