Validation API¶
Nickname/comment/initial-value and PLC/DataView name validators, and system nickname constants.
pyclickplc.AUTOMATIONDIRECT_SYSTEM_CONTROL_RELAY_SOURCE
module-attribute
¶
pyclickplc.AUTOMATIONDIRECT_SYSTEM_DATA_REGISTER_SOURCE
module-attribute
¶
pyclickplc.AUTOMATIONDIRECT_SYSTEM_NICKNAME_REVIEWED_ON
module-attribute
¶
pyclickplc.AUTOMATIONDIRECT_SYSTEM_NICKNAMES
module-attribute
¶
AUTOMATIONDIRECT_SYSTEM_NICKNAMES: dict[
tuple[str, int], SystemNicknameGuidance
] = {
key: SystemNicknameGuidance(
nickname=nickname,
repair_from=_KNOWN_STALE_NICKNAMES.get(
key, _NO_AUTOMATIC_REPAIR
),
source=_source_for(key),
reviewed_on=AUTOMATIONDIRECT_SYSTEM_NICKNAME_REVIEWED_ON,
)
for key, nickname in _AUTOMATIONDIRECT_SYSTEM_NICKNAME_VALUES.items()
}
pyclickplc.SystemNicknameGuidance
dataclass
¶
The CLICK nickname for one system address, and the old nicknames to replace with it.
pyclickplc.SYSTEM_NICKNAME_TYPES
module-attribute
¶
pyclickplc.canonical_system_nickname ¶
Return CLICK's nickname for a system address, or None if this catalog does not list it.
pyclickplc.canonicalize_system_nickname ¶
Return CLICK's current nickname if nickname is an old name for the address.
The old names are the ones that this catalog lists for the address. For any other nickname, or an address that the catalog does not list, return nickname unchanged.
pyclickplc.is_canonical_system_nickname ¶
Return True if nickname is CLICK's current nickname for the address in this catalog.
pyclickplc.validate_nickname ¶
Validate nickname format (length, characters, reserved words).
A nickname with a leading or trailing space, tab or other character up to 0x20 is invalid. CLICK strips those characters, so "Pump " and "Pump" would be one nickname.
A nickname with a character that first_non_cp1252_char returns is invalid in every
bank. write_csv raises ValueError for it. CLICK 4.00's Address Picker was observed
to change ł to l and to refuse a nickname with Ж.
Does NOT check uniqueness -- that is application-specific.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nickname
|
str
|
The nickname to validate |
required |
system_bank
|
str | None
|
Optional system bank context: - "SC"/"SD": allows any punctuation and a leading underscore, as in the PLC's system names - "X": allows only system names that start with _IO and a digit, such as _IO1_Module_Error - None: standard user nickname rules |
None
|
Returns:
| Type | Description |
|---|---|
tuple[bool, str]
|
Tuple of (is_valid, error_message) - error_message is "" if valid |
pyclickplc.validate_comment ¶
Validate comment length, edge whitespace and characters.
A comment with a leading or trailing space, tab or other character up to 0x20 is
invalid. CLICK's nickname CSV import drops a space or tab from either end of a comment.
So if you write such a comment with write_csv and import the file, CLICK stores a
different comment. For the other codes up to 0x20, this function assumes that the
import drops them too. The import keeps a tab inside the comment.
CLICK 4.00's Address Picker was observed to store a tab at either end of a comment when another program set the editor's text with that tab. A tab typed into the editor never reached it. So a CLICK project may hold a comment that this function rejects.
A comment with a character that first_non_cp1252_char returns is invalid. A nickname
CSV cannot hold that character, and write_csv raises ValueError for it.
Does NOT check that a block name is unique. That check needs the comments of the
other addresses. Use is_block_name_available in blocks.py for it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comment
|
str
|
The comment to validate |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, str]
|
Tuple of (is_valid, error_message) - error_message is "" if valid |
pyclickplc.validate_initial_value ¶
Validate an initial value against the data type rules.
A value of any type but Text is invalid if it starts or ends with a space, tab or other character up to 0x20. CLICK's import refuses such a value if it is quoted, and strips the character if the value is unquoted. A Text value may be a space or a tab.
A Text value may be any one character that cp1252 has, such as é or €.
validate_nickname and validate_comment use the same rule.
first_non_cp1252_char returns the first character of a value that cp1252 does not have.
A Text value that is a line feed or the control character 1Ah is invalid, because CLICK
cannot open a saved project that holds it. initial_value_warning returns a warning for
a valid Text value that a CLICK PLC may load as another character. It also returns one for
a carriage return. CLICK's nickname import refuses a row that holds one.
Python's int() and float() accept some INT, INT2, FLOAT and HEX forms that
CLICK's import refuses. This function rejects them. They are a non-ASCII character (an
Arabic-Indic or fullwidth digit, a no-break space), an underscore (1_000) and a
0x prefix on a hex value. CLICK accepts +5. For a float it also accepts 1e3
and .5.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_value
|
str
|
The initial value string to validate |
required |
data_type
|
int
|
The DataType number (0=bit, 1=int, 2=int2, 3=float, 4=hex, 6=txt) |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, str]
|
Tuple of (is_valid, error_message) - error_message is "" if valid |
pyclickplc.initial_value_warning ¶
Return a warning for a Text initial value that may not reach a CLICK PLC as written, or "".
Only a Text value can get a warning. Call validate_initial_value first. If it rejects
the value, do not rely on the result of this function.
A CLICK PLC loads a Text initial value as the low byte of the character's code point. For
the 27 characters that cp1252 maps above U+00FF, that byte is not the character's cp1252
byte. So the PLC starts € (U+20AC) as the byte 0xAC, which cp1252 reads as ¬. A
CLICK C2-03CPU was observed doing this whether the value came through CLICK's nickname
import or was written straight into the project's database.
This function returns "" for a control character below 0x20 other than a carriage return.
validate_initial_value rejects a line feed and 1Ah. For each other control character,
the PLC was observed to start the address with the character itself, both when the value
was written straight into the project's database and when write_csv wrote it and
CLICK's nickname import read the file. write_csv quotes the value. The import stores no
value for an unquoted cell that holds one control character, as CLICK's own export writes
it. No one has loaded 00h through the import.
validate_initial_value accepts a carriage return. If it is written straight into the
project's database, the PLC was observed to start the address with 0Dh. CLICK's nickname
import refuses a row that holds one, nickname and comment included. So this function warns
about it, and format_csv and write_csv refuse it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_value
|
str
|
The initial value string, as |
required |
data_type
|
int
|
The DataType number (0=bit, 1=int, 2=int2, 3=float, 4=hex, 6=txt) |
required |
Returns:
| Type | Description |
|---|---|
str
|
The warning, or "" if the value reaches the PLC as written |
pyclickplc.validate_click_name ¶
Validate a PLC or DataView name.
Leading and trailing whitespace is ignored. What remains must be 1 to 24 letters, digits, spaces, underscores and hyphens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to validate |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, str]
|
Tuple of (is_valid, error_message) - error_message is "" if valid |