Selecting a label by name
Goal: the PLC decides which label the printer prints, for example from the recipe of the current production order.
Printer setup
Add a register mapping:
| Field | Value |
|---|---|
| Address | 20 |
| Mapping | Select label |
| Data type | STRING |
| Length | 16, room for names up to 32 bytes |
| Printer | NoLabel |
Optional settings, see Print job fields:
- Prefix and Suffix let the PLC send a short code instead of the full
name. With prefix
Order-, writing1234selects the labelOrder-1234. - Limit number of prints prints a fixed number of copies of each job.
- Queue label adds the job to the queue, so the PLC can send the next job while the current one is printing.
- Use a snapshot of the label freezes counters and the date and time when the job is selected, so the print matches what the PLC sent at that moment.
If the label names are numbers, a UINT16 or UINT32 item works too. The
PLC then writes the number, and the printer uses its decimal text.
PLC
When a new label is needed, write its name to registers 20–35 with function 16, once. Every write selects a job, even if the name is the same, so do not put the item in a cyclic write.
Check the response: exception 04 means the label does not exist on the
printer, or the printer is not available. To confirm the job is selected, read
the signal printer.NoLabel.label_selected, coil 2 in the example.
Try it
from common import *
check(client.write_registers(20, to_string("Carton", 16)))
print(check(client.read_coils(2, count=1)).bits[0]) # label selected
response = client.write_registers(20, to_string("NoSuchLabel", 16))
print(response.exception_code) # 4