Skip to content

Addressing API

Tier: Stable Core

Address model and canonical normalized address helpers.

pyclickplc.AddressRecord dataclass

Immutable record for a single PLC address.

Simpler than ClickNick's AddressRow -- omits all UI validation state. For user-facing creation from display addresses, prefer make_address_record(...).

addr_key property

addr_key: int

Get the AddrKey for this record.

display_address property

display_address: str

Get the display string for this address.

data_type_display property

data_type_display: str

Get human-readable data type name.

is_default_retentive property

is_default_retentive: bool

Return True if retentive matches the default for this memory_type.

is_default_initial_value property

is_default_initial_value: bool

Return True if the initial value is the default for its data type.

has_content property

has_content: bool

True if record has any user-defined content worth saving.

can_edit_initial_value property

can_edit_initial_value: bool

True if initial value can be edited for this memory type.

can_edit_retentive property

can_edit_retentive: bool

True if retentive setting can be edited for this memory type.

from_address classmethod

from_address(
    address: str,
    *,
    nickname: str = "",
    comment: str = "",
    initial_value: str = "",
    retentive: bool | None = None,
    used: bool | None = None,
) -> AddressRecord

Build an AddressRecord from a display address string.

pyclickplc.parse_address

parse_address(address_str: str) -> tuple[str, int]

Parse a display address string to (memory_type, mdb_address).

Strict: raises ValueError on invalid input. For XD/YD, returns MDB address: "XD1" -> ("XD", 2), "XD0u" -> ("XD", 1).

Parameters:

Name Type Description Default
address_str str

Address string like "X001", "XD0", "XD0u", "XD8"

required

Returns:

Type Description
tuple[str, int]

Tuple of (memory_type, mdb_address)

Raises:

Type Description
ValueError

If the address string is invalid

pyclickplc.normalize_address

normalize_address(address: str) -> str | None

Normalize an address string to its canonical display form.

E.g., "x1" -> "X001", "xd0u" -> "XD0u".

Returns:

Type Description
str | None

The normalized display address, or None if address is invalid.

pyclickplc.format_address_display

format_address_display(
    memory_type: str, mdb_address: int
) -> str

Format a memory type and MDB address as a display string.

X/Y are 3-digit zero-padded. XD/YD use special encoding. Others are unpadded.