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

Last update: February 9, 2024

Step 2 Sending Printing Data: Standard Function

You will send the printing data generated in Step 1 to the printer and print it.
To send the printing data, mainly use the StarPrinter class.

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 Create the printer destination information.
Set interfaceType, which is used for communication, and identifier, which specifies the destination.
If the destination printer has already been searched for in Search for Printer, this setting is unnecessary.
Set the StarPrinter instance acquired with the onPrinterFound method in the printer variable in Step2.

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

2 Provide the printer destination information to acquire the StarPrinter instance.

var printer = new StarPrinter(settings);

3 Set the printing data created in Step 1 in the commands variable.

try {
    var commands: string = ...

4 Call the open method to connect to the printer.

await printer.open();

5 Call the print method to send the printing data to the printer.

await printer.print(commands);

6 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 StarPrinter class methods.
- open method
- print method

}
catch(error) {
    if (error instanceof StarIO10NotFoundError) {
        // Printer not found.
        // This may be due to the printer not being turned on or incorrect connection information.   
    }

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

7 Call the close method to disconnect from the printer.

finally {
    await printer.close();

8 Call the dispose method to dispose the printer instance.

await printer.dispose();
Sample code

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

var printer = new StarPrinter(settings);

try {
    // Set the print data created in Step 1 to the commands variable. 
    var commands: string = ...
    await printer.open();
    await printer.print(commands);
}
catch(error) {
    if (error instanceof StarIO10NotFoundError) {
        // Printer not found.
        // This may be due to the printer not being turned on or incorrect connection information.
    }

    console.log(`Error: ${String(error)}`);
}
finally {
    await printer.close();
    await printer.dispose();
}