Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot reconnect after physical disconnect #97

Open
Florent75 opened this issue Feb 14, 2023 · 1 comment
Open

Cannot reconnect after physical disconnect #97

Florent75 opened this issue Feb 14, 2023 · 1 comment

Comments

@Florent75
Copy link

Current Behavior

Printer is connected to Samsung Galaxy tab using a USB HUB.
Init has been done using USBPrinter.init()
Discover has been done using USBPrinter.getDeviceList()
Connect has been done using USBPrinter.connectPrinter()
Print has been done using USBPrinter.printText("sample text")
Print is WORKING :) !
Printer is physically disconnected from Tablet, and then physically reconnected.

closeConn has been done using USBPrinter.closeConn()
Init has been done using USBPrinter.init()
Discover has been done using USBPrinter.getDeviceList()
Connect has been done using USBPrinter.connectPrinter()
Print has been done using USBPrinter.printText("sample text")
Print is KO : I got a "failed to connected to device" error.

I need to restart the whole app to make It work again

Expected Behavior

No need to restart the whole app. Print should be working as expected.

Your Environment

@Florent75
Copy link
Author

Florent75 commented Feb 17, 2023

Hi there,
After digging into the code, and more precisely USBPrinterAdapter.java,
it seems that it's coming from the following lines : l154 - l 163

After physical disconnect and reconnect, the productID and vendorID are the same, but as far as I have understand the bus used has been changed.
Thought, It's not right to consider that the module should not reconnect.

I know it's a hack but, commenting this lines make it work. As a consequence, the module will connect everytime the function is called, even is all the connect data are the same.

For a more robust solution,
I would recommend checking the DeviceId or DeviceName to ensure that the bus has not been changed.
I am still trying to figure out how to get the values and check this values :).

/*
    if (mUsbDevice != null && mUsbDevice.getVendorId() == usbPrinterDeviceId.getVendorId() && mUsbDevice.getProductId() == usbPrinterDeviceId.getProductId()) {
        Log.i(LOG_TAG, "already selected device, do not need repeat to connect");
        if (!mUSBManager.hasPermission(mUsbDevice)) {
            closeConnectionIfExists();
            mUSBManager.requestPermission(mUsbDevice, mPermissionIndent);
        }
        successCallback.invoke(new USBPrinterDevice(mUsbDevice).toRNWritableMap());
        return;
    }*/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant