star-micronics / StarXpand-SDK-Android

StarXpand SDK for Android is a software development kit for supporting application development for Star Micronics devices.
https://star-m.jp/starxpandsdk-oml.html
Other
13 stars 0 forks source link

Printers discovery stops with the exception when `Bluetooth` or `LAN` interface types are used for discovery but not available on the phone. #12

Open alsedi opened 1 year ago

alsedi commented 1 year ago

Description

Printers discovery stops with the exception when Bluetooth or LAN interface types are used for discovery but not available on the phone. For example, Bluetooth is turned off (for InterfaceType.Bluetooth), or WIFI and 3G are turned off (for InterfaceType.LAN).

Your device where the bug occurs

Your printer

Your development environment

The result of executing the command ver on Windows, sw_vers on macOS, uname –a on Linux, or these equivalent commands.

> sw_vers
ProductName:        macOS
ProductVersion:     13.4
BuildVersion:       22F66

To Reproduce

Steps to reproduce the behavior:

  1. Turn on Bluetooth on the phone
  2. Pair the phone with a Star printer
  3. Create a new app, add Star SDK and add printers discovery code and run discovery, e.g.
    
    private val interfaceType = listOf(InterfaceType.Usb, InterfaceType.Lan, InterfaceType.Bluetooth)
    private val discoveryTimeMs = 10 * 1000
    private lateinit var discoveryManager: StarDeviceDiscoveryManager

try { discoveryManager = StarDeviceDiscoveryManagerFactory.create(interfaceType, context)

discoveryManager.apply {
    discoveryTime = discoveryTimeMs
    callback = object : StarDeviceDiscoveryManager.Callback {
        override fun onDiscoveryFinished() {
            AppLog.d("App -> Star Printers discovery finished")
        }

        override fun onPrinterFound(printer: StarPrinter) {        
            AppLog.d("StarSDK -> StarPrinter.toString(): $newPrinter")
        }
    }
}
AppLog.d("App -> Star Printers discovery is starting")
discoveryManager.startDiscovery()
AppLog.d("App -> Star Printers discovery started")

} catch (error: Exception) { AppLog.d("App -> Star Printers discovery process failed $error") }

5. Application should return all available printers in the LAN, connected by USB or paired and available via Bluetooth.
6. Turn off Bluetooth
7. Run printers discovery again
8. Check list of devices

## Expected behaviour
If BT is unavailable, discovery should not stop and should continue with other available connection types, network or USB. SDK should return all available printers in the LAN or connected via USB.

## Actual behavior
Discovery stops immediately with an exception. Printers available in LAN or connected via USB stay undiscovered.

Note. The same happens if Wifi & 3G are turned off. Available BT printers and those connected via USB will not be shown up.

## Motivation. 
The failure of one of the connection types should not be a reason for stopping printers discovery which may be available on other connection types, because hardware failure could be a result of an Android issue or hardware issue itself. It's good to know that something happened to network or Bluetooth but it is not a reason to prevent usage of other available connection types.

## Additional context
NB!: Chunks of original info partly replaced with `****` for privacy reasons.

Logs:

