Skip to main content

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​

  1. Create a counter Serial, and use it on the label, for example with the dynamic text {COUNTER;Serial}.

  2. Add a register mapping:

    FieldValue
    Address0
    MappingCounter
    NameSerial
    Data typeUINT32
    WritableOn

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