HeligPfleigh / react-native-thermal-receipt-printer

A RN library for thermal printer
169 stars 103 forks source link

Impossible to reconnect after physical disconnect #133

Open Florent75 opened 1 year ago

Florent75 commented 1 year ago

Current Behavior

Printer is physically disconnected from Tablet, and then physically reconnected.

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

software version
react-native 0.69.1
node v14.15.0

react-native-thermal-receipt-printer-image-qr : ^0.1.9

findxdn commented 1 year ago

have you solved this problem yet?

Florent75 commented 1 year ago

Hello, Nop, i didn't have time to solve the issue. I still have the same behaviour

Florent75 commented 1 year ago

To be more accurate : I don't know how to solve it. I am not really an expert on dev. I would really appreciate some help. Regards

Florent75 commented 1 year ago

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;
    }*/