Print the URL_QRLabel defined in the Example Printer Commands and Attributes for Label Printing to a PB32 printer. It uses the PB32_Fingerprint printer settings which include the 3in_FingerprintLabels label group. The following code snippet shows the URL_QRLabel definition in this group:
"URL_QRLabel":
{
"StoreFormat": "INPUT ON\r\nLAYOUT INPUT \"URLQRLABEL.LAY\"\r\nDIR 4:AN 7:PP 200, 50:FT \"Swiss 721 Bold Condensed BT\",16:PT VAR1$:PP 300, 50:FT \"Letter Gothic 12 Pitch BT\",14:PT VAR2$:PP 105,490:BARSET \"QRCODE\",1,1,13,2,2:PB VAR3$\r\nLAYOUT END\r\nINPUT OFF\r\n",
"InvokeFormat": "INPUT OFF\r\nFORMAT INPUT \"#\",\"@\",\"|\"\r\nINPUT ON\r\nLAYOUT RUN \"URLQRLABEL.LAY\"\r\n#qTextLine1$|qTextLine2$|qURL$|@\r\nPF\r\nINPUT OFF\r\n",
"VarPrefix": "q",
"VarPostfix": "$"
}
This label definition object contains both the StoreFormat and the InvokeFormat members. The StoreFormat specifies the commands to store a label layout format on the printer. The InvokeFormat specifies the commands to invoke a label layout format stored on the printer. The StoreFormat commands will be sent to the printer followed by the InvokeFormat commands.
See the Fingerprint Command Reference Manual (P/N 937-005-00x) for complete command information.
Fingerprint or Direct Protocol Command | Description |
---|---|
INPUT ON | Enables the Direct Protocol in order to invoke the LAYOUT INPUT and LAYOUT END commands. |
LAYOUT INPUT "URLQRLABEL.LAY" | Starts the recording of a layout description which will be saved as "URLQRLABEL.LAY" in the printer memory. |
DIR 4 | Specifies a direction to print the label. |
AN 7 | Specifies the anchor point. |
PP 200, 50 | Sets the insertion point to (200, 50). |
FT "Swiss 721 Bold Condensed BT", 16 | Uses "Swiss 721 Bold Condensed BT" font and a height of 16 pts. |
PT VAR1$ | Provides inout data for a text field. VAR1$ specifies a variable data field that will be substituted with the data provided via the LAYOUT RUN command. |
PP 300,50 | Sets the insertion point to (300,50). |
FT "Letter Gothic 12 Pitch BT", 14 | Uses "Letter Gothic 12 Pitch BT" font and a height of 14 pts. |
PT VAR2$ | Provides input data for a text field. VAR2$ specifies a variable data field that will be substituted with the data provided by the LAYOUT RUN command. |
PP 105, 490 | Sets the insertion point to (105, 490). |
BARSET "QRCODE",1,1,13,2,2 | Specifies the QR Code parameters. |
PB VAR3$ | Provides input data for a bar code. VAR3$ specifies a variable data field that will be substituted with the data provided by the LAYOUT RUN command. |
LAYOUT END | Stops the recording of a layout description and saves the layout. |
INPUT OFF | Disables the Direct Protocol. |
Fingerprint or Direct Protocol Command | Description |
---|---|
INPUT OFF | Disables the Direct Protocol in order to invoke the FORMAT INPUT command. |
FORMAT INPUT "#", "@", "|" | Specifies separators for the LAYOUT RUN command. In this case, "#" is the start of data separator, "@" is the end of data separator, and "|" is the data field separator. |
INPUT ON | Enables the Direct Protocol in order to invoke the LAYOUT RUN command. |
LAYOUT RUN "URLQRLABEL.LAY" | Provides variable input data to a predefined layout, "URLQRLABEL.LAY" in this example. |
#qTextLine1$|#qTextLine2$|#qURL$|@ | Specifies three variables: qTextLine1$, qTextLine2$, and qURL$ which will be replaced by the "TextLIne1", "TextLine2", and "URL" key values specified in the aDictionary parameter passed to the LabelPrinter.writeLabel method. |
PF | Prints the label. |
INPUT OFF | Disables the Direct Protocol. |
The following code snippet prints the label:
import android.os.AsyncTask;
import android.app.Activity; import com.honeywell.mobility.print.*;
public class PrintActivity extends Activity
{
private void createPrintTask()
{
PrintTask task = new PrintTask();
// Executes PrintTask with the specified parameters which
// will be passed to the PrintTask.doInBackground method.
// In this case, the doInBackground method does not expect
// any parameter.
task.execute();
}
class PrintTask extends AsyncTask<Void, Integer, Void>
{
@Override
protected Void doInBackground(Void... args)
{
doPrint();
return null;
}
private void doPrint()
{
LabelPrinter lp = null;
LabelPrinter.ExtraSettings exSettings =
new LabelPrinter.ExtraSettings();
exSettings.setContext(PrintActivity.this);
try
{
// Assumes the printer_profiles.JSON contains the
// contents of the LINEPRINTERCONTROL JSON object
// in the Example Printer Commands and Attributes
// for Label Printing section. It also assumes the
// file has been copied to the external storage.
File profiles = new File (getExternalFilesDir(null),
"printer_profiles.JSON");
lp = new LabelPrinter(profiles.getAbsolutePath(),
"PB32_Fingerprint",
"bt://00:02:5B:CF:B3:20",
exSettings);
lp.connect(); // Connects to the printer
// Sets up the variable dictionary.
LabelPrinter.VarDictionary varDataDict =
new LabelPrinter.VarDictionary();
varDataDict.put("TextLine1", "Scan for more info");
varDataDict.put("TextLine2", "www.honeywellaidc.com");
varDataDict.put("URL", "http://www.honeywellaidc.com");
// Prints the URL_QRLabel as defined in the
// printer_profiles.JSON file.
lp.writeLabel("URL_QRLabel", varDataDict);
// You may print more labels.
}
catch (LabelPrinterException ex)
{
// Handles LabelPrinter exceptions
}
catch (Exception ex)
{
// Handles other exceptions
}
finally
{
if (lp != null)
{
try
{
// Note: The PB32_Fingerprint printer settings
// specify a PreCloseDelay setting to ensure the
// label data stream is transmitted to the
// printer before the connection is closed.
lp.disconnect(); // Disconnects from the printer
lp.close(); // Releases resources
}
catch (Exception ex) {}
}
}
}
}
}
When the above lp.writeLabel method is executed, the following printer commands are sent to the printer after variable replacements:
INPUT ON
LAYOUT INPUT "URLQRLABEL.LAY"
DIR 4
AN 7
PP 200, 50
FT "Swiss 721 Bold Condensed BT",16
PT VAR1$
PP 300,50
FT "Letter Gothic 12 Pitch BT",14
PT VAR2$
PP 105,490
BARSET "QRCODE",1,1,13,2,2
PB VAR3$
LAYOUT END
INPUT OFF
INPUT OFF
FORMAT INPUT "#","@","|"
INPUT ON
LAYOUT RUN "URLQRLABEL.LAY"
#Scan for more info|www.honeywellaidc.com|http://www.honeywellaidc.com|@
PF
INPUT OFF