Skip to content

CircuitPython Dialect API

Tier: Dialect Surface

P1AM hardware model, module catalog, validation, and code generation.

pyrung.circuitpy.CircuitPyFinding dataclass

pyrung.circuitpy.CircuitPyValidationReport dataclass

pyrung.circuitpy.ChannelGroup dataclass

One homogeneous group of channels within a module.

Simple modules have a single group. Combo modules (e.g. P1-16CDR) have two groups — one input, one output.

Attributes:

Name Type Description
direction ModuleDirection

INPUT or OUTPUT (never COMBO).

count int

Number of channels in this group (positive).

tag_type TagType

IEC data type for the channels.

pyrung.circuitpy.MAX_SLOTS module-attribute

MAX_SLOTS: Final[int] = 15

Maximum number of I/O module slots on the P1AM-200 base unit.

pyrung.circuitpy.MODULE_CATALOG module-attribute

MODULE_CATALOG: Final[dict[str, ModuleSpec]] = {
    "P1-08ND-TTL": ModuleSpec(
        "P1-08ND-TTL", "8-ch discrete input (TTL)", _di(8)
    ),
    "P1-08ND3": ModuleSpec(
        "P1-08ND3", "8-ch discrete input (24V sink)", _di(8)
    ),
    "P1-08NA": ModuleSpec(
        "P1-08NA", "8-ch discrete input (120V AC)", _di(8)
    ),
    "P1-08SIM": ModuleSpec(
        "P1-08SIM", "8-ch discrete input simulator", _di(8)
    ),
    "P1-08NE3": ModuleSpec(
        "P1-08NE3",
        "8-ch discrete input (24V source)",
        _di(8),
    ),
    "P1-16ND3": ModuleSpec(
        "P1-16ND3",
        "16-ch discrete input (24V sink)",
        _di(16),
    ),
    "P1-16NE3": ModuleSpec(
        "P1-16NE3",
        "16-ch discrete input (24V source)",
        _di(16),
    ),
    "P1-04TRS": ModuleSpec(
        "P1-04TRS", "4-ch relay output", _do(4)
    ),
    "P1-08TA": ModuleSpec(
        "P1-08TA", "8-ch AC output", _do(8)
    ),
    "P1-08TRS": ModuleSpec(
        "P1-08TRS", "8-ch relay output", _do(8)
    ),
    "P1-16TR": ModuleSpec(
        "P1-16TR", "16-ch relay output", _do(16)
    ),
    "P1-08TD-TTL": ModuleSpec(
        "P1-08TD-TTL", "8-ch discrete output (TTL)", _do(8)
    ),
    "P1-08TD1": ModuleSpec(
        "P1-08TD1",
        "8-ch discrete output (24V sink)",
        _do(8),
    ),
    "P1-08TD2": ModuleSpec(
        "P1-08TD2",
        "8-ch discrete output (24V source)",
        _do(8),
    ),
    "P1-15TD1": ModuleSpec(
        "P1-15TD1",
        "15-ch discrete output (24V sink)",
        _do(15),
    ),
    "P1-15TD2": ModuleSpec(
        "P1-15TD2",
        "15-ch discrete output (24V source)",
        _do(15),
    ),
    "P1-16CDR": ModuleSpec(
        "P1-16CDR",
        "8-ch DI + 8-ch relay DO",
        _combo_discrete(8, 8),
    ),
    "P1-15CDD1": ModuleSpec(
        "P1-15CDD1",
        "8-ch DI + 7-ch DO (24V sink)",
        _combo_discrete(8, 7),
    ),
    "P1-15CDD2": ModuleSpec(
        "P1-15CDD2",
        "8-ch DI + 7-ch DO (24V source)",
        _combo_discrete(8, 7),
    ),
    "P1-04AD": ModuleSpec(
        "P1-04AD",
        "4-ch analog input (voltage/current)",
        _ai(4),
    ),
    "P1-04AD-1": ModuleSpec(
        "P1-04AD-1", "4-ch analog input (voltage)", _ai(4)
    ),
    "P1-04AD-2": ModuleSpec(
        "P1-04AD-2", "4-ch analog input (current)", _ai(4)
    ),
    "P1-04RTD": ModuleSpec(
        "P1-04RTD",
        "4-ch RTD temperature input",
        _temp_ai(4),
    ),
    "P1-04THM": ModuleSpec(
        "P1-04THM", "4-ch thermocouple input", _temp_ai(4)
    ),
    "P1-04NTC": ModuleSpec(
        "P1-04NTC",
        "4-ch NTC temperature input",
        _temp_ai(4),
    ),
    "P1-04ADL-1": ModuleSpec(
        "P1-04ADL-1",
        "4-ch analog input (voltage, low-cost)",
        _ai(4),
    ),
    "P1-04ADL-2": ModuleSpec(
        "P1-04ADL-2",
        "4-ch analog input (current, low-cost)",
        _ai(4),
    ),
    "P1-08ADL-1": ModuleSpec(
        "P1-08ADL-1",
        "8-ch analog input (voltage, low-cost)",
        _ai(8),
    ),
    "P1-08ADL-2": ModuleSpec(
        "P1-08ADL-2",
        "8-ch analog input (current, low-cost)",
        _ai(8),
    ),
    "P1-04DAL-1": ModuleSpec(
        "P1-04DAL-1",
        "4-ch analog output (voltage, low-cost)",
        _ao(4),
    ),
    "P1-04DAL-2": ModuleSpec(
        "P1-04DAL-2",
        "4-ch analog output (current, low-cost)",
        _ao(4),
    ),
    "P1-08DAL-1": ModuleSpec(
        "P1-08DAL-1",
        "8-ch analog output (voltage, low-cost)",
        _ao(8),
    ),
    "P1-08DAL-2": ModuleSpec(
        "P1-08DAL-2",
        "8-ch analog output (current, low-cost)",
        _ao(8),
    ),
    "P1-4ADL2DAL-1": ModuleSpec(
        "P1-4ADL2DAL-1",
        "4-ch AI (voltage) + 2-ch AO (voltage)",
        _combo_analog(4, 2),
    ),
    "P1-4ADL2DAL-2": ModuleSpec(
        "P1-4ADL2DAL-2",
        "4-ch AI (current) + 2-ch AO (current)",
        _combo_analog(4, 2),
    ),
}

