new Device(deviceJson)
Represents a device. This object is passed to the client application to determine which device to communicate with.
A device is never instantiated directly, it is supplied by the native application.
Client API Level 2
Parameters:
Name |
Type |
Description |
deviceJson |
string
|
Json describing this device |
Properties:
Name |
Type |
Description |
Device.sendErrorCallback |
ResponseCallback
|
Function that is called if the errorCallback is not included for a send operation |
Device.sendFinishedCallback |
ResponseCallback
|
Function that is called if a finishedCallback is not included for a send operation |
Device.readErrorCallback |
ResponseCallback
|
Function that is called if an errorCallback is not included for a read operation |
Device.readFinishedCallback |
ResponseCallback
|
Function that is called if an finishedCallback is not included for a read operation |
Members
connection :string
The connection type. Possible values are 'network', 'usb', 'bluetooth'
Type:
deviceType :string
The type of device.
Type:
name :string
The friendly name of the device. This will be generated based on the response from discovered network printers. For USB printers, this value will be the same as the uid
Type:
readRetries :number
The default number of times to retry on reads when no data is received. Set to 1 for bluetooth connections, otherwise 0.
Type:
Methods
convertAndSendFile(resource, finishedCallbackopt, errorCallbackopt, optionsopt)
Send contents of url or blob to the device. If the url points to an image file (bmp, jpg, png, tif, gif) or PDF, it will automatically be converted to a printer command language. This method is a wrapper for BrowserPrint.convert
Client API Level 4
Parameters:
Name |
Type |
Attributes |
Description |
resource |
string
|
blob
|
|
The url from which data will be retrieved and be sent to the device |
finishedCallback |
ResponseCallback
|
<optional>
|
The function that is called when sending is completed. |
errorCallback |
ResponseCallback
|
<optional>
|
The function that is called when an error occurs while sending. |
options |
object
|
<optional>
|
Options for converting the file.
Properties
Name |
Type |
Attributes |
Description |
toFormat |
string
|
'zpl'
|
'cpcl'
|
'kpl'
|
'none'
|
<optional>
|
The format the file should be converted to. Options are zpl, cpcl, kpl, and none. If 'none' is provided, the resource will not be converted to a different format before sending to or storing on the device. Default value is zpl. |
fromFormat |
string
|
<optional>
|
The format of the resource provided. If not specified, the application will attempt to determine the format based on the file type or file structure. |
action |
string
|
'print'
|
'store'
|
'return'
|
<optional>
|
The action to take with the converted data. 'print' will attempt to make the converted resource printable and send it to the printer. 'store' will attempt to make the resource storable and store it at the path provide. 'return' will convert the resource and return it to the browser. |
resize.width |
int
|
<optional>
|
The width an image resource should be resized to |
resize.height |
int
|
<optional>
|
The height an image resource should be resized to |
fitTo.width |
int
|
<optional>
|
Scale an image resource so that it fits into a rectangle described by fitTo.width and fitTo.height, maintaining aspect ratio. |
fitTo.height |
int
|
<optional>
|
Scale an image resource so that it fits into a rectangle described by fitTo.width and fitTo.height, maintaining aspect ratio. |
scale |
float
|
<optional>
|
Scale an image resource by the this factor. |
featureKey |
string
|
<optional>
|
The licensing key for the resource conversion. Currently, only converting from a PDF format requires a licensing key |
|
read(finishedCallbackopt, errorCallbackopt)
Read data from the device
Client API Level 2
Parameters:
Name |
Type |
Attributes |
Description |
finishedCallback |
ResponseCallback
|
<optional>
|
The function that is called when reading is completed, passing in the data read. |
errorCallback |
ResponseCallback
|
<optional>
|
The function that is called when an error occurs while reading, passing in the error message if there is one. |
readAllAvailable(finishedCallbackopt, errorCallbackopt, retriesopt)
Read data from the device until a read completes with no data returned.
Client API Level 2
Parameters:
Name |
Type |
Attributes |
Description |
finishedCallback |
ResponseCallback
|
<optional>
|
The function that is called when reading is completed, passing in the data read. |
errorCallback |
ResponseCallback
|
<optional>
|
The function that is called when an error occurs while reading, passing in the error message if there is one. |
retries |
int
|
<optional>
|
The number of reads to attempt before receiving any data. Once any amount of data is received, no retries will be made. If this value is undefined, the value of the readRetries property will be used. |
readUntilStringReceived(receivedString, finishedCallback, errorCallbackopt, retriesopt)
Read data from the device until a specific string is received, or the read response is empty
Client API Level 2
Parameters:
Name |
Type |
Attributes |
Description |
receivedString |
string
|
|
The String that must be received before the finishedCallback is called. |
finishedCallback |
ResponseCallback
|
|
The function that is called when reading is completed, passing in the data read. |
errorCallback |
ResponseCallback
|
<optional>
|
The function that is called when an error occurs while reading, passing in the error message if there is one. |
retries |
int
|
<optional>
|
The number of reads to attempt before receiving any data. Once any amount of data is received, no retries will be made. If this value is undefined, the value of the readRetries property will be used. |
send(dataToSend, finishedCallbackopt, errorCallbackopt)
Send data to the device
Client API Level 2
Parameters:
Name |
Type |
Attributes |
Description |
dataToSend |
string
|
|
The data to be sent to the device |
finishedCallback |
function
|
<optional>
|
The function that is called when sending is completed. |
errorCallback |
ResponseCallback
|
<optional>
|
The function that is called when an error occurs while sending. |
sendFile(resource, finishedCallbackopt, errorCallbackopt)
Send contents of url or blob to the device without any conversion.
Client API Level 4
Parameters:
Name |
Type |
Attributes |
Description |
resource |
string
|
blob
|
|
The url from which data will be retrieved, or an already loaded blob, which will be sent to the device |
finishedCallback |
function
|
<optional>
|
The function that is called when sending is completed. |
errorCallback |
ResponseCallback
|
<optional>
|
The function that is called when an error occurs while sending. |
sendThenRead(dataToSend, finishedCallback, errorCallbackopt)
Send data to the device, then read a response back
Client API Level 2
Parameters:
Name |
Type |
Attributes |
Description |
dataToSend |
string
|
|
The data to be sent to the device |
finishedCallback |
ResponseCallback
|
|
The function that is called when reading is completed. |
errorCallback |
ResponseCallback
|
<optional>
|
The function that is called when an error occurs while sending or reading data. |
sendThenReadAllAvailable(dataToSend, finishedCallback, errorCallbackopt, retriesopt)
Send data to the device, then read all available data back
Client API Level 2
Parameters:
Name |
Type |
Attributes |
Description |
dataToSend |
string
|
|
The data to be sent to the device |
finishedCallback |
ResponseCallback
|
|
The function that is called when reading is completed. |
errorCallback |
ResponseCallback
|
<optional>
|
The function that is called when an error occurs while sending or reading data. |
retries |
int
|
<optional>
|
The number of reads to attempt before receiving any data. Once any amount of data is received, no retries will be made. If this value is undefined, the value of the readRetries property will be used. |
sendThenReadUntilStringReceived(dataToSend, receivedString, finishedCallback, errorCallbackopt, retriesopt)
Send data to the device, then read a response back until the specified string is received or all data has been read
Client API Level 2
Parameters:
Name |
Type |
Attributes |
Description |
dataToSend |
string
|
|
The data to be sent to the device |
receivedString |
string
|
|
The string that must be received before the finishedCallback is called. |
finishedCallback |
ResponseCallback
|
|
The function that is called when reading is completed. |
errorCallback |
ResponseCallback
|
<optional>
|
The function that is called when an error occurs while sending or reading data. |
retries |
int
|
<optional>
|
The number of reads to attempt before receiving any data. Once any amount of data is received, no retries will be made. If this value is undefined, the value of the readRetries property will be used. |
sendUrl(urlOfResource, finishedCallbackopt, errorCallbackopt, optionsopt)
Send contents of url to the device. If the url points to an image file (bmp, jpg, png, tif, gif) or PDF, it will automatically be converted to a printer command language.
Client API Level 2
Parameters:
Name |
Type |
Attributes |
Description |
urlOfResource |
string
|
|
The url from which data will be retrieved and be sent to the device |
finishedCallback |
function
|
<optional>
|
The function that is called when sending is completed. |
errorCallback |
ResponseCallback
|
<optional>
|
The function that is called when an error occurs while sending. |
options |
object
|
<optional>
|
Options for converting the file at the url being sent.
Properties
Name |
Type |
Attributes |
Description |
featureKey |
string
|
<optional>
|
The licensing key for the file conversion. Currently, only converting from a PDF file requires a licensing key |
toFormat |
string
|
<optional>
|
The format the file should be converted to. Options are zpl, cpcl, and kpl. Default value is zpl. |
fromFormat |
string
|
<optional>
|
The file type of the resource to convert from. If not specified, the file extension will be used to determine file type. |
|
- Deprecated:
- - This method has been deprecated as of version 3.0.0 and will be removed in the future. Please reference convertAndSendFile for a replacement method.