star-micronics / react-native-star-io10

react-native-star-io10 is a library for supporting application development for Star Micronics devices.
Other
89 stars 55 forks source link

Android - printer.open() always results in StarIO10CommunicationError: Open failed. #78

Closed NTKrieger closed 2 years ago

NTKrieger commented 2 years ago

Description

printer.open() always results in StarIO10CommunicationError: Open failed.

Your device where the bug occurs

Your printer

Your development environment

System: OS: macOS 12.4 CPU: (10) arm64 Apple M1 Max Memory: 20.29 GB / 64.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node Yarn: 1.22.19 - ~/.yarn/bin/yarn npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm Watchman: 2022.09.05.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5 Android SDK: API Levels: 24, 25, 26, 27, 28, 29, 30, 31, 32 Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3, 31.0.0, 33.0.0 System Images: android-28 | Google ARM64-V8a Play ARM 64 v8a, android-31 | Google APIs ARM 64 v8a, android-31 | Google Play ARM 64 v8a, android-31 | Google Play Intel x86 Atom_64, android-32 | Google Play ARM 64 v8a Android NDK: 22.1.7171670 IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8609683 Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild Languages: Java: 11.0.13 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.68.2 => 0.68.2 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

To Reproduce

Steps to reproduce the behavior:

Below is a minimal representation of the code I am attempting to run. I have already paired the device with the printer at this point through the Android system bluetooth menu.

  if (await canUseBluetooth()){
    try {
      const manager = await StarDeviceDiscoveryManagerFactory.create([InterfaceType.Bluetooth]);

      manager.onPrinterFound = async (printer) => {
        console.log('printer', printer);
        await printer.open();
        const status = await printer.getStatus();
        console.log('status', status);
        await printer.close();
        await printer.dispose();
      };

      manager.onDiscoveryFinished = () => {
        console.log('Discovery finished.');
      };

      manager.discoveryTime = 5000;
      await manager.startDiscovery();

    } catch (error) {
      // Error.
      console.log('printInvoice', error);
    }
  }

Expected behavior

Printer socket should be established and status printed to the console.

Logcat logs (package name and bluetooth UUID redacted)

2022-09-12 14:25:22.200 31829-31829/[PACKAGE_NAME] W/StarPrinterInformation: Reserved parameter. 2022-09-12 14:25:22.217 31829-32002/[PACKAGE_NAME] I/ReactNativeJS: 'printer', { _lock: { _locked: false, _sleep: [Function] }, _eventSubscriptions: [ { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] }, { remove: [Function: remove] } ], _printerDelegate: { _onEventSet: [Function: _callee], _onReady: [Function], _onError: [Function], _onPaperReady: [Function], _onPaperNearEmpty: [Function], _onPaperEmpty: [Function], _onCoverOpened: [Function], _onCoverClosed: [Function], onCommunicationError: [Function] }, _drawerDelegate: { _onEventSet: [Function: _callee2], _onOpenCloseSignalSwitched: [Function], onCommunicationError: [Function] }, _inputDeviceDelegate: { _onEventSet: [Function: _callee3], _onConnected: [Function], _onDisconnected: [Function], _onDataReceived: [Function], onCommunicationError: [Function] }, _displayDelegate: { _onEventSet: [Function: _callee4], _onConnected: [Function], _onDisconnected: [Function], onCommunicationError: [Function] }, _information: { _model: 'Unknown', _emulation: 'Unknown', _reserved: {} }, openTimeout: 10000, printTimeout: 30000, getStatusTimeout: 5000, _connectionSettings: { interfaceType: 'Bluetooth', identifier: [VALID BLUETOOTH ADDRESS], autoSwitchInterface: false } } 2022-09-12 14:25:22.258 31829-32189/[PACKAGE_NAME] D/BluetoothUtils: isSocketAllowedBySecurityPolicy start : device null 2022-09-12 14:25:22.258 31829-32189/[PACKAGE_NAME]W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback 2022-09-12 14:25:22.730 31829-32189/[PACKAGE_NAME] E/BluetoothAdapter: notifyPackageNameForWifi [PACKAGE_NAME]/10253 ---- the above three lines repeat for however many retries ----- 2022-09-12 14:25:34.461 31829-32002/[PACAKAGE_NAME] W/ReactNativeJS: Possible Unhandled Promise Rejection (id: 1): StarIO10CommunicationError: Open failed. StarIO10CommunicationError: Open failed.

Other things I've tried

NTKrieger commented 2 years ago

The reason for this was a setting on the printer itself. It must be set to Bluetooth Mode not Bluetooth (iAP). I hope this helps someone.