pyrung.circuitpy.ModuleDirection

Bases: Enum

I/O direction of a P1AM module.

pyrung.circuitpy.ModuleSpec dataclass

Static specification for a single P1AM I/O module.

Attributes:

Name Type Description
part_number str

Manufacturer part number (e.g. "P1-08SIM").

description str

Human-readable summary.

groups tuple[ChannelGroup, ...]

One or two :class:ChannelGroup entries describing the module's channels.

direction property

direction: ModuleDirection

Overall direction: INPUT, OUTPUT, or COMBO.

is_combo property

is_combo: bool

True if the module has both input and output channels.

input_group property

input_group: ChannelGroup | None

The input channel group, or None if the module has no inputs.

output_group property

output_group: ChannelGroup | None

The output channel group, or None if the module has no outputs.

pyrung.circuitpy.P1AM

P1AM-200 hardware configuration.

Represents a P1AM-200 base unit with up to 15 I/O module slots. Each slot is configured with a module part number via :meth:slot, which constructs and returns the appropriate :class:~pyrung.core.memory_block.InputBlock / :class:~pyrung.core.memory_block.OutputBlock.

This class holds no runtime state — it produces Block instances whose tags reference values in SystemState.tags via the core engine.

Example::

hw = P1AM()
inputs  = hw.slot(1, "P1-08SIM")        # InputBlock
outputs = hw.slot(2, "P1-08TRS")         # OutputBlock
inp, out = hw.slot(3, "P1-16CDR")        # combo → tuple

Button = inputs[1]    # LiveInputTag("Slot1.1", BOOL)
Light  = outputs[1]   # LiveOutputTag("Slot2.1", BOOL)

configured_slots property

configured_slots: dict[int, ModuleSpec]

Mapping of slot number → :class:ModuleSpec for all configured slots.

slot

slot(
    number: int,
    module: InputModuleName,
    *,
    name: str | None = None,
) -> InputBlock
slot(
    number: int,
    module: OutputModuleName,
    *,
    name: str | None = None,
) -> OutputBlock
slot(
    number: int,
    module: ComboModuleName,
    *,
    name: str | None = None,
) -> tuple[InputBlock, OutputBlock]
slot(
    number: int, module: str, *, name: str | None = None
) -> SlotValue
slot(
    number: int, module: str, *, name: str | None = None
) -> SlotValue

Configure a module in the given slot and return its block(s).

Parameters:

Name Type Description Default
number int

Slot number (1–15 inclusive).

required
module str

Module part number (e.g. "P1-08SIM"). Must exist in :data:~pyrung.circuitpy.catalog.MODULE_CATALOG.

required
name str | None

Optional custom name prefix for tags in this slot. Defaults to "Slot{number}".

None

Returns:

Type Description
SlotValue
  • :class:~pyrung.core.memory_block.InputBlock for input-only modules.
SlotValue
  • :class:~pyrung.core.memory_block.OutputBlock for output-only modules.
SlotValue
  • tuple[InputBlock, OutputBlock] for combo modules.

Raises:

Type Description
ValueError

If number is out of range, module is not in the catalog, or the slot is already configured.

get_slot

get_slot(number: int) -> SlotValue

Retrieve the block(s) for an already-configured slot.

Raises:

Type Description
ValueError

If the slot has not been configured.

pyrung.circuitpy.RunStopConfig dataclass

Optional RUN/STOP hardware-mode mapping for generated runtime.

pyrung.circuitpy.ValidationMode module-attribute

ValidationMode = Literal['warn', 'strict']

pyrung.circuitpy.board

P1AM-200 onboard peripheral tag model.

P1AMNeoPixelNamespace dataclass

Onboard single NeoPixel RGB channels.

P1AMBoardNamespace dataclass

Onboard P1AM peripheral tags.

RunStopConfig dataclass

Optional RUN/STOP hardware-mode mapping for generated runtime.

is_board_tag

is_board_tag(tag: Tag) -> bool

Return True when the tag belongs to the onboard P1AM model.

pyrung.circuitpy.generate_circuitpy

generate_circuitpy(
    program: Program,
    hw: P1AM,
    *,
    target_scan_ms: float,
    watchdog_ms: int | None = None,
    runstop: RunStopConfig | None = None,
) -> str

pyrung.circuitpy.validate_circuitpy_program

validate_circuitpy_program(
    program: Program,
    hw: P1AM | None = None,
    mode: ValidationMode = "warn",
) -> CircuitPyValidationReport