1. API Reference
API list¶
Constructor¶
| Contents | Description |
|---|---|
| PrinterManager | A constructor of the PrinterManager class. |
Methods¶
| Contents | Description |
|---|---|
| start | Starts communication with the SDK server. |
| stop | Disconnects from the SDK server. |
| doPrint | Sends the data in the buffer to the printer and prints it. |
| appendFeed | Adds a paper feed request to the buffer. |
| appendMarkFeed | Adds a paper form feed request of marked paper or label to the buffer. |
| appendBinary | Adds binary data to the buffer. |
| appendImage | Adds an image to the buffer. |
| onDeviceStatus | Specifies or cancels the callback function to be executed when the printer status changes. |
| doReset | Resets the printer. |
| getVersion | Gets the SDK version as the character string. |
| selectSmartLabelFile | Specifies the label file (*.slex) to use the label printing function. |
| appendSmartLabelFile | Adds the specified label file to the buffer. |
| replaceSmartLabelTextData | Replaces the value of the text object in the specified label file. |
| replaceSmartLabelImageData | Replaces the image object in the specified label file. |
| replaceSmartLabelBarcodeData | Replaces the value of the barcode object in the specified label file. |
Common for Each Method and Property¶
- The settings of each method and property cannot be executed in parallel. Do not execute the next method or set the next property until the method has returned the retuen value or the property setting has been completed.
Return Value¶
The each method returns the following object as the return value unless otherwise instructions. (This object is hereafter referred to as the result object.)
Return Value
{
[(Elements specific to each method),]
errorCode: errorCode,
errorString: errorString,
errorExtendedString: errorExtendedString
}
Element
(Elements specific to each method)
Element specific to each method. See each method description for details. Methods with no return value listed in the method description have no element specific to the method.
errorCode
Error code. Type is numeric.
errorString
Error string. Type is a character string.
errorExtendedString
Error extension string. Stores error details. The type is a string.
Reference
- In the "Syntax" section within each method description, optional elements are indicated by surrounding them with '[', ']'.
PrinterManager¶
A constructor of the PrinterManager class.
Syntax
public PrinterManager()
Parameter
NoneSpecifing parameters is not required.
Return Value
Returns an instance of the PrinterManager class.
start¶
Starts communication with the SDK server.
Syntax
async start( { [ lockDevice: lockDevice ] } )
Parameter
lockDevice
Specify whether the device should be locked so that it cannot be accessed by other hosts or software with a boolean.
When locking, the time to send a command to a device is reduced, but the device cannot be shared with other hosts.
Optional (default: false).
When the device goes to sleep, the lock may be temporarily unlocked.
Clicking the "Back" button or reloading the browser will disconnect communication with the SDK server. In that case, call the start method again.
When connecting to a device via Wireless LAN or Ethernet, the lock is canceld after the device's TCP Socket Port timeout period has elapsed since the start of the connection to the device or the last data transmission.
Description
Call this method before using any other methods in the PrinterManager class.
The buffer is cleared.
Select the device on the SDK server before calling this method. The device cannot be selected again on the SDK server until the stop method is called after this method is called.
Reference
- The Web SDK server accepts only 1 connection at the same time. When connecting from other pages, etc., terminate the connection with the Web SDK server by using the stop method on the currently connected Web page.
- When the Android device or Windows PC goes into sleep, the connection to the Web SDK server is disconnected.
- If a connection is made to the Web SDK server from a page that is not the original page, the Web SDK server will clear the data in the buffer it holds.
- If the error code -605 (Error due to failure to connect to Web SDK server) is returned when executing each method, execute the start method after executing the stop method. The stop method may return an error.
- If the error code -201 (Error due to timeout) is returned when executing the appendXXX method, execute the start method again. At the time, the buffer is cleared, so execute the appendXXX method again from the beginning.
stop¶
Terminates device status monitoring and connection to the Web SDK server.
Syntax
async stop( { } )
Parameter
NoneSpecify an empty object.
doPrint¶
Sends and prints the data in the buffer added by the appendXXX method.
Syntax
async doPrint( { [ timeout: timeout] } )
Parameter
timeout
Specify the print timeout as a number. The unit is seconds.
The valid value is -1, 10 to 300. If -1 is specified, print timeout is disabled. If the Taken Mode of the printer setting is set to enabled, specify -1.
Optional (default: 90).
Return Value
Returns the result object including the following elements.
printIdReturns the print ID as a number.
Description
Sends and prints the data stored in the buffer in the SDK server to the printer.
The maximum size of the buffer in the SDK server is 10 MB.
If the callback function is set for the onDeviceStatus, notices the completion of printing when printing is normally completed.
If an error is detected during printing, the completion of printing will not be notified.
The contents of the buffers in the SDK server are cleared in the following cases.
appendBinary¶
Adds binary data to the buffer.
Syntax
async appendBinary( { data: data } )
Parameter
text
Specify binary data as a blob.
The data size that can be specified at 1 time is 16KB (16384 bytes).
Note that the data is converted to Base64 format before transmission. Therefore, the maximum size of binary data that can actually be specified is 12KB (12288 bytes).
Cannot be omitted.
Description
This method adds the specified binary data to the buffer without conversion.
By sending printer commands as binary data with this method, printer functions which are not supported in the library become available. However, this method does not support commands which get responses from the printer.
A single printer command cannot be sent to the printer multiple times using doPrint.
appendImage¶
Adds the specified image to the buffer.
Syntax
async appendImage( { format: format,
data: data,
[ alignment: alignment] } )
Parameter
format
Specify the image data format by character string.
The values that can be specified are 'jpeg', 'png', or 'bmp'.
Cannot be omitted.
data
Specify image data as a blob.
The size of the image data that can be specified is 3 MB (3145728 bytes).
Specify image data in the same format specified with format.
When the color image is specified, it is converted to monochrome image.
Cannot be omitted.
alignment
Specify the alignment by character string.
The values that can be specified are 'left', 'center', or 'right'.
Optional (default: center).
appendFeed¶
Adds the paper feed request to the buffer.
Syntax
async appendFeed( { value: value } )
Parameter
value
Specify the paper feed amount by a numerical value.
See the table below for available values.
Cannot be omitted.
| Printer | Range of feed value |
|---|---|
| SLP850 | -160 to 8000 |
appendMarkFeed¶
Adds the paper form feed request of marked paper or label to the buffer.
Syntax
async appendMarkFeed( { [ feedPosition: feedPosition ] } )
Parameter
feedPosition
Specify the paper form feed position by character string.
The values that can be specified are 'cutPosition', or 'printPosition'.
Optional (default: 'cutPosition').
| feedPosition | Description |
|---|---|
| cutPosition | Feeds the paper to the cutting position after detecting the mark or gap. |
| printPosition | Feeds the paper to the printing position after detecting the next mark or next gap. |
Warning
- Set the mark mode to enable in the memory switch settings of the printer beforehand when performing the paper form feed of marked paper or label.
onDeviceStatus¶
Specifies or cancels the callback to be executed when the printer status changes.
When canceling, specify NULL.
While a callback is specified by onDeviceStatus, no other host can send to the printer or obtain printer status.
Exceptions occurred during the callback call are ignored.
Syntax
onDeviceStatus = function( object )
Description
Returns an object including the following elements when the printer's state changes.
For those with a value in "Priority", executes the callback only for the higher priority state.
| 'type' | 'status' | priority | Description |
|---|---|---|---|
| 'error' | 'communication error' | - | Communication error (when unable to connect to the printer such as 26100 connection) |
| 'error' | 'timeout error' | - | Timeout error |
| 'error' | 'hardware error' | 1 | Hardware error |
| 'error' | 'head temperature error' | 2 | Head temperature error |
| 'error' | 'voltage error' | 3 | Voltage error |
| 'error' | 'paper jam error' | 4 | Paper jam error while detecting mark |
| 'error' | 'out-of-paper error' | 5 | Out-of-paper error |
| 'info' | 'print-ready' | 6 | Print-ready status |
| 'info' | 'printing finished' | - | Detects end of printing |
doReset¶
Resets the printer.
Syntax
async doReset( {} )
Parameter
NoneSpecify an empty object.
getVersion¶
Gets the SDK version as the character string.
Syntax
async getVersion( { } )
Parameter
NoneSpecify an empty object.
Return value
Returns the result object including the following elements.
versionSDK version string (e.g., if the SDK server version is Ver. 1.0.0 and the SDK version is Ver. 1.0.1, the return value is '1.0.0/1.0.1')
selectSmartLabelFile¶
Specifies the label file (*.slex) required to use the label printing function.
Syntax
async selectSmartLabelFile( { data: data } )
Parameter
data
Specify label file data by blob.
Cannot be omitted.
Description
This method specifies the label file (*.slex) required to use the label printing function.
The specified label file remains valid until either the selectSmartLabelFile method or the stop method is executed.
The following methods can be executed on the label file specified by this method.
appendSmartLabelFile, replaceSmartLabelTextData, replaceSmartLabelImageData, replaceSmartLabelBarcodeData
appendSmartLabelFile¶
Adds the specified label file (*.slex) to the buffer.
Syntax
async appendSmartLabelFile( {[autoFeedCut: autoFeedCut,]} )
Parameter
autoFeedCut
Specify whether to control using the label file settings by character string.
The values that can be specified are 'Enable', or 'Disable'.
Optional (default: 'Enable').
Description
This method adds the label file specified by selectSmartLabelFile to the buffer.
replaceSmartLabelTextData¶
Replaces the value of the text object in the specified label file.
Syntax
async replaceSmartLabelTextData( { mapId: mapId,
text: text})
Parameter
mapId
Specify the mapId of the text object to be replaced as a numeric value.
Cannot be omitted.
text
Specify the text data to be replaced as a character string.
Cannot be omitted.
Description
This method replaces the value of the text object in the label file specified by selectSmartLabelFile.
replaceSmartLabelImageData¶
Replaces the image object in the specified label file.
Syntax
async replaceSmartLabelImageData( { mapId: mapId,
format: format,
data: data,})
Parameter
mapId
Specify the mapId of the image object to be replaced as a numeric value.
Cannot be omitted.
format
Specify the format of the image data to be replaced as a character string.
The values that can be specified are 'jpeg', 'png', or 'bmp'.
Cannot be omitted.
data
Specify the image data to be replaced as a blob.
The valid size of the image data that can be specified is 3 MB (3145728 bytes).
Cannot be omitted.
Description
This method replaces the value of the image object in the label file specified by selectSmartLabelFile.
replaceSmartLabelBarcodeData¶
Replaces the value of the barcode object in the specified label file.
Syntax
async replaceSmartLabelBarcodeData( { mapId: mapId,
[text: text,]
[data: data,]})
Parameter
mapId
Specify the mapId of the barcode object to be replaced as a numeric value.
Cannot be omitted.
text
Specify the barcode data to be replaced as a character string.
Be sure to specify text or data.
data
Specify the barcode data to be replaced as a blob.
Be sure to specify text or data.
Description
This method replaces the value of the barcode object in the label file specified by selectSmartLabelFile.
Error Code¶
| Error Code | Discription |
|---|---|
| 0 | Success |
| -21 | Failed to connect to printer. |
| -24 | No printer is selected. |
| -111 | An error occurred in the encoding of the property. |
| -201 | Print timed out. |
| -202 | Aborted during data conversion. |
| -203 | The start method needs to be called. |
| -299 | Failed to parse response from Web SDK server. |
| -299 | Failed to parse request from Web SDK. |
| -311 | Failed to allocate memory. |
| -420 | Printer error occurred. |
| -503 | An error occurred during the data conversion. |
| -521 | The label file is not selected. |
| -522 | Failed to create the label image. |
| -601 | Unable to connect to Web SDK server. |
| -602 | The Web SDK server does not support this SDK version. Web SDK does not support this version of Web SDK Server. |
| -604 | Web SDK server is busy. |
| -605 | Communication with the SDK server is not connected. Failed to reconnect to Web SDK server. Accessed from another web page while the connection to the Web SDK server was disconnected. |
| -9999 | The object is not specified in the method argument. No property. Invalid property type. Invalid property value. Unknown property was specified. |