Selecting a product from a table
Goal: the PLC sends an article number, and the printer looks up which label, and how many copies, to print for it. The product data is maintained on the printer, and the PLC only needs to know the article numbers.
Printer setup
Create a table on the printer, for example Products:
| Article | Label | Copies |
|---|---|---|
| A100 | Carton | 1 |
| A200 | Pallet | 2 |
Add a register mapping:
| Field | Value |
|---|---|
| Address | 36 |
| Mapping | Select from table |
| Data type | STRING |
| Length | 8 |
| Printer | NoLabel |
| Table name | Products |
| Key column | Article |
| Label column | Label |
| Copies column | Copies |
| Queue label | On |
PLC
Write the article number to registers 36–43 with function 16, once per job. With Queue label on, each write adds a job to the printer's queue.
Exception 04 means the article is not in the table, or the table, label or printer is missing. The printer's log says which.
Try it
from common import *
check(client.write_registers(36, to_string("A200", 8))) # 2 x Pallet
response = client.write_registers(36, to_string("X999", 8))
print(response.exception_code) # 4, not in the table