Skip to main content

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
}
...
}
}

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()
}
...
}
}

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

ErrorDescription
ConnectionFailedIndicates 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.
InvalidDeviceThis error is triggered when the provided device is not compatible with the SDK or is unavailable for use.
DeviceTypeAlreadyConnectedThis error occurs when attempting to connect a specific device type that is already connected.
AssetCreationFailedThis error occurs when there is a failure while attempting to create the asset associated with the printing process.
PrintErrorAn 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.
AbortedThis error indicates that the printing operation was aborted, possibly due to user intervention or a system failure.
InternalErrorA 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:

ErrorDescription
FILE_NOT_FOUNDOccurs when a file required for printing cannot be found.
BUSYThe device is currently in use and busy with another operation, preventing the new request from being processed.
BITMAP_MAX_WIDTH_EXCEEDEDThis 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_ERRORGenerated when there is a problem with the connection to the device, preventing proper communication.
UNKNOWN_ERRORGenerated when an error occurs that cannot be identified or classified, often due to unexpected failures.
PAPER_PROBLEMRelated to paper issues, such as lack of paper, jams, or paper running out during the printing process.
OTHERA 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:

DeviceMessageDescription
MoreFunADD_PRN_IMG_FAILError adding print image.
MoreFunLOW_POWERLow power.
MoreFunOTHERGeneric unspecified error.
MoreFunOUT_OF_MEMORYOut of memory.
MoreFunPRINT_FAILPrint failure.
MoreFunPRINTER_FAILUREPrinter failure.
MoreFunWRONG_PACKAGEWrong package.
UrovoERROR_BMBLACKBlack mark detector detects a black signal.
UrovoERROR_BUFOVERFLOWThe position operated in buffer mode is out of range.
UrovoERROR_CUTPOSITIONERRThe paper cutter is not in place.
UrovoERROR_HARDERRHardware error.
UrovoERROR_LIFTHEADPrint head lift.
UrovoERROR_LOWTEMPLow temperature protection.
UrovoERROR_LOWVOLLow-voltage protection.
UrovoERROR_MOTORERRPrinter motor failure
UrovoERROR_NOBMNo black mark found.
UrovoERROR_OVERHEATPrint head overheated.
UrovoERROR_PENOFOUNDAutomatic positioning did not find the alignment position.
UrovoERROR_WORKONPrinter 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