Codec API¶
Tier: Stable Core
Encode and decode Click clipboard binary and program files.
laddercodec.encode ¶
Encode ladder rungs as the binary that CLICK puts on the clipboard.
Definitions¶
Rung
One logical unit of ladder logic. A rung has 1..32 rows, each with 31 condition columns (A..AE) and 1 output column (AF). A rung may also have one comment.
Row
A horizontal slice of the rung grid. Row 0 is the topmost visible row. The grid starts at absolute offset 0x0A60 with a stride of 0x800 per row (32 columns x 64 bytes per cell).
Cell
The bytes for one (row, column) position in the grid. A wire cell is 64 (0x40) bytes, and an instruction cell is longer. A cell holds wire flags and bytes that describe the grid's structure. An instruction cell also holds its index among the rung's instructions, at +0x0D. The encoder numbers the condition instructions row by row, then the AF instructions. When the AF cell on the last row of the last rung is a 0x40-byte cell, blank or a NOP, the encoder writes the number of that rung's instructions at its +0x3C. A NOP is not counted. CLICK often writes another value there.
Wire topology
The arrangement of horizontal wires ("-"), vertical pass-throughs ("|"), and junction-down points ("T") across the condition grid. Each cell stores it in three flag bytes: +0x19 (segment), +0x1D (right) and +0x21 (down). A condition cell sets these flags as a "-" cell does.
Condition
An instruction in a condition column (A..AE): a Contact
(NO/NC/edge) or a CompareContact (GT/GE/LT/LE/EQ/NE). A
condition cell has a variable length. It is a 0x25-byte header
(wire flags, column, row, instruction index) followed by the
instruction blob (class name, type marker, operand, func_code). The
caller passes each condition as an object in the condition_rows grid.
NOP
The simplest AF-column instruction. A rung holds at most one. The encoder writes it as flags: +0x1D = 1 in column 31 of the NOP's row, and +0x15 = 1 in column 0 of that row if it is not the first row and the rung holds no other instruction. A NOP gets no instruction index and is not counted.
Page
A 0x1000 (4096) byte allocation unit. Buffer size is: pad_to_page(0x0A60 + logical_rows * 0x800 + payload_len).
Program header
A single 0x40-byte structure at 0x0254. It holds the row-count word (+0x00/+0x01 = (rows+1)*0x20) and other GUI state. There is only one. The range 0x0294–0x0A5F after it is the payload region, not a table of 32 headers.
Supported checklist¶
Verified in Click (encode → paste → copy back → decode round-trip):
[x] Empty rung, 1..32 rows
[x] Wire topology, 1..32 rows (-, |, T in any valid position)
[x] NOP on any row (with col0 +0x15 enable for non-first rows)
[x] Plain comment, 1-row (empty, wire, NOP, max 1400 bytes)
[x] Plain comment, 2-row (empty, NOP, wire incl. col-A, max 1324)
[x] Plain comment, 3-row (empty, NOP, wire, mixed, max 1400)
[x] Plain comment, 4..32 rows (wire combos, scaling)
[x] Multi-line comment (\n → \par)
[x] Styled comments (bold/italic/underline via markdown → RTF groups)
[x] Contacts (NO, NC, edge, immediate — via Contact objects in condition_rows)
[x] Coils (out, latch, reset, immediate, range — via Coil objects in af_tokens)
[x] Comparison contacts (GT, GE, LT, LE, EQ, NE — via CompareContact objects)
[x] Timers (on_delay, off_delay, retentive — via Timer objects in af_tokens)
[x] These AF instructions: counters, the Copy family, Search, Math,
Shift, drums, For/Next, Call, Return, End, Send/Receive and the
Out variants (tests/fixtures/coverage/golden/)
[x] Email, Home, Position and Velocity, as raw(...) only
Pipeline steps¶
1. Header — load from synthesize_empty_multirow (includes row_word)
2. Grid — build the 32 cells of each row, with their wire flags
and any NOP, and join them into the grid bytes
3. Assemble — header[:0x0A60] + grid_bytes
4. Comment — assemble RTF, insert at 0x0298, push grid forward
5. Pad — to next 0x1000 page boundary
Each cell is the bytes that ClickCell.to_bytes() returns. A wire
cell is 0x40 bytes. An instruction cell, such as a contact, coil or
timer, is longer. The encoder joins the cells end to end, so it does
not assume that any cell sits at a fixed offset in the grid.
encode_rung ¶
encode_rung(
logical_rows: int,
condition_rows: Sequence[Sequence[ConditionToken]],
af_tokens: Sequence[InstructionToken],
comment: str | None = None,
*,
show_nicknames: bool = False,
) -> bytes
Encode one ladder rung as CLICK clipboard binary.
Parameters¶
logical_rows:
Number of rung rows (1..32).
condition_rows:
The token grid, one list per row. Each row has 31 condition-column
entries. Each entry is "" blank, "-" horizontal wire,
"|" vertical pass-through, "T" junction-down,
a Condition such as a Contact, or a Tee around one.
af_tokens:
One per row. "NOP" encodes the NOP instruction on the AF
column, and "" leaves it blank. An Instruction, such as a
Coil, encodes that instruction.
comment:
Optional comment text, at most 1400 bytes after RTF encoding. The
encoder inserts it as RTF at 0x0298 and moves the cell grid forward
by the length of the RTF.
Inline styles (markdown syntax):
``**text**`` → bold
``__text__`` → underline
``*text*`` → italic (asterisk)
``_text_`` → italic (underscore)
A backslash before ``*``, ``_`` or ``\`` makes that character text.
Line breaks: ``\n`` becomes an RTF paragraph break (``\par``).
``\r\n`` and a lone ``\r`` are normalized to ``\n`` first.
Returns¶
bytes The encoded rung, padded to a whole number of 0x1000-byte pages.
encode ¶
Encode one or more rungs to clipboard binary.
Parameters¶
rungs:
A single Rung object (single-rung encode) or a sequence of
Rung objects (multi-rung encode).
show_nicknames:
When True, sets the nickname display flag on math instructions
so Click shows project-level tag names instead of raw addresses.
The nicknames must already be loaded in the Click project before
pasting.
Returns¶
bytes Encoded binary payload.
Raises¶
EncodeError
If a rung can't be written: a grid of the wrong size, a wire token where CLICK
can't draw one, more than one NOP, an undecoded marker, or a comment too long.
FieldError
If an instruction holds a value CLICK's dialog refuses.
laddercodec.decode ¶
The decoder that reads a CLICK clipboard binary into Rung objects.
Each Rung holds the values that encode_rung() and encode_rungs() take as
input.
Public API¶
decode(data) -> list[Rung]
decode_rung(data) -> Rung
decode_rungs(data) -> list[Rung]
inspect_cells(data, cells) -> list[CellDump]
decode_rung returns the values that encode_rung was given, as tuples:
decode_rung(encode_rung(lr, cr, af, cmt))
.logical_rows == lr
.conditions == tuple(map(tuple, cr))
.instructions == tuple(af)
.comment == cmt
Instruction cells¶
A cell that holds a contact or a coil is a horizontal wire cell, with the flags
(1,1,0), that also holds the instruction's data. A contact cell may also set its down
flag (+0x21) for a wire down. The decoder returns that cell as a Tee around the
contact. The instruction data starts at offset +0x25 in the cell. It holds the
class name in UTF-16LE, a type marker, the operand and the function code. A cell with only wires is exactly 0x40 bytes long.
A cell with an instruction is longer.
For each instruction type it knows, the decoder builds an object from instructions/,
such as a Contact, Coil or Timer. A condition cell that it does not
recognise becomes an UnknownCondition. An AF cell that it does not recognise becomes
a RawInstruction when the decoder can find the instruction's blob, and an
UnknownInstruction otherwise. Each of these keeps the instruction's raw bytes.
Rung
dataclass
¶
One rung of ladder logic. The decoders return it, and encode() accepts it.
A Rung holds what the rung means, not how CLICK stored it. It does not
keep CLICK's row and segment flags or any trace of how the rung was edited.
encode() writes the flags in a standard form, so its bytes can differ
from the bytes that CLICK wrote.
A Rung is frozen. You may pass lists for conditions and instructions.
The rung stores them as tuples, so a rung built from lists equals the same rung built
from tuples, and it can be hashed. To change a rung, build a new one or call
laddercodec.replace(rung, instructions=...). A text where a row of
conditions or the instructions list belongs raises
:class:~laddercodec.EncodeError.
Attributes¶
conditions:
One tuple of tokens per row. Each row has 31 entries, one per
condition column. A cell with only wires is a string ("" blank,
"-" horizontal, "|" vertical, "T" junction-down). A
contact is an object such as Contact. A cell that the decoder
does not recognise is an UnknownCondition. A cell that holds a
contact and a wire down from its left edge is a Tee around the
contact, such as Tee(Contact("X001")). A Tee is to a
contact what "T" is to "-".
instructions:
One AF token per row. A row with no instruction holds "NOP"
or "". An instruction is an object such as Coil. A cell
that the decoder does not recognise is a RawInstruction or an
UnknownInstruction.
comment:
The rung comment as Markdown text, or None. The CSV form
uses this text.
comment_rtf:
The comment's RTF bytes as the binary stored them, or None.
encode() does not read them. It writes the comment from
comment. Two rungs that differ only in comment_rtf are equal.
logical_rows
property
¶
The number of rows in the rung, len(conditions). encode() takes 1 to 32.
CellDump
dataclass
¶
The raw bytes of one cell and what they decode to, for reverse engineering and debugging.
Attributes¶
rung: Rung index (0-based).
row: Visual row within the rung (0-based).
col: Column letter ("A".."AE" or "AF").
offset: Absolute byte offset in the buffer.
size: Cell size in bytes (0x40 for wire-only, larger for instructions).
raw: Raw cell bytes.
flags: Flags (segment, right, down) read from +0x19/+0x1D/+0x21.
token: Decoded wire/instruction token, or None if not decoded.
decode ¶
Decode a clipboard binary into its rungs, one or several.
Parameters¶
data:
Raw clipboard bytes (page-aligned, starts with CLICK magic).
Returns¶
list[Rung]
One Rung per rung of the buffer, in order. A single-rung buffer gives a
list of one. A rung that can't be decoded comes back as an undecoded marker
rung (:func:laddercodec.undecoded.marker_rung), with an
UndecodedRungWarning. If the decoder can't walk the grid past a row, the
marker stands for that rung and every rung after it. If that happens in rung 0,
before any preamble row, the decoder can't tell one rung from several. It then
returns a list that holds only the marker rung.
Raises¶
DecodeError
If the buffer does not start with the CLICK magic or is too short.
decode_rung ¶
Decode a single-rung clipboard binary.
Parameters¶
data:
Raw clipboard bytes (page-aligned, starts with CLICK magic).
Returns¶
Rung
The decoded rung. Its fields hold the values that encode_rung() takes.
Raises¶
DecodeError
If the buffer is invalid or contains multiple rungs. A rung that can't be decoded
does not raise. It comes back as an undecoded marker rung, as from :func:decode.
decode_rungs ¶
Decode a multi-rung clipboard binary.
Parameters¶
data:
Raw clipboard bytes (page-aligned, starts with CLICK magic).
Returns¶
list[Rung] One entry per rung, in order.
Raises¶
DecodeError
If the buffer is invalid or contains only a single rung. A rung that can't be
decoded does not raise. It comes back as an undecoded marker rung, as from
:func:decode. If the walk stops in rung 0, before any preamble row, the
decoder can't tell one rung from several. The list then holds only that rung's
marker.
inspect_cells ¶
Dump raw bytes for specific cells in a clipboard binary.
Parameters¶
data:
Raw clipboard bytes.
cells:
List of (rung_index, visual_row, column_letter) tuples.
Column is "A".."AE" for conditions or "AF" for output.
Returns¶
list[CellDump] One entry per requested cell, in the same order as cells.
Example::
dumps = inspect_cells(raw, [(0, 1, "A"), (0, 1, "B")])
for d in dumps:
print(d)
laddercodec.decode_program ¶
Decode a CLICK program file (Scr*.tmp) into Rung objects.
Reads Click Programming Software's internal temp files and produces
the same Rung objects as the clipboard decoder.
Public API¶
decode_program(data) -> Program
An SCR file holds the whole program as CLICK stores it on disk. It is about 17 times smaller than the clipboard form. It uses the same instruction tag IDs and operand values as the clipboard. Only the framing differs.
decode_program ¶
Decode an SC-SCR temp file into a Program.
Parameters¶
data:
Raw bytes of a Scr*.tmp file (starts with SC-SCR magic).
Returns¶
Program
Program with name, prog_idx, and rungs parsed from the file. If a rung can't
be decoded, an undecoded marker rung takes its place, and the decoder warns
with UndecodedRungWarning.
A framing error is a truncated record, or rows or an instruction section that
the decoder can't read. The rungs before the error decode, and one marker takes
the place of that rung and every rung after it. If the error is in a record's
prefix, or the file does not end after the last record, the record before may
have ended in the wrong place. The marker then starts at that record.
A marker acts as ``end()`` in the main program and as ``return()`` in a
subroutine.
Raises¶
DecodeError If the file header cannot be parsed.
laddercodec.Rung
dataclass
¶
One rung of ladder logic. The decoders return it, and encode() accepts it.
A Rung holds what the rung means, not how CLICK stored it. It does not
keep CLICK's row and segment flags or any trace of how the rung was edited.
encode() writes the flags in a standard form, so its bytes can differ
from the bytes that CLICK wrote.
A Rung is frozen. You may pass lists for conditions and instructions.
The rung stores them as tuples, so a rung built from lists equals the same rung built
from tuples, and it can be hashed. To change a rung, build a new one or call
laddercodec.replace(rung, instructions=...). A text where a row of
conditions or the instructions list belongs raises
:class:~laddercodec.EncodeError.
Attributes¶
conditions:
One tuple of tokens per row. Each row has 31 entries, one per
condition column. A cell with only wires is a string ("" blank,
"-" horizontal, "|" vertical, "T" junction-down). A
contact is an object such as Contact. A cell that the decoder
does not recognise is an UnknownCondition. A cell that holds a
contact and a wire down from its left edge is a Tee around the
contact, such as Tee(Contact("X001")). A Tee is to a
contact what "T" is to "-".
instructions:
One AF token per row. A row with no instruction holds "NOP"
or "". An instruction is an object such as Coil. A cell
that the decoder does not recognise is a RawInstruction or an
UnknownInstruction.
comment:
The rung comment as Markdown text, or None. The CSV form
uses this text.
comment_rtf:
The comment's RTF bytes as the binary stored them, or None.
encode() does not read them. It writes the comment from
comment. Two rungs that differ only in comment_rtf are equal.
logical_rows
property
¶
The number of rows in the rung, len(conditions). encode() takes 1 to 32.
laddercodec.Program
dataclass
¶
A single PLC program (main or subroutine) with its rungs.
prog_idx is CLICK's program index: 1 for the main program, 2 and up for
subroutines.
undecoded
property
¶
The undecoded markers in :attr:rungs, in rung order.
The list is empty if every rung decoded.
laddercodec.Project
dataclass
¶
A complete PLC project: main program plus subroutines.
laddercodec.find_v4_only ¶
Return every v4-only instruction in rungs as (rung index, instruction) pairs.
An empty list means that laddercodec knows of nothing in the rungs that needs CLICK v4.
laddercodec.is_v4_only ¶
Return True if instruction needs CLICK v4.
An older CLICK changes such an instruction when you paste it. A Fill of a hex digit into TXT is the exception: the function returns True for it because an older CLICK's Fill dialog refuses it.
laddercodec.addresses ¶
Return every address that payload stores or implies, with only a range's two ends.
payload is a Rung, a list of rungs, or clipboard bytes as encode() writes
them or CLICK copies them. The function encodes rungs first. addresses() returns
the same list for a rung and for its encoded bytes. Each address is in display form
(X001, DS1, XD0u) and appears once, in the order that the payload first
uses it.
The list holds each address that an instruction's fields store, both ends of each
range, the ends that the encoder works out ("HALLO" into TXT1 ends in TXT5), and
the index of each pointer (DS1 in TXT[DS1]). It holds the addresses in a Math
formula, in an Email's indexed arrays, in a raw cell and in an unknown condition too.
It also lists a Send's or a Receive's remote start, an address in the other PLC, and a
time drum's done bit (T4 for the accumulator TD4). The list does not hold the
addresses between the ends of a range, or text inside a quoted constant.
If the function can't walk a row of the bytes, it issues an UndecodedRungWarning
that names the row. The list then lacks the addresses in that row and in every row
after it. If the function can't read the fields of a cell, it issues an
UndecodedRungWarning that names the cell, and the list lacks the addresses in that
cell. decode() reads such a cell as an unknown cell and issues no warning.
Raises¶
TypeError
If payload is text or None.
EncodeError, FieldError
If payload is rungs that encode() refuses.
DecodeError
If payload is bytes that lack the CLICK magic or end before the cell grid.
laddercodec.check ¶
Return a finding for every shape in rungs that CLICK's syntax check refuses for how its lines connect, in rung order.
rungs can also be a :class:~laddercodec.Program or a :class:~laddercodec.Project.
check() then also reports the rules of a program that need more than one rung:
"next-without-for": a Next closes the nearest open For. A Next with no open For before it gets a finding."for-nesting-depth": loops nest at most 3 deep. A For past that depth gets a finding, and it opens no loop."oneshot-inside-loop": only the outermost For of a nest can use One Shot."return-inside-loop": a Return or End inside a loop of its own program gets a finding. So does every Return or End after a For with no Next."for-without-next": a loop that is still open at the last Return or End of its program gets a finding there, after that rung's"return-inside-loop". When no Return or End comes after the For, the For gets the finding."nested-call": a Call in a subroutine gets a finding, because a paste into CLICK drops it. In aProject, the main program isproject.main. For aProgramalone, it is the program withprog_idx1."call-without-subroutine": in aProject, a Call in the main program that names no subroutine of the project gets a finding. A mainProgramalone gets none, even in the shape of a project that CLICK checked."break-outside-loop"and"continue-outside-loop": a Break or a Continue that is not inside a loop gets a finding."missing-end"and"missing-return": in aProject, the main program needs an End that always runs, and each subroutine needs a Return that always runs. An End or a Return always runs when every condition cell of its row is a-orTwire, in the layout that CLICK's syntax check draws for the rung. It can be on any rung. A program without one gets a finding at the rung after its last rung. AProgramalone gets neither finding. AProgramis often a few rungs cut from a larger program. A"missing-end"finding on every suchProgramwould hide its other findings.
In a Project, the loops around a Call in the main program count in the subroutine
that the Call names. They count for its depth and for One Shot. In that subroutine, a
Next with no open For of its own closes one of those loops, and gets no finding. A Break
or a Continue there is inside those loops. A Call names the first subroutine whose name
matches Call.subroutine without regard to case. When main calls a subroutine from
loops of different depths, the loops around the deepest Call count. check() reads
any Program alone other than main as a subroutine that main calls outside any loop.
The rules of a program read each rung as CLICK's syntax check lays it out, the same way
as read_csv(). A rung that CLICK splits is read as the rungs that CLICK makes of it,
in CLICK's order. For example, take a rung whose row 0 holds - in column A and
T in column B, and whose row 1 holds wires from column B to an End. Wires alone
join the End to the rail, so it always runs. A rung that the layout can't draw, such
as one whose circuit is not series-parallel, is read as you wrote it. A program finding
still names the rung and the row of your rung, not those of the layout.
A program finding is at the instruction's AF cell. A "missing-end" or
"missing-return" finding has no cell, and it comes after the other findings of its
program. The message of a program finding ends with what to change. The finding is
captured, with its CLICK id, only in a project of the exact shape of one that CLICK
checked, and only when CLICK reported that finding there. The shape is the project's
exact CSV: each program's name, a # row for each line of each rung's comment, and
each row of the rung as it is, with each cell's CSV text. The shape is not laid out
first. The subroutines may come in any order. A main program alone has the
shape of a project with no subroutines. A subroutine alone, and a rung with a cell that
the CSV can't hold, are never captured.
check() reads no For, Next, Return, End, Call, Break or Continue after a program's
first undecoded marker, because the rung that the marker stands for may hold a For or a
Next. A RawInstruction of class For, Next, Return, End or Call stops the reading in
the same way. A For that is open where the reading stops gets no "for-without-next"
finding. A program whose reading stops before an End or a Return that always runs gets no
"missing-end" or "missing-return" finding. When the reading of the main program
stops, the loops around a later Call are not known. In that project, a Next, a Break or
a Continue in a subroutine gets no finding when the subroutine has no open For of its
own.
A Project is checked in the order project.main, then project.subroutines.
Within a program, the findings come in rung order. A rung's own findings come first, then
its program findings in row order. Each finding's program names its program.
check() also reports two problems that are not rules of CLICK's syntax check. A
rung that needs more than the 32 rows of a CLICK rung gets a "layout-too-tall"
finding. A rung whose comment encode() refuses as too long gets a
"comment-too-long" finding.
An empty list means that every rung has all of these:
- a series-parallel circuit from the rail into each box input, pins included;
- no box above a box with a used pin, on the pinned box's main input's net or on a net that the main input's circuit runs through;
- no input of another box on a pin's net, unless that net is the rail;
- contacts of its own on every pin input.
On a rung whose circuit is not series-parallel, the C0001 finding is the last one for
that rung. No C000A finding, and no finding about a pin's contacts, follows it.
encode() refuses a rung with an "undecoded-rung" or "comment-too-long"
finding, and a rung of more than 32 rows. It encodes a rung with any other finding as
drawn. That includes a 32-row rung with a box that runs past the last row. check()
reports that rung as "layout-too-tall". A finding with captured False may
be a shape that CLICK accepts, such as a reset wired straight from the rail.
A rung that holds an undecoded marker gets one "undecoded-rung" finding for each
marker, at the marker's AF cell, before its other findings. A marker rung, as the
decoders make it, is one row of wires from the rail into the marker. It gets no other
finding, because its wires only stand in for the rung or rungs that did not decode. That
includes "comment-too-long". encode() refuses the rung for its marker, whatever
its comment.
A rung that needs more than the 32 rows of a CLICK rung gets one "layout-too-tall"
finding about the whole rung, after its "undecoded-rung" findings. The count
includes every row that a box spans, as encode() writes the box. write_csv()
refuses the rung too, unless the rungs that it would write each fit in 32 rows. They
can fit when CLICK splits the rung, or when the layout drops blank rows.
A rung whose comment's RTF body is longer than the 1400 bytes that encode() accepts
gets one "comment-too-long" finding about the whole rung. The size counts each
character as encode() writes it. The finding comes after the rung's
"undecoded-rung" and "layout-too-tall" findings, and before its other findings.
On one rung, encode() refuses a marker, or more than 32 rows, before it reads the
comment. A comment that is not text gets no finding.
check() raises :class:~laddercodec.EncodeError before it reports any finding if
a rung has no rows, if a rung has a row that does not have 31 condition cells, or if a
rung does not have one AF token for each row. encode() refuses the same rung.
laddercodec.Finding
dataclass
¶
One shape in a rung that CLICK's syntax check refuses, or may refuse.
Attributes¶
rung:
Index of the rung in the checked list, or in its program's rungs, from 0. A
"missing-end" or "missing-return" finding is at len(program.rungs), the
empty rung after the program's last rung.
code:
The :class:~laddercodec.Code that names the shape. In the decoding guide, the
table under "Check for rungs CLICK's syntax check rejects or redraws" gives each
code's shape and CLICK id.
click_id:
CLICK's syntax check error code for the shape, or None where no code is known.
captured:
Whether CLICK's syntax check is known to report this shape with click_id.
False for every finding with no CLICK id. Also False for the findings
below, which have a CLICK id. For each, the brackets give the id and the shape
that CLICK is known to report with it.
- ``"not-series-parallel"`` on a pin input (C0001, as for a main input).
- ``"input-without-contact"`` on a reset that is wired straight from the rail, or
whose contacts all belong to another pin (C0205 or C0212, as for a reset whose
contacts all belong to the main input).
- ``"unwired-input"`` on a pin other than a timer's or counter's reset, on a pin
whose row holds a contact or a wire, or in a rung whose rail reaches no box
(C0202, as for a reset whose row holds nothing, in a rung whose rail reaches a
box).
- ``"output-above-box-inputs"`` where the box above is a ``NOP`` or a box with a
used pin (C000A, as for an output above).
- ``"shared-input-net"`` where a pin's net is shared with another pin, with a
``NOP``, with a main input above the pin, or with the pinned box's own main input
(C000A, as for another box's main input below the pin, on a net that is not the
pinned box's main input net).
- ``"no-rail"`` or ``"feeds-no-box"`` on a loop of contacts, and ``"no-coil"`` when
all of its paths end in such a loop.
A program finding, such as ``"for-without-next"``, is captured only in a project
of the exact shape of one that CLICK checked, and only when CLICK reported that
finding there. A larger project that contains such a shape is not captured. A
``"nested-call"`` finding has no CLICK id.
These findings are provisional. Their codes may be renamed or dropped once CLICK's
response to those shapes is captured. An ``"undecoded-rung"`` finding is not
provisional. It reports an undecoded marker, which CLICK never sees.
row, column:
The cell, with both counted from 0. row 0 is the rung's first row. column
0 is A and 31 is AF. Both are None for a finding about the whole rung or the
whole program. A "no-rail" or "feeds-no-box" finding is at a contact. When
the finding is captured, that is the contact CLICK names in its C0202 error. A
finding about a box input is at the input's AF cell. A finding about a whole box is
at the AF cell of the box's first row.
message:
The finding in words. A captured C0202 finding gives the cell as CLICK prints it,
with rows counted from 1. row 2, column 3 reads row 3, column D in
CLICK's numbering. When the rung's first row is blank, the count starts on the
second row, so the same cell reads row 2. This rule is not known to hold for
every rung, and CLICK may count otherwise. Every other finding with a cell gives
it counted from 0, as row 2 from 0, column D. The message ends with
(CLICK: <click_id>) when captured is True. Otherwise it ends by saying
that CLICK's response to the shape is not captured. Four kinds of finding end
otherwise. An "undecoded-rung" finding ends with the marker's error. A
"layout-too-tall" finding ends by saying how to split the rung. A
"comment-too-long" finding ends by saying how many bytes to cut from the comment.
A program finding, such as "for-without-next", gives its CLICK id, or says that
CLICK's response is not captured. A "nested-call" finding says that it has no
CLICK id. It then ends with what to change.
program:
The Program.name of the program that holds the rung, such as "Main Program".
It is None when check() was given rungs.
laddercodec.FieldError ¶
Bases: LaddercodecError
Raised when an instruction field holds a value that CLICK's dialog refuses.
An instruction runs its checks when it is built. If its checks refuse any values, it
raises one error for the first refusal, and the :attr:errors of that error holds
every refusal. A decoder that meets this error keeps the instruction and its
refusal. A blob that no stored instruction holds, such as an address not in display
form, stays unparsed. The message is for people and may change. Read the attributes
instead.
Attributes¶
field:
The refused field, written as Class.attr, with [i] for an item of a list
field, such as Coil.range_end or Drum.outputs[2]. Class is the class
whose checks refused the value. It is an instruction or a Modbus target
(ModbusTcpTarget.port). attr is one of its dataclass fields. field
is None only for a CSV token that does not follow its instruction's syntax.
fields:
Every field that the refusal is about, with :attr:field first. It is
(field,) for one field, and holds both fields for a pair, such as
CompareContact.left with CompareContact.right.
reason:
Why the field refused the value, as a :class:Reason. None when the check
names no reason.
code:
The rule that refused the value, as a :class:~laddercodec.Code, such as
"bank-not-allowed". Each refusal in :attr:errors has its own code.
click_id:
CLICK's id for the error ("OBJ-005"), or None where CLICK has none.
errors:
Every refusal from one construction, with this one first. It is (self,)
when there is one refusal.
obj:
The instruction being built when its checks refused the value, or None.
span:
Where a refusal of a Math formula is in the formula: a (start, end) pair of
character offsets into Math.expression as it was passed, before any trimming or
change of case. expression[start:end] is the refused text, and end is not
part of it. For a Math that a decoder built, the offsets index into the decoded
Math's expression, not into the display text that CLICK stored. span is
None for a refusal of any other field. It is also None for a formula refusal that
no one stretch of the formula causes: a blank formula, a formula that is too long,
a ( with no ), a key that only the other mode takes, and a formula that is
not a string, such as Math(5, "DS1").
laddercodec.AddressError ¶
Bases: FieldError
Raised when a field holds an address outside CLICK's banks or ranges, or in a bank that the field does not allow.
laddercodec.Reason ¶
Bases: StrEnum
Why a field refused its value. :attr:FieldError.reason holds one of these.
The set is fixed. Each value compares equal to its text (Reason.BANK == "bank").
ADDRESS
class-attribute
instance-attribute
¶
Not a CLICK address: not an address at all, no bank of that name, or a number
outside its bank (DS5000).
BANK
class-attribute
instance-attribute
¶
A CLICK address in a bank the field does not take.
RANGE
class-attribute
instance-attribute
¶
A number, a constant or a length outside the field's limits.
POINTER
class-attribute
instance-attribute
¶
A pointer that the field does not take. The field takes no pointer, or no pointer to this bank, or the pointer's index is not a DS address.
KIND
class-attribute
instance-attribute
¶
A constant of a kind the field does not take, or text that is no constant.
FORM
class-attribute
instance-attribute
¶
Written in a form the field does not take: a sign, a quote, a character, a shape,
XD0u where the field takes no upper byte, or an address not in display form.
NOT_WRITABLE
class-attribute
instance-attribute
¶
An address the instruction can't write: a read-only SC bit or SD register.
CHOICE
class-attribute
instance-attribute
¶
Not one of the field's named values, such as a timer unit.
CONFLICT
class-attribute
instance-attribute
¶
A value that the field takes, but not together with another field's value. Most such
refusals name the other field in :attr:FieldError.fields as well. An immediate
Coil on a C bit names Coil.operand and Coil.immediate.
MISSING
class-attribute
instance-attribute
¶
Blank where the field needs a value.
laddercodec.Code ¶
Bases: StrEnum
The name of the rule that a refusal, a finding or a layout error reports.
Each member compares equal to its text: Code.NO_COIL == "no-coil" is true. One code
can come with several CLICK ids, or with none. The click_id of the refusal, finding
or layout error says which id CLICK gave. The error codes page in the docs lists every
code.
BLANK_FIELD
class-attribute
instance-attribute
¶
A field that needs a value is blank.
NOT_AN_ADDRESS
class-attribute
instance-attribute
¶
Text that is no CLICK address or names no bank, or a value that is not text.
ADDRESS_OUT_OF_RANGE
class-attribute
instance-attribute
¶
A number outside its bank (DS5000, X017).
BANK_NOT_ALLOWED
class-attribute
instance-attribute
¶
An address in a bank the field doesn't take.
UPPER_BYTE_NOT_ALLOWED
class-attribute
instance-attribute
¶
XD0u or YD0u in a field that takes no upper byte.
NOT_CLICK_FORM
class-attribute
instance-attribute
¶
A stored value in a form that CLICK never writes. It is an address, a Math keypad name or a Math hex constant that is not in display form (x1, sqrt), or a numeric tag that holds no number. A decoder keeps such a blob raw.
NOT_WRITABLE
class-attribute
instance-attribute
¶
An address the instruction can't write: a read-only SC bit, an SD outside the writable list, or a Send to a read-only Modbus type.
POINTER_OUTSIDE_COPY
class-attribute
instance-attribute
¶
A pointer in any field but a single Copy's source or destination.
POINTER_BANK_NOT_ALLOWED
class-attribute
instance-attribute
¶
A pointer to a bank the field's pointer can't address.
POINTER_NOT_DS
class-attribute
instance-attribute
¶
A pointer whose index is no DS address.
CONSTANT_KIND_NOT_ALLOWED
class-attribute
instance-attribute
¶
A constant of a kind the field doesn't take, or a Python value of the wrong type, such as 2.5 for a Send or Receive quantity.
NOT_A_CONSTANT
class-attribute
instance-attribute
¶
Text read as neither an address nor a constant.
CONSTANT_OUT_OF_RANGE
class-attribute
instance-attribute
¶
A constant outside the field's limits (its value, hex digits, float32, text length or typed length), or a minus sign where the field's lowest value is 0 or more.
INVALID_CONSTANT
class-attribute
instance-attribute
¶
A constant in a form the field refuses: a + where no sign is taken, a sign before hex, a space in a count, a real with more significant digits than CLICK keeps, or a hex constant that spells a bank name (DH) in Compare's Data B opposite a hex Data A.
INVALID_CHAR_CODE
class-attribute
instance-attribute
¶
A $hh or a termination code that is no character code.
INVALID_TEXT_CONSTANT
class-attribute
instance-attribute
¶
Quoted text holding a quote or a character CLICK doesn't keep.
NOT_A_FLAG
class-attribute
instance-attribute
¶
A flag that is not True, False, 1 or 0.
INVALID_CHOICE
class-attribute
instance-attribute
¶
Not one of the field's named values: a unit, type, op, format, kind, port, function code, stop or pattern cell.
OPTION_NOT_OFFERED
class-attribute
instance-attribute
¶
A field or option CLICK's dialog greys out for the other fields' values.
RANGE_MIXED_BANKS
class-attribute
instance-attribute
¶
A range whose two ends are in two banks.
RANGE_NOT_ASCENDING
class-attribute
instance-attribute
¶
A range that ends below its start, such as C5..C1.
RANGE_CROSSES_SLOT
class-attribute
instance-attribute
¶
An X or Y range that crosses a 16-point slot.
DUPLICATE_ADDRESS
class-attribute
instance-attribute
¶
Two fields that must differ name one address, such as the two ends of the range C1..C1.
TIMER_PAIR_MISMATCH
class-attribute
instance-attribute
¶
A timer's or counter's done bit and accumulator with different numbers, such as T1 with TD2.
IMMEDIATE_CONTACT_NOT_X
class-attribute
instance-attribute
¶
An immediate contact outside X.
IMMEDIATE_COIL_NOT_Y
class-attribute
instance-attribute
¶
An immediate coil outside Y.
IMMEDIATE_EDGE_CONTACT
class-attribute
instance-attribute
¶
Immediate on a rise or fall contact.
IMMEDIATE_NOT_ALLOWED
class-attribute
instance-attribute
¶
Immediate on an instruction with no immediate form.
TEXT_ORDER_COMPARE
class-attribute
instance-attribute
¶
< or > on text, in a Compare or a Search.
INVALID_SUBROUTINE_NAME
class-attribute
instance-attribute
¶
A subroutine name that is not text, is over 24 characters, holds a forbidden character or is a device name.
DUPLICATE_SUBROUTINE_NAME
class-attribute
instance-attribute
¶
Two subroutine names that are equal when the case of A-Z is ignored, such as Pump and pump.
INVALID_INPUT_ROWS
class-attribute
instance-attribute
¶
pin_rows that is not one ascending row (1 to 255) per box input.
COPY_BANK_INCOMPATIBLE
class-attribute
instance-attribute
¶
A source bank or kind that can't copy into this destination bank.
CONSTANT_INTO_BIT
class-attribute
instance-attribute
¶
A single Copy of a constant into a bit address.
COPY_CONVERTER_BANK
class-attribute
instance-attribute
¶
A converter the source and destination kinds don't offer.
COPY_TXT_NEEDS_CONVERT
class-attribute
instance-attribute
¶
A single Copy between TXT and a number, or a Block Copy from TXT into numbers, with no converter.
COPY_HEX_READS_AS_REAL
class-attribute
instance-attribute
¶
A Copy source EH or 1EH into any bank except TXT, or a Fill of EH into TXT. CLICK reads each as a real.
TEXT_PAST_BANK
class-attribute
instance-attribute
¶
Text a Copy writes that runs past TXT1000, or a Copy Binary of a constant whose end is past it.
BLOCK_COPY_END_MISMATCH
class-attribute
instance-attribute
¶
A Block Copy dest_end that is not where the copy ends.
PACK_KIND_MISMATCH
class-attribute
instance-attribute
¶
A Pack or Unpack kind (bits, words or text) that doesn't match the bank.
PACK_TOO_MANY
class-attribute
instance-attribute
¶
A Pack source or Unpack destination past its count limit.
MATH_NICKNAME
class-attribute
instance-attribute
¶
A formula that holds a <nickname>.
MATH_INVALID_TOKEN
class-attribute
instance-attribute
¶
A word or character that is no formula part, or a formula that is not text.
MATH_CONSTANT_KIND
class-attribute
instance-attribute
¶
A hex constant in a decimal Math, a constant without an h in a hex Math, or a text constant in any Math.
MATH_CONSTANT_OUT_OF_RANGE
class-attribute
instance-attribute
¶
Hex over 4 digits, a real past float32 or with more digits than CLICK keeps, an integer past int32, or leading zeros.
MATH_NESTING_DEPTH
class-attribute
instance-attribute
¶
Parentheses more than 8 deep.
MATH_UNBALANCED_PARENS
class-attribute
instance-attribute
¶
A ) with no (, or a ( with no ).
MATH_FUNCTION_MODE
class-attribute
instance-attribute
¶
A function, an operator or PI that only the other mode's keypad has, such as SIN in a hex Math or XOR in a decimal Math.
MATH_SYNTAX_ERROR
class-attribute
instance-attribute
¶
A formula with tokens out of order, a comma outside a call, : outside a range function, or a wrong first or last token.
MATH_ARG_EXPRESSION
class-attribute
instance-attribute
¶
A function argument that is not one address or constant.
RANDOM_BOUND_TYPE
class-attribute
instance-attribute
¶
A RAND bound that is a real, or in a bank RAND doesn't take.
RANDOM_EQUAL_BOUNDS
class-attribute
instance-attribute
¶
RAND with equal bounds.
MATH_OPERAND_BANK
class-attribute
instance-attribute
¶
An address outside a SUM range, in a bank that the Math mode doesn't take. A decimal Math takes bit addresses only in a SUM range.
SUM_BANK_UNAVAILABLE
class-attribute
instance-attribute
¶
SUM over a bank SUM doesn't read.
MATH_RANGE_MIXED_BANKS
class-attribute
instance-attribute
¶
An a : b range in two banks.
MATH_RANGE_NOT_ASCENDING
class-attribute
instance-attribute
¶
An a : b range that runs high to low.
MEDIAN_RANGE_TOO_LARGE
class-attribute
instance-attribute
¶
MDN over more than 1024 bytes.
SUM_OPTION_SLOT
class-attribute
instance-attribute
¶
An X or Y SUM range with an end in the option slot.
MATH_FORMULA_TOO_LONG
class-attribute
instance-attribute
¶
A formula longer than 270 characters in the internal form that CLICK stores.
COMPARE_MIXED_TYPES
class-attribute
instance-attribute
¶
Compare operands in different groups (hex, numeric, text).
SEARCH_VALUE_BANK
class-attribute
instance-attribute
¶
A Search value whose kind or compare group doesn't search the table's bank.
COIL_TIME_UNIT
class-attribute
instance-attribute
¶
An Out variant with a time unit its kind lacks.
DEBOUNCE_NEEDS_PHASE
class-attribute
instance-attribute
¶
A debounce with neither phase filled.
DRUM_SIZE_OUT_OF_RANGE
class-attribute
instance-attribute
¶
Drum steps or outputs outside 1 to 16.
DRUM_PATTERN_SHAPE
class-attribute
instance-attribute
¶
A drum pattern or event list that doesn't match its steps and outputs.
DRUM_STEP_EMPTY
class-attribute
instance-attribute
¶
A drum step with no event or duration.
FUNCTION_CODE_MISMATCH
class-attribute
instance-attribute
¶
A Modbus function code that doesn't fit the remote type or the count.
COUNT_OUT_OF_RANGE
class-attribute
instance-attribute
¶
A Send or Receive count past its cap or room, or an odd TXT count.
TXT_START_NOT_ODD
class-attribute
instance-attribute
¶
A Send of TXT that starts at an even address, such as TXT1000.
REMOTE_ADDRESS_OUT_OF_RANGE
class-attribute
instance-attribute
¶
A remote start outside the MODBUS 984 ranges, or past FFFDh.
INVALID_MODBUS_TARGET
class-attribute
instance-attribute
¶
A Modbus target with a bad device_id, IP or port, or a Send or Receive target that is no Modbus target.
FOR_COUNT_BANK
class-attribute
instance-attribute
¶
A For loop count in a bank the count doesn't take.
INVALID_TOKEN
class-attribute
instance-attribute
¶
A CSV token that doesn't follow its instruction's syntax.
INVALID_RAW
class-attribute
instance-attribute
¶
A RawInstruction field with a value of the wrong type or out of range, or a raw(...) token whose rows= does not fit its pins=.
INVALID_UNDECODED
class-attribute
instance-attribute
¶
An Undecoded field refused.
INVALID_TEE
class-attribute
instance-attribute
¶
A Tee built around something other than one contact.
INVALID_CIRCUIT
class-attribute
instance-attribute
¶
A Series, Parallel, Box, Branch or Circuit built from a part it doesn't take, such as a Parallel with one leg, an empty Series outside a Parallel, or a pin that the box doesn't use.
NOT_SERIES_PARALLEL
class-attribute
instance-attribute
¶
A circuit that is not series-parallel.
NO_RAIL
class-attribute
instance-attribute
¶
A contact whose input no rail reaches.
FEEDS_NO_BOX
class-attribute
instance-attribute
¶
A contact that feeds no box.
NO_COIL
class-attribute
instance-attribute
¶
A path from the rail that reaches no box.
CONTACT_FEEDS_ONLY_NOP
class-attribute
instance-attribute
¶
A contact that feeds a NOP and no other box.
UNWIRED_INPUT
class-attribute
instance-attribute
¶
A box input (a Reset input, a Down input, ...) that no rail or contact reaches.
OUTPUT_ABOVE_BOX_INPUTS
class-attribute
instance-attribute
¶
A box above a lower box that uses an input row, such as a .reset() row, where the upper box's main input is on the lower box's main input circuit. That is the lower box's main input net, or a net that its main input circuit runs through from the rail. The rail reaches that net through a contact.
SHARED_INPUT_NET
class-attribute
instance-attribute
¶
A box input whose net another input shares.
INPUT_WITHOUT_CONTACT
class-attribute
instance-attribute
¶
A box input with no contact of its own.
INPUT_SHARES_ENABLE
class-attribute
instance-attribute
¶
A box input whose circuit shares contacts with an enable.
INPUTS_SHARE_CONTACTS
class-attribute
instance-attribute
¶
A box input whose circuit shares contacts with another box input.
UNPOWERED_BOX
class-attribute
instance-attribute
¶
A box that no rail or contact reaches.
SHORTED_CONTACT
class-attribute
instance-attribute
¶
A wire that joins a contact's two sides.
UNDECODED_RUNG
class-attribute
instance-attribute
¶
A rung that holds an Undecoded marker. The marker stands in for a rung that a decoder could not decode, that write_csv could not write or that write_bundle could not strip.
COMMENT_TOO_LONG
class-attribute
instance-attribute
¶
A rung comment whose RTF body is longer than the 1400 bytes that encode() accepts.
FOR_WITHOUT_NEXT
class-attribute
instance-attribute
¶
A loop that is still open at the last Return or End of its program, or a For with no Next and no Return or End after it.
NEXT_WITHOUT_FOR
class-attribute
instance-attribute
¶
A Next with no open For before it.
FOR_NESTING_DEPTH
class-attribute
instance-attribute
¶
A For that would nest loops more than 3 deep. The loops around a Call count in the subroutine that it calls.
ONESHOT_INSIDE_LOOP
class-attribute
instance-attribute
¶
A For with One Shot on, inside another loop. Only the outermost For of a nest can use One Shot.
RETURN_INSIDE_LOOP
class-attribute
instance-attribute
¶
A Return or an End inside a loop of its own program.
NESTED_CALL
class-attribute
instance-attribute
¶
A Call in a subroutine. A paste into CLICK drops it.
CALL_WITHOUT_SUBROUTINE
class-attribute
instance-attribute
¶
A Call in the main program that names no subroutine of the project. The names match without regard to case.
BREAK_OUTSIDE_LOOP
class-attribute
instance-attribute
¶
A Break that is not inside a For/Next loop.
CONTINUE_OUTSIDE_LOOP
class-attribute
instance-attribute
¶
A Continue that is not inside a For/Next loop.
MISSING_END
class-attribute
instance-attribute
¶
A main program with no End that always runs. An End behind a contact does not count.
MISSING_RETURN
class-attribute
instance-attribute
¶
A subroutine with no Return that always runs. A Return behind a contact does not count.
LAYOUT_TOO_WIDE
class-attribute
instance-attribute
¶
A layout that needs more than 31 condition columns.
LAYOUT_TOO_TALL
class-attribute
instance-attribute
¶
A rung that needs more than the 32 rows that a CLICK rung holds.
LAYOUT_NOP_SPLIT
class-attribute
instance-attribute
¶
A rung that CLICK would split into several rungs, and that holds a NOP behind a contact or has only NOPs as outputs. laddercodec does not know how CLICK splits such a rung.
LAYOUT_CANNOT_DRAW
class-attribute
instance-attribute
¶
Nets that collide, cells that overlap, or a contact drawn twice.
laddercodec.CLICK_IDS
module-attribute
¶
CLICK_IDS: dict[Code, tuple[str, ...]] = {
Code.NOT_AN_ADDRESS: (
"OBJ-002",
"OBJ-003",
"OBJ-004",
"OBJ-005",
),
Code.ADDRESS_OUT_OF_RANGE: ("OBJ-002", "OBJ-003"),
Code.BANK_NOT_ALLOWED: ("OBJ-003", "OBJ-004"),
Code.NOT_WRITABLE: ("OBJ-003", "OBJ-004", "OBJ-018"),
Code.POINTER_BANK_NOT_ALLOWED: ("OBJ-004",),
Code.CONSTANT_OUT_OF_RANGE: ("OBJ-005", "OBJ-023"),
Code.INVALID_CONSTANT: ("OBJ-005",),
Code.INVALID_CHAR_CODE: ("OBJ-036",),
Code.RANGE_MIXED_BANKS: ("OBJ-008",),
Code.RANGE_NOT_ASCENDING: ("OBJ-009",),
Code.RANGE_CROSSES_SLOT: ("OBJ-033", "OBJ-1009"),
Code.DUPLICATE_ADDRESS: ("OBJ-012", "OBJ-014"),
Code.INVALID_SUBROUTINE_NAME: ("GUI-040",),
Code.DUPLICATE_SUBROUTINE_NAME: ("GUI-036",),
Code.COPY_BANK_INCOMPATIBLE: ("OBJ-004", "OBJ-024"),
Code.CONSTANT_INTO_BIT: ("OBJ-004", "OBJ-024"),
Code.TEXT_PAST_BANK: ("OBJ-003",),
Code.PACK_TOO_MANY: (
"OBJ-003",
"OBJ-027",
"OBJ-032",
"OBJ-039",
"OBJ-040",
"OBJ-041",
"OBJ-042",
),
Code.MATH_INVALID_TOKEN: ("OBJ-1001",),
Code.MATH_CONSTANT_KIND: ("OBJ-1001",),
Code.MATH_CONSTANT_OUT_OF_RANGE: ("OBJ-1009",),
Code.MATH_NESTING_DEPTH: ("OBJ-1010",),
Code.MATH_UNBALANCED_PARENS: ("OBJ-1004", "OBJ-1005"),
Code.MATH_FUNCTION_MODE: ("OBJ-1006",),
Code.MATH_SYNTAX_ERROR: ("OBJ-1001", "OBJ-037"),
Code.MATH_ARG_EXPRESSION: ("OBJ-1001",),
Code.RANDOM_BOUND_TYPE: ("OBJ-1001", "OBJ-1002"),
Code.RANDOM_EQUAL_BOUNDS: ("OBJ-1001",),
Code.MATH_OPERAND_BANK: ("OBJ-1002",),
Code.SUM_BANK_UNAVAILABLE: ("OBJ-1002",),
Code.MATH_RANGE_MIXED_BANKS: ("OBJ-1015",),
Code.MATH_RANGE_NOT_ASCENDING: ("OBJ-1014",),
Code.MEDIAN_RANGE_TOO_LARGE: ("OBJ-1013",),
Code.MATH_FORMULA_TOO_LONG: ("OBJ-1008",),
Code.DEBOUNCE_NEEDS_PHASE: ("OBJ-006",),
Code.DRUM_STEP_EMPTY: (
"OBJ-021",
"OBJ-022",
"OBJ-1019",
),
Code.FUNCTION_CODE_MISMATCH: ("OBJ-004",),
Code.COUNT_OUT_OF_RANGE: ("OBJ-010", "OBJ-029"),
Code.TXT_START_NOT_ODD: ("OBJ-028",),
Code.REMOTE_ADDRESS_OUT_OF_RANGE: ("OBJ-010",),
Code.FOR_COUNT_BANK: ("OBJ-004",),
Code.COMPARE_MIXED_TYPES: ("OBJ-007",),
Code.SEARCH_VALUE_BANK: ("OBJ-004",),
Code.NOT_SERIES_PARALLEL: ("C0001",),
Code.NO_RAIL: ("C0202",),
Code.FEEDS_NO_BOX: ("C0202",),
Code.NO_COIL: ("C0003",),
Code.CONTACT_FEEDS_ONLY_NOP: ("C0003",),
Code.UNWIRED_INPUT: ("C0202",),
Code.OUTPUT_ABOVE_BOX_INPUTS: ("C000A",),
Code.SHARED_INPUT_NET: ("C000A",),
Code.INPUT_WITHOUT_CONTACT: ("C0205", "C0212"),
Code.UNPOWERED_BOX: ("C0202",),
Code.SHORTED_CONTACT: ("C0002",),
Code.FOR_WITHOUT_NEXT: ("C0102",),
Code.NEXT_WITHOUT_FOR: ("C0101",),
Code.FOR_NESTING_DEPTH: ("C010D",),
Code.ONESHOT_INSIDE_LOOP: ("C0111",),
Code.RETURN_INSIDE_LOOP: ("C0115",),
Code.CALL_WITHOUT_SUBROUTINE: ("C010C",),
Code.BREAK_OUTSIDE_LOOP: ("C010F",),
Code.CONTINUE_OUTSIDE_LOOP: ("C0110",),
Code.MISSING_END: ("C0201",),
Code.MISSING_RETURN: ("C0105",),
}
The CLICK ids that each code can come with.
A code that is missing here has no CLICK id. A blank-field refusal has the id of the
check that refused the blank, whatever that id is.
laddercodec.LaddercodecError ¶
Bases: ValueError
The base class of every error that laddercodec raises for input it can't read or write.
except LaddercodecError catches all of them, and so does except ValueError.
:meth:message, :meth:short and :meth:detail return the error's text with your
names for the addresses in it. A FieldError from any instruction, Modbus target
or ModbusAddress shows your name for each address it names, except in a Math
refusal that quotes the whole formula. The refusals of Call, Tee,
RawInstruction, Undecoded, Series, Parallel, Box, Branch and
Circuit name no address, but they still split into :meth:short and
:meth:detail. A
CsvReadError about the shape of a token shows no names. For example,
read_csv refuses blockcopy(DS1,DS10..DS20) with 'DS1' is not a range, and
:meth:message returns that text with no name in it. A CsvReadError that wraps a
box's refusal shows names as that refusal does. Any other error ignores the names.
message ¶
Return the error's text, with each address in names shown by its name.
With names None or empty, return str(err). Otherwise each address that
names maps is replaced by its name. CLICK's form of the value follows in
parentheses when the two differ. A name that is another form of the same address,
such as X1 for X001, gets no parentheses. A value that holds an address is
shown without quotes, even if no key of names is a CLICK address. When a
Math refusal quotes the whole formula, names do not replace the addresses in it,
and the formula stays in quotes. For the refusal err
that Copy(source="DS1", dest="C1") raises::
str(err)
# Copy.dest: 'C1' can't take 'DS1'; a numeric register copies to DS, DD, ...
err.message({"C1": "Valve"})
# Copy.dest: Valve (C1) can't take DS1; a numeric register copies to DS, DD, ...
A range and a pointer are shown in the same way:
Valve1..Valve2 (C1..C2)when both ends have names.Valve1..C2 (C1..C2)when only the start has a name.DS[Ptr] (DS[DD1])when the pointer's index register has a name.
A key of names may be in any form that CLICK reads, such as ds1 or
DS001. It matches the address in CLICK's display form. A key that is not a
CLICK address is ignored. If two keys are the same address, the later key is used.
A constant, a bank list and a limit are never replaced. A CSV location stays at
the end of the text.
short ¶
Return the refused value and its rule, such as 'C1' can't take 'DS1'.
The text has no Class.field: prefix, no explanation, no CLICK id and no CSV
location. Where the rule names the field, it says this field instead, so
outside the range of Copy.dest becomes outside the range of this field.
names works as it does for :meth:message. For an error that does
not show names, return str(err) without its Class.field: prefix and without
its CSV location.
detail ¶
Return the explanation alone, such as a numeric register copies to DS, DD, ....
If the error also tells you what to do, that sentence follows the explanation.
Where the explanation names the field, it says this field instead, so
Fill.value takes one character becomes this field takes one character.
names works as it does for :meth:message. Return an empty string for a
refusal that has no explanation, and for an error that does not show names.
laddercodec.DecodeError ¶
Bases: LaddercodecError
Raised when a clipboard binary or a program file cannot be decoded.
For example, decode() raises it when the binary does not start with the expected
magic bytes or is too short. decode_program() raises it when it can't read
the file header.
laddercodec.EncodeError ¶
Bases: LaddercodecError
Raised when encode() is given a rung it can't write.
Examples are a grid of the wrong size, a vertical wire token in a cell where CLICK
can't draw one, more than one NOP, an undecoded marker, and a comment that is too
long once it is written as RTF. A value that CLICK's dialog refuses raises
:class:~laddercodec.FieldError instead.
check() raises it for a rung with no rows, for a rung with a row that does not have
31 condition cells, and for a rung that does not have one AF token for each row.
laddercodec.CsvWriteError ¶
Bases: LaddercodecError
Raised when write_csv or csv_rows is given a rung that the CSV can't hold, or
a bad stop=.
stop= must be "end" or "return". write_csv builds every row before it
opens the file. If it raises CsvWriteError, it has not created or changed the file.
write_bundle raises it for a rung that the CSV can't hold, for two subroutines whose
names are equal when the case of A-Z is ignored, for two subroutines whose files would be
one file on a file system that ignores case, for a subroutine name that holds a control
character, and for a path that it would write that exists and is of the wrong kind. It
raises before it writes any file.
write_csv, csv_rows and write_bundle raise it for a rung that needs more than
the 32 rows of a CLICK rung. The __cause__ is then a :class:LayoutError with the
code layout-too-tall.
code and click_id are None, except in these two cases:
- For a rung that needs more than 32 rows,
codeislayout-too-tallandclick_idisNone. - For two subroutines whose names are equal when the case of A-Z is ignored,
codeisduplicate-subroutine-nameandclick_idisGUI-036.
laddercodec.CsvReadError ¶
Bases: LaddercodecError
Raised when read_csv or read_bundle cannot read a CSV.
read_csv raises it for a file that isn't UTF-8 text, and for a row, a token or a
rung that it can't read. Like every error that read_csv raises for a bad CSV, it
has a :class:~laddercodec.CsvLocation as its location attribute.
read_bundle raises it for the same reasons in any file of the bundle. It also
raises it when main.csv is missing, when CLICK refuses the name of a file in
subroutines/ as a subroutine name, when one of those names starts or ends with
whitespace, and when two of them are equal with the case of A-Z ignored. For a name
that CLICK refuses, the CsvReadError copies the refusal's data in the same way as for a
pin row, described next.
Both functions raise it for a bad allow=, before they read any file. A bad
allow= is an item that is not a code's name, a single string or bytes in place of a
list, a value that you can't iterate over, or a non-empty allow= with
unchecked=True. This CsvReadError has no location.
Some boxes, such as a counter, take inputs from pin rows below the box's own row.
read_csv builds such a box from all of its rows. If the box refuses a value at that
step, the FieldError reaches you wrapped in a CsvReadError, and except FieldError
does not catch it. The CsvReadError copies the refusal's data. field, fields,
reason, code and click_id are those of the first refusal, with the meanings
they have on FieldError. errors holds every refusal for the box, and each is a
FieldError with its own location. errors[0] is the wrapped FieldError,
which is also __cause__. It is not this exception. A refusal of a value that a pin
row sets is located at that pin's row. Any other refusal is located at the box's own row.
A CsvReadError that is not about a refused field has field and reason set to
None, an empty fields, and errors == (self,). A pin token that does not
parse and a rung with no rows are two examples. Such a CsvReadError has code and
click_id set to None, except in these two cases:
read_csvandread_bundleraise it for a rung that needs more than the 32 rows of a CLICK rung, in strict and in relaxed mode. Itscodeis thenlayout-too-tall, itsclick_idisNone, and its location is the rung'sRrow.read_bundleraises it for two files insubroutines/whose names are equal when the case of A-Z is ignored. Itscodeis thenduplicate-subroutine-name, and itsclick_idisGUI-036.
If you build a CsvReadError with refusal, it copies its attributes from the refusal
and ignores field, code and click_id.
laddercodec.LayoutError ¶
Bases: LaddercodecError
Raised by :func:~laddercodec.lay_out for a circuit that CLICK can't hold or that
laddercodec can't draw.
code is a :class:~laddercodec.Code that says why:
layout-too-tall: a rung needs more than 32 rows.layout-too-wide: a rung needs more than the 31 condition columns.layout-cannot-draw: two wires or two cells of the drawing would fall on one place.layout-nop-split: outputs meet only at the rail, and one of them is a NOP behind a contact, or all of them are NOPs.output-above-box-inputs: an output comes before a box whose pin is used, on that box's main input circuit. Itsclick_idisC000A.shared-input-net: an output comes after a box whose pin is used, on that box's main input circuit. Itsclick_idisC000A.
click_id is None for the four layout- codes. When write_csv can't lay
out a rung, it raises :class:~laddercodec.CsvWriteError. The __cause__ of that error
can be a LayoutError with one of these codes, or with the code of a check()
finding such as not-series-parallel. Its click_id is then CLICK's id when CLICK
has one, such as C0001.
laddercodec.LegacyEncodingWarning ¶
Bases: UserWarning
Issued when a decoded rung holds bytes that an older laddercodec wrote and CLICK runs differently.
Attributes¶
instruction:
Instruction class name, e.g. "Math". For a flag field that is stored empty, it
names the field too, e.g. "Copy.oneshot".
token:
The stored token, e.g. "H70000". It is "" for a flag field that is stored
empty. If no field can be named, instruction is the class and token names
the tag, e.g. "1246=".
detail:
What CLICK runs instead. For a flag field, it also says what laddercodec reads.
rung:
0-based rung index in the decoded buffer or program, or None if unknown.
program:
The program name if :func:laddercodec.decode_program decoded the rung, else
None.
laddercodec.RefusedFieldWarning ¶
Bases: UserWarning
Emitted when a decoded instruction holds a value that its checks refuse. The instruction still decodes as that instruction.
If you leave the instruction unchanged, it encodes as the bytes it was decoded from.
If you change a field with :func:~laddercodec.replace, the copy is checked again, and
a refused value raises. An instruction read from CSV, or a condition read from a
program file, has no stored bytes to write. When the instruction does not write stored
bytes and still holds a refusal, encode() raises that refusal, as building the
instruction would.
Attributes¶
instruction:
The decoded instruction, a Condition or an Instruction.
error:
The :class:~laddercodec.FieldError that building the instruction would raise.
It is the first refusal.
errors:
Every refusal, with :attr:error first. For a Send or Receive, the refusals of
its Modbus target and remote address come before its own. When
read_csv(..., unchecked=True) reads the instruction, each refusal has a
:class:~laddercodec.CsvLocation as its location, the same location that the
default read raises it with. The warning message then ends with the location of
:attr:error.
rung:
0-based rung index in the decoded buffer, program or CSV, or None if unknown.
program:
The program name for :func:laddercodec.decode_program and
:func:laddercodec.read_bundle, else None.
laddercodec.UndecodedRungWarning ¶
Bases: UserWarning
Issued when a rung can't be decoded, written or stripped, or when addresses() can't read
part of the bytes.
decode(), decode_program(), write_csv and write_bundle put an undecoded
marker in the rung's place. addresses() puts no marker anywhere. Its list lacks the addresses of
a cell whose fields it can't read, or of a row that it can't walk and every row after
that row.
Attributes¶
marker:
The :class:~laddercodec.instructions.Undecoded marker. It says where the rung,
row or cell is and what went wrong.
program:
The name of the program when the warning comes from
:func:laddercodec.decode_program, else None.
text:
The warning's message when the caller gave one, else None. addresses()
and write_bundle(strip="mark") pass one.
laddercodec.UndecodedCommentWarning ¶
Bases: UserWarning
Issued when a rung's comment, or part of it, cannot be decoded. The rung keeps its logic.
If the whole comment cannot be decoded, the rung's comment becomes
UNDECODED comment: <error>. The next line holds the plain text that can be read out
of the comment's bytes, if there is any. If that text would make the comment too long
to encode, it is cut short and ends with ....
If a font in the comment has a charset that laddercodec does not read, partial is
True. The decoder reads each non-ASCII byte in that font as U+FFFD and reads the rest of
the comment. partial is also True if a GBK font holds bytes that GBK cannot read.
The decoder reads each of those bytes as U+FFFD.
The rung's comment_rtf keeps the comment's bytes. The rung is not a marker, so
Program.undecoded does not list it.
Attributes¶
rung:
Index of the rung, from 0.
error:
Why the comment could not be decoded, on one line.
program:
The name of the program when the warning comes from
:func:laddercodec.decode_program, else None.
partial:
True if the rest of the comment was decoded, else False.
laddercodec.marker_rung ¶
Return the one-row rung that stands for a rung that could not be decoded.
Its comment is the marker's headline as text, followed by comment if one is given. A caller passes the rung's own comment, as Markdown, when that comment decoded. The one row is a wire from the rail straight into the marker, with no conditions.
Comment
Text attached to a rung. The encoder stores it as RTF: a fixed prefix, the ASCII body and a fixed suffix. The RTF goes in the payload region at 0x0298, and its 4-byte length goes at 0x0294. With no comment the cell grid starts at 0x0A60. A comment moves the grid forward by the length of the RTF. The body is at most 1400 bytes.