Printer
Create printer
A printer is needed to print assets.
To create a SDKPrinter
, use the SDKPrinterFactory.createPrinter
. This method need a SDKPrinterListener
implementation, that is used to handle different states in print process.
Note:: This print process will replace to previous print process defined for MoreFun and Urovo SmartPOS.
printer = SDKPrinterFactory.createPrinter(object : SDKPrinterListener {
override fun onPrintStateChanged(state: SDKPrintState) {
handlePrintState(state) // define this function to handle print states
}
override fun onPrinterStateChanged(state: SDKPrinterState) {
handlePrinterState(state) // define this function to handle printer states
}
})
Printer can be aborted to cancel print process, using:
printer.abort()
Explaining the SDKPrintState states
Provide a device
Provide a device which was previously scanned. This device must be compatible with print process.
Call the method provideDevice
in SDKPrintState.DeviceRequired
state.
fun handlePrintState(state: SDKPrintState) {
when (state) {
is SDKPrintState.DeviceRequired -> {
state.provideDevice(selectedDevice) // device previously found by the scanner
}
...
}
}
Provide an asset to print
Provide an asset to be printed. Asset will be a FileWrapper
implementation or a Bitmap
.
Call the method print
in SDKPrintState.ReadyToPrint
state.
fun handlePrintState(state: SDKPrintState) {
when (state) {
is SDKPrintState.ReadyToPrint -> {
state.print(bitmap) // Bitmap or FileWrapper to be printed
}
...
}
}
Print again
When a print has been success, you can print an asset again.
Call the method printAgain
in SDKPrintState.SuccessfulPrint
state to print again. This method will trigger SDKPrintState.ReadyToPrint
state again.
Otherwise, you can finish print calling method finish
in SDKPrintState.SuccessfulPrint
. This method will trigger SDKPrintState.PrintCompleted
fun handlePrintState(state: SDKPrintState) {
when (state) {
is SDKPrintState.SuccessfulPrint -> {
state.printAgain()
// state.finish()
}
is SDKPrintState.PrintCompleted -> {
// trigger with state.finish()
}
...
}
}
Print error
During a print process, two kind of errors can occur: recoverable and not recoverable. In the recoverable, it's possible to retry the print calling the associate callback. In the not recoverable errors, print finish and it's necessary to create another print process.
Check whether state is SDKPrintState.RecoverableError
or SDKPrintState.NonRecoverableError
.
fun handlePrintState(state: SDKPrintState) {
when (state) {
is SDKPrintState.RecoverableError -> {
...
state.recover() //if you want try recover an error
}
is SDKPrintState.NonRecoverableError -> {
//print finish by an error
}
...
}
}
Both SDKPrintState.RecoverableError
and SDKPrintState.NonRecoverableError
states include an error
parameter, which is an instance of SDKPrinterError
. The possible values for SDKPrinterError
are described in the following table:
SDKPrinterError
Error | Description |
---|---|
ConnectionFailed | Indicates that there was an issue attempting to establish a connection with the device. This error can occur due to device configuration issues or network failures. |
InvalidDevice | This error is triggered when the provided device is not compatible with the SDK or is unavailable for use. |
DeviceTypeAlreadyConnected | This error occurs when attempting to connect a specific device type that is already connected. |
AssetCreationFailed | This error occurs when there is a failure while attempting to create the asset associated with the printing process. |
PrintError | An error occurred during the printing process. This error is specified by a device error type SDKPrintHardwareError , an error code code , and an additional message message . This error is triggered when there are failures related to the printing device or the printing process. |
Aborted | This error indicates that the printing operation was aborted, possibly due to user intervention or a system failure. |
InternalError | A generic error that occurs when an internal failure happens in the SDK during the printing process. |
SDKPrintHardwareError
In the case of PrintError
from SDKPrinterError
, the parameter error
is of type SDKPrintHardwareError
. This is an enum that defines the type of device error that can occur during the printing process. The possible values are:
Error | Description |
---|---|
FILE_NOT_FOUND | Occurs when a file required for printing cannot be found. |
BUSY | The device is currently in use and busy with another operation, preventing the new request from being processed. |
BITMAP_MAX_WIDTH_EXCEEDED | This error occurs when an image exceeds the maximum width allowed by the device for printing. It is recommended to adjust the image dimensions before attempting to print. |
CONNECTION_ERROR | Generated when there is a problem with the connection to the device, preventing proper communication. |
UNKNOWN_ERROR | Generated when an error occurs that cannot be identified or classified, often due to unexpected failures. |
PAPER_PROBLEM | Related to paper issues, such as lack of paper, jams, or paper running out during the printing process. |
OTHER | A generic error that does not fall into the other categories, usually caused by unforeseen failures. |
OTHER error messages by device model
Within the OTHER
error type SDKPrintHardwareError
, specific error messages may be provided depending on the device model. The following table lists the possible messages and their descriptions for MoreFun and Urovo devices:
Device | Message | Description |
---|---|---|
MoreFun | ADD_PRN_IMG_FAIL | Error adding print image. |
MoreFun | LOW_POWER | Low power. |
MoreFun | OTHER | Generic unspecified error. |
MoreFun | OUT_OF_MEMORY | Out of memory. |
MoreFun | PRINT_FAIL | Print failure. |
MoreFun | PRINTER_FAILURE | Printer failure. |
MoreFun | WRONG_PACKAGE | Wrong package. |
Urovo | ERROR_BMBLACK | Black mark detector detects a black signal. |
Urovo | ERROR_BUFOVERFLOW | The position operated in buffer mode is out of range. |
Urovo | ERROR_CUTPOSITIONERR | The paper cutter is not in place. |
Urovo | ERROR_HARDERR | Hardware error. |
Urovo | ERROR_LIFTHEAD | Print head lift. |
Urovo | ERROR_LOWTEMP | Low temperature protection. |
Urovo | ERROR_LOWVOL | Low-voltage protection. |
Urovo | ERROR_MOTORERR | Printer motor failure |
Urovo | ERROR_NOBM | No black mark found. |
Urovo | ERROR_OVERHEAT | Print head overheated. |
Urovo | ERROR_PENOFOUND | Automatic positioning did not find the alignment position. |
Urovo | ERROR_WORKON | Printer power is on. |
Explaining the SDKPrinterState states
SDKPrinterState tells the user the current state of the printer
Connecting
Printer is connecting
Connected.Idle
Printer is connected and ready to print
Connected.Printing
Printer is printing
NotConnected
Printer is not connected