Reading and presetting a counter
Goal: read the serial number the printer is at, and preset it at the start of a production order.
Printer setup
-
Create a counter
Serial, and use it on the label, for example with the dynamic text{COUNTER;Serial}. -
Add a register mapping:
Field Value Address 0 Mapping Counter Name SerialData type UINT32Writable On
Use UINT32 unless the counter never exceeds 65535. A UINT16 item reads
65535 for any larger value.
PLC
Read registers 0–1 to get the current value, high word first. Write both registers in one function 16 request to preset the counter.
Try it
from common import *
print(from_uint32(check(client.read_holding_registers(0, count=2)).registers))
check(client.write_registers(0, to_uint32(123456)))
print(from_uint32(check(client.read_holding_registers(0, count=2)).registers))
# 123456