LabelServer4j Operation
This page describes the end-to-end operational workflow of LabelServer4j — from an operator assigning a process order in Commander4j through to a label being printed on the production line.
Step 1 — Assign a Process Order to a Labeller
In the Commander4j desktop application, an operator opens the Pallet Labelling screen (or uses the Process Order Assign to Labeller function) and assigns a Process Order to a configured production line.
Commander4j validates:
- That the operator's workstation is permitted to assign to that line (if workstation validation is enabled)
- That the order's Required Resource matches the line (if resource validation is enabled)
Step 2 — CSV Export
Commander4j writes a CSV data file to the labeller's input directory. The filename follows the format LINE_NAME_PRINTER_NAME.CSV. The file contains a header row and a single data row with all the fields needed to produce the label. See LabelServer4j Dataset CSV for the full list of fields.
Step 3 — File Detection
LabelServer4j polls the input directory every 250 ms. When the CSV file appears:
- The file is immediately renamed to
.into prevent it being picked up twice. - The file is parsed using the column headers to map each value to a named variable (e.g.
$data_BATCH_SUFFIX,$data_SSCC).
Step 4 — Script Execution
LabelServer4j loads the command script configured for this labeller (a plain text .txt file from the labeller_cmd/ directory). The script is executed line by line. Each line consists of a label (for flow control) and a command with its arguments.
During execution, data variables from the CSV are substituted into the commands. Functions such as SUBSTRING(), PADLEFT(), EXTRACT_DATE(), and CODE128SWITCHER() can be used to format values before transmission.
Control Flow
Scripts support conditional branching and looping:
GOTO label— unconditional jumpIF (condition) GOTO label— conditional jump- Labels can be used to structure sections for different label types within a single script
This allows one script to handle multiple label variants based on a field value in the CSV (for example, switching between a production layout and a rework layout based on $data_MODULE_ID).
Database Queries
The DB_QUERY command executes a parameterised SQL statement against the Commander4j database and stores the result in a variable. This enriches label data beyond what Commander4j included in the CSV.
Sending to the Printer
The SEND command transmits a line of text to the printer over the TCP/IP connection. Control characters such as <CR>, <LF>, <STX>, and <ETX> are encoded in the script and expanded at send time.
WAIT_FOR_REPLY blocks execution until a response is received. CHECK_SUCCESS compares the response against configured success and failure patterns.
File Operations
For Logopak and similar printers that use stored label templates, LabelServer4j can upload (SEND_FILE_INTELHEX) and download (RECEIVE_FILE_INTELHEX) binary files to and from the printer using Intel Hex encoding. It can also list remote files, delete them, and back them up locally.
Step 5 — Completion
On successful completion of the script, the input CSV file is deleted and a record written to the log. The labeller thread immediately returns to polling for the next file.
If the script fails (invalid response, connection error, or script error), the CSV file is moved to an error directory and an error message is logged. If email notifications are configured, an alert is sent.
Logging
All activity is written to logs/c4jLabelServer.log with rolling rotation (10 MB per file, 14 days retention). The log records every command sent, every response received, and all file operations. This makes diagnosing communication issues straightforward.
Running Multiple Labellers
Each configured labeller runs in its own background thread. All labellers poll and execute simultaneously. A site with six printers runs six independent threads, each managing its own TCP connection and input directory.
See also: Overview LabelServer4j, LabelServer4j Configuration, LabelServer4j Dataset CSV, LabelServer4j Folder Structure, Production Lines & Labellers