Scan and Print Automatically

Article ID: 87284591

Issue / Question

How do I scan a barcode and automatically print a label containing this data?

Applicable To

ZPL, ZebraDesigner, 123Scan

Resolution / Answer

There are two methods to scan a barcode with a barcode reader and automatically print it on the printer connected to the reader.

  • The printer can be connected by Bluetooth (BTLE is not supported) or over a network connection.
  • If you intend to connect the scanner to the USB HOST port of the printer, follow the next article:

Standalone Printing - Print Station Used With USB Host Port

To connect the barcode reader to the printer via Bluetooth, open 123Scan, click Barcodes > Bluetooth Barcodes > Serial port profile (master) pairing bar code.



In the Pairing value field, enter the printer Bluetooth MAC address, and click on the generate bar code button.


The pairing of the devices will be accomplished by scanning the barcode printed by the printer.

Method 1

This method is used to store a label template on the printer memory and recall it each time the barcode reader reads the barcode you want to print. Since the barcode must be configured to send a prefix and a suffix at every read, this method might be limited by the memory size of the barcode reader. Hence, do check your free or available memory before you begin. 

The first part will focus on configuring the printer and the first step is to use ZebraDesigner to create the template that contains all the fixed and variable fields you want on the final label.

  1. With the printer installed and connected to the computer, open a new label in ZebraDesigner and add all the fields you need, including the variable ones. 

    In the following example, there is a fixed text field (Fixed text) and a Code 128 barcode type variable field. 

 


You can check if the file is on the printer memory by sending the following commands to the printer: 
^XA
^HWE:*.*
^XZ
One of the files should be EXAMPLE.ZPL
 
You can find more information about this procedure in this article: Zebra Setup Utilities -- Sending Printer Commands and Receiving Data.

Open the example.prn file saved before with a text editor, and the following window pops up:
 

View the Using ZPL Stored Formats article (refer to Example 2) if you need further information about how to store and recall a format from the printer memory.

Now that the printer is configured correctly, we can work on the barcode reader.

Send the required ZPL code to the printer that will recall the template file and fill the variable field. This can be achieved by creating an Advanced Data Formatting (ADF) rule using 123Scan which will send the following prefix:
^XA^XFE:EXAMPLE.ZPL^FS^FN11^FD
and the following suffix:
^FS^PQ1^XZ<CR><LF>

In details, the prefix contains the command to open the label ^XA, then it recalls the EXAMPLE.ZPL file using the ^XF command and open the ^FN11 field that will be filled with the data read by the reader. The command contained in the suffix closes the ^FN11 tag with the ^FS command, adds the print quantity ^PQ1, and close the label with the ^XZ tag. The <CR> and <LF> refer to Carriage Return and Line Feed respectively. This needs to be added at the end so that the printer confirms the action to print. Carriage Return is listed in 123Scan as <CTRL M/ENTER> and Line Feed is listed as <CTRL J/LINEFEED>.

This step can be achieved using the 123Scan Utility as shown below:

 
You can download from here the example file used in this article.

Refer to the Creating an Advanced Data Formatting (ADF) Rule Using 123Scan article for more details.
 

Method 2

This method is used to create a barcode containing just a carriage return and is used to confirm the quantity. This operation can be done using ZebraDesigner 3

Procedure: 

Step 1:
Scan the barcode you want to print.
Step 2: Scan the carriage return barcode and the printer will print the label.
 
With Step 1, you are sending the data you want to print to the printer, while Step 2 works like an enter pressed on the keyboard and it's needed to confirm the action to print.
 
Below are two ZebraDesigner samples that contain the carriage return:

Helpful Information:
 
  • Save the file with a filename no longer than 8 characters and ensure it does not contain spaces in between. (example.nlbl in this case).
  • Click on File and select Store.
  • Select the Print to file checkbox, and save the example.prn file at a known location to be used later. 
  • Repeat the previous step, but deselect the Print to file checkbox and choose Internal Flash under the Printer memory location so the file will be stored on the printer memory. 
    • ^DFE:EXAMPLE.ZPL > This command instructs the printer to store the file instead of printing it.
    • ^FDFixed Text:^FS This is the fixed text field).
    • ^BY4,3,238^FT501,127^BCI,,Y,N,N,A > These are the features of the variable barcode field. It contains the barcode type, its position, size, etc.
    • ^FN11 > This is the empty variable field on the template which will be filled with the data read by the barcode reader.

+ Applicable Products

  • ZebraDesigner Pro
  • ZebraDesigner Pro