StarXpand SDK for React Native Developer's Manual Ver. 1.12.0

Last update: Mar 13, 2026

Pairing(Bluetooth Low Energy)

Use StarPrinter to connect to the printer or other devices (hereinafter referred to as the printer) via Bluetooth Low Energy results in a pairing process.

If the device and the printer have not been paired, a pairing request is presented to the user.
In addition, it is possible to determine the outcome of the user’s action in response to the pairing request.

Refer to the following steps to connect the device and the printer and receive the result of the pairing.

Memo

There are two pairing methods, which vary depending on the type of printer. For details, refer to the accompanying manual.
  • 「Passkey Entry」
  • A passkey entry is required. There is a time limit for input, and the required passkey value varies by model. Refer to the manual for each model and confirm the passkey to be entered in advance.
  • 「Numeric comparison」
  • Pairing codes are displayed on the host device and printed by the printer. Confirm that the pairing codes match, press the feed button on the printer, and approve the confirmation on the host device.

Pairing is performed only during the initial connection with the printer and will not occur again thereafter after a successful pairing.
However, if you reset the Bluetooth settings on your device or replace the printer, pairing will be required again.




Pairing procedure

Refer to the following steps to connect the device and the printer and receive the result of the pairing.

1Check the Bluetooth Low Energy connection information.
UseStarDeviceDiscoveryManager to check the Bluetooth Low Energy address of the printer to pair with.
There is sample codeat the bottom of the page. Refer to it as a reference.

2Create the printer’s connection target information.
Set theinterfaceTypeused for communication to BluetoothLE, set theidentifier to the Bluetooth Low Energy address of the destination.

var settings = new StarConnectionSettings();
settings.interfaceType = InterfaceType.BluetoothLE;
settings.identifier = “00:11:62:00:00:01”;

3Provide the printer’s connection target information and obtain a StarPrinter instance.
In case of iOS device, set the timeout to 30 seconds.

var printer = new StarPrinter(settings);
printer.openTimeout = 30_000

4Call the open method to connect to the printer.

try {
    await printer.open();

5 If the printer has not been paired with the device, the following pairing request screen will be displayed. Follow the on-screen instructions to proceed.

Caution
In case of Android device, disable “Silent Mode”. If it is enabled, the message required for pairing will not be notified, and the pairing operation cannot be completed.


6Implement error processing. You can determine pairing failure from the error instance type and StarIO10ErrorCode.

catch(error) {
    if (error instanceof StarIO10NotFoundError) {
        // Printer not found.
        // This may be due to the printer not being turned on or incorrect connection information.   
    }
    else if (error instanceof StarIO10IllegalDeviceStateError) {
        if (error.code == StarIO10ErrorCode.BluetoothUnavailable) {
            // The Bluetooth function of the host device cannot be used.
        }
        else if (error.code == StarIO10ErrorCode.BluetoothLeDeviceIsNotPaired) {
            // Pairing failed. Please try again with the correct operation.
        }
    }

    console.log(`Error: ${String(error)}`);
}

7Call the close method to disconnect from the printer.

finally {
    await printer.close();

8Call the dispose method to dispose the printer instance.

await printer.dispose();

Refer to the full sample code here.
Sample code : Check Bluetooth Low Energy connection information.
private _manager?: StarDeviceDiscoveryManager;

private startDiscovery = async() => {
  try {
    var interfaceTypes: Array<InterfaceType> = [InterfaceType.BluetoothLE];
    this._manager = await StarDeviceDiscoveryManagerFactory.create(interfaceTypes);
    this._manager.discoveryTime = 10000;
    this._manager.onPrinterFound = (printer: StarPrinter) => {
      var identifier = printer.connectionSettings.identifier;
      var deviceName = printer.information?.detail.bluetoothLE.deviceName;
      console.log(`Found printer: $identifier - $deviceName.`);
    };

    this._manager.onDiscoveryFinished = () => {
        console.log(`Discovery finished.`);
    };
    await this._manager.startDiscovery();
  }
  catch(error) {
    if (error instanceof StarIO10IllegalDeviceStateError) {
      if (error.codeCode == StarIO10ErrorCode.BluetoothUnavailable) {
          // Example of error: Bluetooth capability of host device is disabled.
          // This may be due to the host device's Bluetooth being off, the host device not having Bluetooth, etc. 
      }
    }
    console.log(`Error: ${String(error)}`);
  }
}

Sample code : Pairing
async function Pairing(identifier: String) {
    var settings = new StarConnectionSettings();
    settings.interfaceType = InterfaceType.BluetoothLE;
    settings.identifier = identifier;

    var printer = new StarPrinter(settings);

    try {
        await printer.open();
    }
    catch(error) {
        if (error instanceof StarStarIO10NotFoundError) {
            if (error.codeCode == StarIO10ErrorCode.BluetoothUnavailable) {
                // Printer not found.
                // This may be due to the printer not being turned on or incorrect connection information.   
            }
        }
        else if (error instanceof StarIO10IllegalDeviceStatError) {
            if (error.codeCode == StarIO10ErrorCode.BluetoothUnavailable) {
                // Example of error: Bluetooth capability of host device is disabled.
                // This may be due to the host device's Bluetooth being off, the host device not having Bluetooth, etc. 
            }
            else if (error.codeCode == StarIO10ErrorCode.BluetoothLeDeviceIsNotPaired) {
                // Pairing failed. Please try again with the correct operation
            }
        }
       console.log(`Error: ${String(error)}`);
    }
    finally {
        await printer.close();
        await printer.dispose();
    }
}