Cookbook
Each recipe solves one common task: what to configure on the printer, what the PLC does, and a short Python script to try it from a PC before writing the PLC program.
| Recipe | Uses |
|---|---|
| Testing the connection | Device identification |
| Monitoring printer status | Signal coils |
| Starting and stopping the ink system | Action coils |
| Using a PLC bit in the printer | Writable signal coils |
| Selecting a label by name | Select label |
| Selecting a product from a table | Select from table |
| Setting a lot number | Variable |
| Reading and presetting a counter | Counter |
| Sending the line speed | Fixed speed |
| Reading production statistics | Statistic |
| Exchanging data with an extension | Internal registers, Aurora API |
All recipes use the example mapping list, for a
printer with the ID NoLabel.
Trying it from a PC
The scripts use pymodbus 3.x:
pip install pymodbus
Each script starts with this common part. Replace the address with your printer's.
Common part
from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient("192.168.1.50", port=502)
client.connect()
def check(response):
if response.isError():
raise RuntimeError(f"Modbus exception {response.exception_code}")
return response
def to_string(text, length):
"""Encode text as a STRING item of length registers."""
data = text.encode("utf-8")
if len(data) > 2 * length:
raise ValueError("text too long")
data = data.ljust(2 * length, b"\0")
return [data[i] << 8 | data[i + 1] for i in range(0, len(data), 2)]
def from_string(registers):
"""Decode the registers of a STRING item."""
data = b"".join(r.to_bytes(2, "big") for r in registers)
return data.rstrip(b"\0").decode("utf-8")
def to_uint32(value):
return [value >> 16, value & 0xFFFF]
def from_uint32(registers):
return registers[0] << 16 | registers[1]
Save it as common.py, and start each recipe's script with
from common import *.