Files API¶
Tier: Stable Core
Nickname CSV, DataView CDV, PLC data, installed modules, and channel parameters.
pyclickplc.read_csv ¶
Read a user-format CSV file into AddressRecords.
The user CSV has columns: Address, Data Type, Nickname, Initial Value, Retentive, Address Comment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the CSV file. |
required |
Returns:
| Type | Description |
|---|---|
AddressRecordMap
|
AddressRecordMap keyed by addr_key (int) with |
pyclickplc.write_csv ¶
write_csv(
path: str | Path,
records: Mapping[int, AddressRecord]
| Iterable[AddressRecord],
) -> int
Write AddressRecords to a user-format CSV file.
Only records with content (nickname, comment, non-default initial value or retentive) are written. Records are sorted by memory type order then address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to write the CSV file. |
required |
records
|
Mapping[int, AddressRecord] | Iterable[AddressRecord]
|
Address records to write. Accepts a mapping keyed by addr_key or any iterable of AddressRecord values. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of rows written. |
pyclickplc.AddressRecordMap ¶
pyclickplc.make_address_record ¶
make_address_record(
address: str,
*,
nickname: str = "",
comment: str = "",
initial_value: str = "",
retentive: bool | None = None,
used: bool | None = None,
) -> AddressRecord
Create an AddressRecord from a display address with inferred defaults.
pyclickplc.read_cdv ¶
Read a CDV file into a DataViewFile model.
pyclickplc.write_cdv ¶
Write a DataViewFile or list of DataViewRecords to a CDV path.
pyclickplc.verify_cdv ¶
verify_cdv(
path: Path | str,
rows: list[DataViewRecord],
has_new_values: bool | None = None,
) -> list[str]
Verify in-memory rows against a CDV file using native value comparison.
pyclickplc.check_cdv_file ¶
Validate a single CDV file and return issue strings.
pyclickplc.DataViewFile
dataclass
¶
CDV file model with row data in native Python types.
value_to_display
staticmethod
¶
Render a native value as a display string.
validate_display
staticmethod
¶
Validate display text for a target data type.
try_parse_display
staticmethod
¶
Parse a display string to a native value without raising.
validate_row_display
staticmethod
¶
Validate a user edit for a specific row.
set_row_new_value_from_display
staticmethod
¶
Strictly set a row's native new_value from a display string.
load
classmethod
¶
Load a CDV file and parse new values into native Python types.
save ¶
Save CDV back to disk, converting native values at the file boundary.
verify ¶
Compare this in-memory dataview to a CDV file on disk.
pyclickplc.DataViewRecord
dataclass
¶
Represents a single row in a CLICK DataView.
A dataview row contains an address to monitor and optionally a new value
to write to that address. The nickname and comment are display-only
fields populated from SharedAddressData.
For user-facing creation from display addresses, prefer
make_dataview_record(...).
memory_type
property
¶
Get the memory type prefix (X, Y, DS, etc.) or None if invalid.
address_number
property
¶
Get the address number as a display string, or None if invalid.
from_address
classmethod
¶
Build a DataViewRecord from a display address string.
update_data_type ¶
Update the DataType based on the current address.
Returns:
| Type | Description |
|---|---|
bool
|
True if data_type was updated, False if address is invalid. |
pyclickplc.make_dataview_record ¶
Create a DataViewRecord from a display address with inferred defaults.
pyclickplc.get_data_type_for_address ¶
Get the DataType for an address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
Address string like "X001", "DS1" |
required |
Returns:
| Type | Description |
|---|---|
DataType | None
|
DataType or None if address is invalid. |
pyclickplc.validate_new_value ¶
Validate a user-entered display string for the New Value column.
pyclickplc.Module
dataclass
¶
Installed module identity and physical I/O counts.
A count of zero means the module has no I/O of that kind. Counts describe hardware capacity, not currently assigned channel addresses.
pyclickplc.Modules
dataclass
¶
Installed CPU, CPU slots 0/1, and expansion positions 1..8.
Empty positions are omitted from the read-only mappings. CPU is None if the project does not identify one. Power supplies are not included.
pyclickplc.read_modules ¶
Read installed hardware and I/O counts without requiring CLICK installed.
CPU slots use keys 0 and 1; expansions use keys 1 through 8. Unpopulated positions and stale CPU slots unsupported by the installed CPU are omitted. Channel parameters are not interpreted, so malformed channel records do not prevent reading the hardware inventory.
Raises OSError for unreadable files and ValueError for malformed INI data, invalid module IDs, or unknown installed hardware. Missing CPU information returns cpu=None; a file without installed modules returns empty mappings.
pyclickplc.ChannelParameters
dataclass
¶
Normalized DF addresses assigned to analog input and output channels.
pyclickplc.read_channel_parameters ¶
Read analog channel assignments for the installed CLICK hardware.
Covers built-in CPU analog channels, expansion positions 1..8, and CLICK PLUS CPU slots 0 and 1. Output addresses are separate from input addresses; scaling and electrical ranges are not interpreted. Empty assignments and settings left behind by removed or non-analog modules are ignored.
Returns empty sets if there are no assigned analog channels. Raises OSError for unreadable files and ValueError for malformed channel data or unknown installed hardware. No CLICK installation is required.
pyclickplc.read_plc_data ¶
read_plc_data(
path: str | Path, *, skip_default: bool = False
) -> dict[str, bool | int | float | str]
Parse a Click PLC 'Read Data from PLC' CSV dump.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the CSV file exported from Click Programming Software via Data > Read Data from PLC > Save to File. |
required |
skip_default
|
bool
|
If True, omit addresses whose value equals the bank
default ( |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, bool | int | float | str]
|
Dict mapping normalised address strings (e.g. |
dict[str, bool | int | float | str]
|
to native Python values ( |
dict[str, bool | int | float | str]
|
|
pyclickplc.write_plc_data ¶
write_plc_data(
path: str | Path,
data: Mapping[str, bool | int | float | str],
*,
banks: Iterable[str] | None = None,
) -> None
Write a Click PLC data CSV that can be loaded via Write Data into PLC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Output file path. |
required |
data
|
Mapping[str, bool | int | float | str]
|
Dict mapping normalised address strings (e.g. |
required |
banks
|
Iterable[str] | None
|
Bank names to include (e.g. |
None
|