Skip to main content

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.

RecipeUses
Testing the connectionDevice identification
Monitoring printer statusSignal coils
Starting and stopping the ink systemAction coils
Using a PLC bit in the printerWritable signal coils
Selecting a label by nameSelect label
Selecting a product from a tableSelect from table
Setting a lot numberVariable
Reading and presetting a counterCounter
Sending the line speedFixed speed
Reading production statisticsStatistic
Exchanging data with an extensionInternal 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 *.