Search for Printer
Use StarDeviceDiscoveryManager to asynchronously search for the printer.
When you start a search, events occur in the order where they are found, and you can acquire the StarPrinter instance instantly.
Memo
The StarPrinter instance provides the functions required to communicate with the printer.
There are two methods, including searching, to acquire the StarPrinter method.
- Method to acquire by searching (Step 8 on this page)
- Method to generate by passing interfaceType and identifier to the constructor of the StarPrinter class
By using this StarPrinter instance, you can send printing data to the printer and control POS peripheral devices.
Send the printing data using the procedure below.
The sample code is available at the bottom of the page.
Also, refer to the sample application in the SDK.
1 Prepare a StarDeviceDiscoveryManager type variable used for searching.
private _manager?: StarDeviceDiscoveryManager;
2 Select the target interface. Generate the InterfaceType array you would like to search for.
private startDiscovery = async() => {
try {
var interfaceTypes: Array<InterfaceType> = [InterfaceType.Lan, InterfaceType.Bluetooth];
3 Acquire the StarDeviceDiscoveryManager instance using the array generated in Step2 as an argument.
this._manager = await StarDeviceDiscoveryManagerFactory.create(interfaceTypes);
4 Set the search time.
this._manager.discoveryTime = 10000;
5 Implement the process for when the printer is found. Set the delegate method for when the printer is found in the onPrinterFound property.
this._manager.onPrinterFound = (printer: StarPrinter) => {
console.log(`Found printer: ${printer.connectionSettings.identifier}.`);
};
6 Implement the process for when the search is finished. Set the delegate method for when the search is finished in the onDiscoveryFinished property.
this._manager.onDiscoveryFinished = () => {
console.log(`Discovery finished.`);
};
7 Call the startDiscovery method to start searching.
When the printer is found, the delegate method implemented in Step5 is called. When the search is finished, the delegate method implemented in Step6 is called.
await this._manager.startDiscovery();
8 Implement the process for when an error occurs. You can identify the error cause based on the error instance type.
Possible errors are described in the API reference of the create method of the StarDeviceDiscoveryManagerFactory class and the startDiscovery method of the StarDeviceDiscoveryManager class.
}
catch(error) {
if (error instanceof StarIO10IllegalDeviceStateException) {
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
private _manager?: StarDeviceDiscoveryManager;
private startDiscovery = async() => {
try {
var interfaceTypes: Array<InterfaceType> = [InterfaceType.Lan, InterfaceType.Bluetooth];
this._manager = await StarDeviceDiscoveryManagerFactory.create(interfaceTypes);
this._manager.discoveryTime = 10000;
this._manager.onPrinterFound = (printer: StarPrinter) => {
console.log(`Found printer: ${printer.connectionSettings.interfaceType } ${printer.connectionSettings.identifier}.`);
};
this._manager.onDiscoveryFinished = () => {
console.log(`Discovery finished.`);
};
await this._manager.startDiscovery();
}
catch(error) {
if (error instanceof StarIO10IllegalDeviceStateException) {
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)}`);
}
}
Monitoring the RSSI (Radio Signal Strength) of Bluetooth LE Devices
You can use the StarDeviceDiscoveryManager API to obtain the RSSI value of a Star Micronics Bluetooth LE device (*1) near the host device.
*1: For the list of Star Micronics Bluetooth LE devices that support this feature, refer to the StarPrinterInformationBluetoothLE.rssi API reference.
Use Case
- Using the RSSI value of a Bluetooth LE device as a reference for determining whether the host device is near the target Bluetooth LE device, as well as any peripheral connected to it, such as a cash drawer.
Related APIs
Sample Code
private _manager?: StarDeviceDiscoveryManager;
private startDiscovery = async() => {
try {
var interfaceTypes: Array<InterfaceType> = [InterfaceType.BluetoothLE];
this._manager = await StarDeviceDiscoveryManagerFactory.create(interfaceTypes);
manager.isEnabledFindSameDevice = true; // Enables continuous detection of the same device.
this._manager.discoveryTime = 10000;
this._manager.onPrinterFound = (printer: StarPrinter) => { // The detected Bluetooth LE device is passed to the property.
var rssi = printer.information?.detail.bluetoothLE?.rssi;
if (rssi != undefined) {
console.log(`RSSI: ${rssi}`); // You can obtain the RSSI value as shown here.
}
};
this._manager.onDiscoveryFinished = () => {
console.log(`Discovery finished.`);
};
await this._manager.startDiscovery();
}
catch(error) {
if (error instanceof StarIO10IllegalDeviceStateException) {
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)}`);
}
}
Notes
- RSSI values are generally higher when devices are closer together. However, a value can vary depending on factors such as the models of the host device and the Bluetooth LE device, the radio characteristics of each device, the orientation of the Bluetooth LE device, and the surrounding environment (for example, radio interference or obstructions).
- Before deploying an application that uses this API, test it thoroughly in the actual environment where it will run.
- When using RSSI values to determine whether the host device is near the cash drawer, we do not recommend opening the cash drawer based solely on that determination without any user action, for security reasons.
- We recommend designing your implementation to handle cases where the target Bluetooth LE device cannot be detected, for example due to radio interference or obstructions.

