Create Printer Settings

The Printing Java API uses commands and attributes to control the data output for a specific printer model. Command and attribute settings define everything from escape character sequences to timing delays the printer needs to function correctly. The printer commands and attributes are defined in JSON format. This section supplements the Printer Commands and Attributes User Guide by providing additional usage information specific to the Printing Java API.

The Honeywell Mobility Android Printing SDK zip file includes a file called printer_profiles.JSON in the libs subfolder. The JSON file contains a PRINTERS JSON object which contains settings for several printer models.

Receipt Printer Settings

For receipt printing, you may use PR2, PR3, PB21, PB31, PB42 and PB51 settings. You may modify the predefined settings or add a new printer object to the PRINTERS JSON object. All predefined settings include graphic and barcode settings. If you decide to create a new printer JSON object, the safest way is to clone the predefined settings of the desired printer model and add your own custom settings as seen in this example:

"PRINTERS":
{
"My_PR2":
{
"INCLUDE_01": "PR_SETTINGS", "DisplayName":"My PR2 Bt Printer",
"PrintHeadWidth": 384, "INCLUDE_02": "BARCODE_SETTINGS",
"MySlogan": "\u001bwmSave Time and Money at MYSTORE.com\u001bw!"
}
}

Note that My_PR2 defines a custom command called "MySlogan". You may use LinePrinter.sendCustomCommand("MySlogan") to send the custom command to the printer.

Label Printer Settings

The PRINTERS JSON object in the printer_profiles.JSON file contains PB22_Fingerprint and PB32_Fingerprint objects as an example for label printer settings. The next example shows some settings extracted from printer_profiles.JSON in order to explain the label printer settings.

"DEFAULTS":
{
"Initialize": "[0x00,0x00,0x00,0x00,0x1b,0x40,0x00,0x00,0x00]",
"NormalFont": "[0x1b,0x77,!,0x1b,!,0x00]",
"FormFeed": "[0x0d,0x0d,0x0d,0x0d,0x0d]",
"BtConnectRetries" : 3, "BtconnectRetryDelay" : 100,
"BtWriteDataReadyTimeout" : 10000, "BtWriteIntervalTimeout" : 10000,
"BtMaxSegWrite" : 1024, "BtLinger" : 10
},
"PRINTERS":
{
"PB22_Fingerprint":
{
"DisplayName":"PB22 Bt Label Printer",
"LABEL_01": "2in_FingerprintLabels",
"FormFeed": "[0x46,0x4F,0x52,0x4D,0x46,0x45,0x45,0x44]",
"Initialize": [], "NormalFont": [],
"NullsBeforeClose": 0, "PreCloseDelay": 1000
}
}

In the PB22_Fingerprint object, the LABEL_01 setting specified that this printer includes the label definitions defined in the 2in_FingerprintLabels object. The label definitions are defined in groups in a LABELS JSON object. For more information on label definitions, see Create Label Definitions.

The FormFeed setting specifies a command sequence that overrides the ESC/P sequence defined in the DEFAULTS object.

Both the Initialize and NormalFont settings are set to an empty array to override the ESC/P sequence defined in the DEFAULTS object. The Printing Java API sends the Initialize commands followed by the NormalFont commands to the printer after a connection is successfully established. Unless these settings are overridden, the ESC/P commands defined for Initialize and NormalFont in the DEFAULTS object are sent. This may not work well with label printers. In this example, no commands are sent after the printer connection is opened. You may customize these settings if you wish to initialize the printer with specific printer commands.

The PreCloseDelay setting specifies to wait 1000 milliseconds after the LabelPrinter.disconnect method is called to close the printer connection. The amount of delay required depends on the size of the data sent to the printer. The delay is to ensure the data is transmitted to the printer before the connection is closed.

You may also define custom command settings in the printer JSON object and use the LabelPrinter.sendCustomCommand method to send the commands to the printer.