2023-06-20 14:25:47.998 App -> Star Printers discovery is starting 2023-06-20 14:25:47.998 App -> Star Printers discovery started 2023-06-20 14:25:48.122 BT Manager -> Paired Bluetooth devices: [:56:CB, :8E:74, :69:76, :84:CB] 2023-06-20 14:57:05.447 StarSDK -> StarPrinter.toString(): openTimeout : 10000, getStatusTimeout : 5000, printTimeout : 30000, connectionSettings : {interfaceType : Bluetooth, identifier : 56CB, autoSwitchInterface : false}, information : {model : mC_Print3, emulation : StarPRNT, reserved : {bluetoothAddress=56CB, macAddress=null, specifiedIdentifier=null, usbSerialNumber=null, device=:56:CB}} 2023-06-20 14:57:05.450 StarSDK -> StarPrinter.toString(): openTimeout : 10000, getStatusTimeout : 5000, printTimeout : 30000, connectionSettings : {interfaceType : Bluetooth, identifier : 8E74, autoSwitchInterface : false}, information : {model : Unknown, emulation : Unknown, reserved : {bluetoothAddress=8E74, macAddress=null, specifiedIdentifier=null, usbSerialNumber=null, device=:8E:74}} 2023-06-20 14:57:05.453 StarSDK -> StarPrinter.toString(): openTimeout : 10000, getStatusTimeout : 5000, printTimeout : 30000, connectionSettings : {interfaceType : Bluetooth, identifier : 6976, autoSwitchInterface : false}, information : {model : Unknown, emulation : Unknown, reserved : {bluetoothAddress=6976, macAddress=null, specifiedIdentifier=null, usbSerialNumber=null, device=:69:76}} 2023-06-20 14:57:05.457 StarSDK -> StarPrinter.toString(): openTimeout : 10000, getStatusTimeout : 5000, printTimeout : 30000, connectionSettings : {interfaceType : Bluetooth, identifier : 84CB, autoSwitchInterface : false}, information : {model : SM_L200, emulation : StarPRNT, reserved : {bluetoothAddress=84CB, macAddress=null, specifiedIdentifier=null, usbSerialNumber=null, device=:84:CB}} 2023-06-20 14:57:05.739 StarSDK -> StarPrinter.toString(): openTimeout : 10000, getStatusTimeout : 5000, printTimeout : 30000, connectionSettings : {interfaceType : Lan, identifier : E874, autoSwitchInterface : false}, information : {model : mC_Print3, emulation : StarPRNT, reserved : {bluetoothAddress=null, macAddress=E874, specifiedIdentifier=null, usbSerialNumber=null, configGateway=0.0.0.0, configIPAddress=0.0.0.0, configPrint=false, configSubnetMask=0.0.0.0, deviceClass=PRINTER, deviceCommandSet=STAR, deviceManufacture=Star, deviceModel=MCP31 (STR-001), deviceStatus=[41, -118, 2, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dhcp=true, firmwareVersionBoot=3.6, firmwareVersionMain=3.6, gateway=.1, hostName=, ipAddress=.2, ipAddressProtocol=DHCP, ipVersion=1, multiSession=false, name=mC-Print3, nameDetail=MCP31L, pldRevision= , productSerialNumber=49, rarp=false, responseVersion=4.0.0, subnetMask=.0, usedIPAddress=.255, usedPort=0}} 2023-06-20 14:57:05.788 StarSDK -> StarPrinter.toString(): openTimeout : 10000, getStatusTimeout : 5000, printTimeout : 30000, connectionSettings : {interfaceType : Lan, identifier : CD57, autoSwitchInterface : false}, information : {model : mC_Print3, emulation : StarPRNT, reserved : {bluetoothAddress=null, macAddress=CD57, specifiedIdentifier=null, usbSerialNumber=null, configGateway=0.0.0.0, configIPAddress=0.0.0.0, configPrint=false, configSubnetMask=0.0.0.0, deviceClass=PRINTER, deviceCommandSet=STAR, deviceManufacture=Star, deviceModel=MCP31 (STR-001), deviceStatus=[41, -118, 2, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dhcp=true, firmwareVersionBoot=3.6, firmwareVersionMain=3.6, gateway=.1, hostName=, ipAddress=.3, ipAddressProtocol=DHCP, ipVersion=1, multiSession=false, name=mC-Print3, nameDetail=MCP31L, pldRevision= , productSerialNumber=91, rarp=false, responseVersion=4.0.0, subnetMask=.0, usedIPAddress=.255, usedPort=0}} 2023-06-20 14:57:05.789 StarSDK -> StarPrinter.toString(): openTimeout : 10000, getStatusTimeout : 5000, printTimeout : 30000, connectionSettings : {interfaceType : Lan, identifier : 7A42, autoSwitchInterface : false}, information : {model : mC_Print3, emulation : StarPRNT, reserved : {bluetoothAddress=null, macAddress=7A42, specifiedIdentifier=null, usbSerialNumber=null, configGateway=0.0.0.0, configIPAddress=0.0.0.0, configPrint=false, configSubnetMask=0.0.0.0, deviceClass=PRINTER, deviceCommandSet=STAR, deviceManufacture=Star, deviceModel=MCP31 (STR-001), deviceStatus=[41, -118, 2, 0, 0, 4, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dhcp=true, firmwareVersionBoot=3.6, firmwareVersionMain=3.6, gateway=.1, hostName=, ipAddress=.4, ipAddressProtocol=DHCP, ipVersion=1, multiSession=false, name=mC-Print3, nameDetail=MCP31LB, pldRevision= , productSerialNumber=53, rarp=false, responseVersion=4.0.0, subnetMask=.0, usedIPAddress=.255, usedPort=0}} 2023-06-20 14:57:05.790 StarSDK -> StarPrinter.toString(): openTimeout : 10000, getStatusTimeout : 5000, printTimeout : 30000, connectionSettings : {interfaceType : Lan, identifier : 7A20, autoSwitchInterface : false}, information : {model : mC_Print3, emulation : StarPRNT, reserved : {bluetoothAddress=null, macAddress=7A20, specifiedIdentifier=null, usbSerialNumber=null, configGateway=0.0.0.0, configIPAddress=0.0.0.0, configPrint=false, configSubnetMask=0.0.0.0, deviceClass=PRINTER, deviceCommandSet=STAR, deviceManufacture=Star, deviceModel=MCP31 (STR-001), deviceStatus=[41, -118, 2, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dhcp=true, firmwareVersionBoot=3.7, firmwareVersionMain=3.7, gateway=.1, hostName=, ipAddress=.5, ipAddressProtocol=DHCP, ipVersion=1, multiSession=false, name=mC-Print3, nameDetail=MCP31LB, pldRevision= , productSerialNumber=79, rarp=false, responseVersion=4.0.0, subnetMask=.0, usedIPAddress=.255, usedPort=0}} 2023-06-20 14:57:05.790 StarSDK -> StarPrinter.toString(): openTimeout : 10000, getStatusTimeout : 5000, printTimeout : 30000, connectionSettings : {interfaceType : Lan, identifier : F7D0, autoSwitchInterface : false}, information : {model : mC_Print3, emulation : StarPRNT, reserved : {bluetoothAddress=null, macAddress=F7D0, specifiedIdentifier=null, usbSerialNumber=null, configGateway=0.0.0.0, configIPAddress=0.0.0.0, configPrint=false, configSubnetMask=0.0.0.0, deviceClass=PRINTER, deviceCommandSet=STAR, deviceManufacture=Star, deviceModel=MCP31 (STR-001), deviceStatus=[41, -118, 2, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dhcp=true, firmwareVersionBoot=3.6, firmwareVersionMain=3.6, gateway=.1, hostName=, ipAddress=.6, ipAddressProtocol=DHCP, ipVersion=1, multiSession=false, name=mC-Print3, nameDetail=MCP31L, pldRevision= , productSerialNumber=28, rarp=false, responseVersion=4.0.0, subnetMask=.0, usedIPAddress=.255, usedPort=0}} 2023-06-20 14:57:05.791 StarSDK -> StarPrinter.toString(): openTimeout : 10000, getStatusTimeout : 5000, printTimeout : 30000, connectionSettings : {interfaceType : Lan, identifier : E4C0, autoSwitchInterface : false}, information : {model : mC_Print3, emulation : StarPRNT, reserved : {bluetoothAddress=null, macAddress=E4C0, specifiedIdentifier=null, usbSerialNumber=null, configGateway=0.0.0.0, configIPAddress=0.0.0.0, configPrint=false, configSubnetMask=0.0.0.0, deviceClass=PRINTER, deviceCommandSet=STAR, deviceManufacture=Star, deviceModel=MCP31 (STR-001), deviceStatus=[41, -118, 2, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dhcp=true, firmwareVersionBoot=3.7, firmwareVersionMain=3.7, gateway=.1, hostName=, ipAddress=.7, ipAddressProtocol=DHCP, ipVersion=1, multiSession=false, name=mC-Print3, nameDetail=MCP31L, pldRevision= , productSerialNumber=35, rarp=false, responseVersion=4.0.0, subnetMask=.0, usedIPAddress=.255, usedPort=0}} 2023-06-20 14:25:47.998 App -> Star Printers discovery finished


If BT is turned off:

2023-06-20 15:12:50.127 D Star Printers discovery is starting 2023-06-20 15:12:50.129 D Star Printers discovery process failed: com.starmicronics.stario10.StarIO10IllegalHostDeviceStateException: Bluetooth unavailable. errorCode: BluetoothUnavailable


if Lan/3G are not available:

2023-06-20 15:19:22.620 D Star Printers discovery process failed: com.starmicronics.stario10.StarIO10IllegalHostDeviceStateException: Network unavailable. errorCode: NetworkUnavailable

Tatsuki-Yamamoto2731 commented 4 months ago

@alsedi Apologies for the delayed response to this issue.

I understood the problem you've encountered, and regret to inform you that our current library indeed behaves as you have described. We appreciate your request and acknowledge the issue you've raised. We will take your feedback into consideration for potential improvements in our library.

As a temporary workaround, I suggest attempting a re-discovery excluding the interface that triggered the errorCode: BluetoothUnavailable or errorCode: NetworkUnavailable. This might serve as a viable method to continue discovery on available connection types.

Please consider trying this approach and let us know if it helps with your situation.