### setup Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Sets up the pyzkaccess environment, checking OS settings and PULL SDK installation. ```APIDOC ## setup ### Description Convenience command to setup the pyzkaccess running environment. This command checks the OS settings and the PULL SDK installation status (and suggests to download and install it if not found). It is recommended to run this command before using other commands. ### Parameters #### Path Parameters - **yes** (bool) - Optional - assume yes for all questions. Default is False - **path** (str) - Optional - URL, path to zip or path to directory with PULL SDK dll files. ``` -------------------------------- ### Setup Environment Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html The `setup` command helps in setting up the pyzkaccess running environment by checking OS settings and PULL SDK installation status. ```APIDOC ## setup ### Description Convenience command to set up the pyzkaccess running environment. It checks OS settings and PULL SDK installation status, suggesting installation if needed. Recommended to run before other commands. ### Method `setup(*, yes: bool = False, path: str = None) -> None` ### Parameters #### Keyword Arguments - **`yes`** (bool): Assume yes for all questions. Defaults to `False`. - **`path`** (str): URL, path to zip, or path to directory containing PULL SDK dll files. Defaults to `None`. ``` -------------------------------- ### Setup pyzkaccess with Wine (*nix) Source: https://bdragon300.github.io/pyzkaccess Run the setup command using Wine to install the PULL SDK for pyzkaccess on *nix systems. ```bash wine pyzkaccess.exe setup ``` -------------------------------- ### Run pyzkaccess setup command Source: https://bdragon300.github.io/pyzkaccess Execute the pyzkaccess setup command to install the PULL SDK and follow the on-screen instructions. ```bash pyzkaccess setup ``` -------------------------------- ### CLI Setup Method Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Provides a convenience command to set up the pyzkaccess environment by checking OS settings and PULL SDK installation status. It's recommended to run this before other commands. ```python def setup(self, *, yes: bool = False, path: str = None) -> None: """Convenience command to setup the pyzkaccess running environment. This command checks the OS settings and the PULL SDK installation status (and suggests to download and install it if not found). It is recommended to run this command before using other commands. Args: yes (bool): assume yes for all questions. Default is False path (str): URL, path to zip or path to directory with PULL SDK dll files. """ sys.stdout.write("Setting up the environment...\n") setup(not yes, path) ``` -------------------------------- ### Setup pyzkaccess Environment Source: https://bdragon300.github.io/pyzkaccess Run this command to set up the pyzkaccess environment and install the PULL SDK. ```bash pyzkaccess setup ``` -------------------------------- ### Setup pyzkaccess Environment Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html A convenience command to set up the pyzkaccess environment. It checks OS settings and PULL SDK installation status, offering to download and install the SDK if not found. It's recommended to run this before other commands. The 'yes' flag bypasses prompts, and 'path' can specify the SDK location. ```python def setup(self, *, yes: bool = False, path: str = None) ‑> None ``` -------------------------------- ### Install Wine for *nix Systems Source: https://bdragon300.github.io/pyzkaccess Install the 32-bit Wine environment on Debian/Ubuntu systems to run the Windows executable. ```bash apt-get install wine wine32 ``` -------------------------------- ### Install pyzkaccess library Source: https://bdragon300.github.io/pyzkaccess Install the pyzkaccess library using pip. Ensure you have a 32-bit Python version for Windows. ```bash pip install pyzkaccess ``` -------------------------------- ### Install pyzkaccess via Pip (Windows) Source: https://bdragon300.github.io/pyzkaccess Install the pyzkaccess library using pip. Ensure you have a 32-bit Python version for Windows installed and added to your PATH. ```bash pip install pyzkaccess ``` -------------------------------- ### PyZKAccess CLI Usage Examples Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Demonstrates typical usage patterns for the pyzkaccess command-line interface, including connecting to devices and accessing help. ```bash pyzkaccess connect [args] [ [args]...] ``` ```bash pyzkaccess [parameters] ``` ```bash pyzkaccess connect --help ``` ```bash pyzkaccess connect 192.168.1.201 table User where --help ``` -------------------------------- ### Get All Device Parameters Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Retrieve all device parameters along with their current values. ```bash Get all device parameters with values: $ ... parameters ``` -------------------------------- ### Example: Poll events of a reader on a door Source: https://bdragon300.github.io/pyzkaccess Demonstrates how to connect to a device and poll events from a specific reader on a door using the command-line interface. ```bash $ pyzkaccess connect 192.168.0.201 doors select 1 readers select 1 events poll ``` -------------------------------- ### EventLog Live Polling Example Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/event.html Shows a convenient way to get new events in live mode using the poll() method. This example continuously prints new events as they arrive or exits after a timeout if no new events occur. It's useful for real-time event display. ```python import threading from pyzkaccess import ZKAccess connstr = 'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=' zk = ZKAccess(connstr=connstr) # Print new events in live mode (or exit after 60 seconds if nothing appeared since last poll) while events := zk.events.poll(): for event in events: print(event) ``` -------------------------------- ### Quick start with ZKAccess library Source: https://bdragon300.github.io/pyzkaccess Initialize ZKAccess with a connection string, retrieve device parameters like serial number and IP address, control relays, and wait for card events. ```python from pyzkaccess import ZKAccess connstr = 'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=' zk = ZKAccess(connstr=connstr) print('Device SN:', zk.parameters.serial_number, 'IP:', zk.parameters.ip_address) # Turn on relays in "lock" group for 5 seconds zk.relays.lock.switch_on(5) # Wait for any card will appear on reader of Door 1 card = None while not card: for door1_event in zk.doors[0].events.poll(timeout=60): print(door1_event) if door1_event.card and door1_event.card != '0': print('Got card #', door1_event.card) card = door1_event.card # Switch on both relays on door 1 zk.doors[0].relays.switch_on(5) # After that restart a device zk.restart() zk.disconnect() ``` -------------------------------- ### QuerySet Initialization Example Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/device_data/queryset.html Demonstrates how to initialize a QuerySet object. Typically, this is done via the `table` method of the ZKAccess object rather than direct instantiation. ```python class QuerySet(Generic[_ModelT]): """Interface to make queries to data tables, iterate over results and write the data to tables QuerySet follows the "fluent interface" pattern in most of its methods. This means you can chain them together in a single line of code. Example:: records = zk.table('User').where(card='123456').only_fields('card', 'password').unread() for record in records: print(record.password) For table and fields you can use either objects or their names. For example, the following is equal to the previous one:: from zkaccess.tables import User records = zk.table(User).where(card='123456').only_fields(User.card, User.password).unread() for record in records: print(record.password) """ _estimate_record_buffer = 256 def __init__(self, sdk: "ZKSDK", table: Type[_ModelT], buffer_size: Optional[int] = None) -> None: """QuerySet constructor. Typically, you don't need to create QuerySet objects manually, but use `table` method of ZKAccess object instead. Args: sdk (ZKSDK): ZKSDK object table (Type[_ModelT]): model class buffer_size (int, optional): size of c-string buffer to keep query results from a device. If omitted, then buffer size will be guessed automatically """ self._sdk = sdk self._table_cls = table self._cache: Optional[List[Mapping[str, str]]] = None self._results_iter: Optional[Iterator[Mapping[str, str]]] = None # Query parameters self._buffer_size = buffer_size self._only_fields: Set[Field] = set() self._filters: MutableMapping[str, str] = {} self._only_unread = False ``` -------------------------------- ### Get Parameters Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Retrieves device parameters with their current values. ```APIDOC ## Get Parameters ### Description Retrieves device parameters with their current values. You can request all parameters or specific ones by name. ### Method GET ### Endpoint `/parameters` ### Parameters #### Query Parameters - **names** (string) - Optional - Comma-separated list of parameter names to request from a device. If omitted, then all parameters will be requested. For example, `--names=param1,param2,param3`. ### Usage Example ```bash $ ... parameters $ ... parameters --names=datetime,ip_address,serial_number ``` ### Response #### Success Response (200) - **parameter_name** (string) - The name of the parameter. - **value** (any) - The current value of the parameter. #### Response Example ```json { "datetime": "2023-10-27 10:00:00", "ip_address": "192.168.1.100", "serial_number": "SN123456789" } ``` ``` -------------------------------- ### Handle Property Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/main.html Get the device handle, which is `None` if there is no active connection. ```APIDOC ## Handle ### Description Returns the device handle. The value is `None` if there is no active connection to the device. This property is read-only. ### Returns - `Optional[int]`: The device handle, or `None` if not connected. ``` -------------------------------- ### Get Specific Device Parameters Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Fetch specific device parameters by name. This can be faster than retrieving all parameters. ```bash Get particular device parameters with values (could be faster than requesting all ones): $ ... parameters --names=datetime,ip_address,serial_number ``` -------------------------------- ### Get All Device Parameters Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Retrieve all device parameters along with their current values. This command fetches all readable parameters by default. ```bash $ ... parameters ``` -------------------------------- ### Get Specific Device Parameters Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Fetch specific device parameters by name. This can be faster than requesting all parameters if you only need a few values. ```bash $ ... parameters --names=datetime,ip_address,serial_number ``` -------------------------------- ### Get and Set Device Parameters with PyZKAccess Source: https://bdragon300.github.io/pyzkaccess Demonstrates how to retrieve and set device-specific parameters like IP address. Use this to configure device settings. The `__doc__` attribute provides a description of the parameter. ```python from pyzkaccess import ZKAccess connstr = 'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=' zK = ZKAccess(connstr=connstr) print(zk.parameters.ip_address) # Get a value zk.parameters.ip_address = "192.168.1.2" # Set a value print(zk.parameters.ip_address.__doc__) # Get description ``` -------------------------------- ### Reading Data - Get All Records Source: https://bdragon300.github.io/pyzkaccess Demonstrates how to retrieve all records from a specified table using the QuerySet. It initializes a ZKAccess connection and then queries the 'User' table. ```APIDOC ## Reading Data - Get All Records ### Description Retrieves all records from a specified table. ### Method `zk.table(model)` followed by iteration. ### Endpoint N/A (SDK method) ### Parameters None ### Request Example ```python from pyzkaccess import ZKAccess zk = ZKAccess('protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=') records = zk.table('User') for record in records: print(record) # prints all users from the table ``` ### Response Iterates over all records in the specified table. ``` -------------------------------- ### Accessing Auxiliary Input Events Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/main.html Demonstrates how to access events from auxiliary inputs on a ZKAccess device. This covers getting events from all inputs, a specific input, or a range of inputs. ```python zk.aux_inputs.events ``` ```python zk.aux_inputs[0].events ``` ```python zk.aux_inputs[:2].events ``` -------------------------------- ### Get User Model Data as Dictionary Source: https://bdragon300.github.io/pyzkaccess Demonstrates how to retrieve all data from a `User` model object as a Python dictionary. This is useful for inspecting the current state of a user record or preparing data for other operations. ```python from pyzkaccess.tables import User my_user = User(card='123456', pin='123', password='555', super_authorize=True) print(my_user.dict) # {'card': '123456', # 'pin': '123', # 'password': '555', # 'group': None, # 'start_time': None, # 'end_time': None, ``` -------------------------------- ### Instantiate a User Model Source: https://bdragon300.github.io/pyzkaccess Example of creating a `User` model object with essential fields like card number, PIN, and password. This is the first step in creating or modifying user records in the device's database. ```python from pyzkaccess.tables import User my_user = User(card='123456', pin='123', password='555', super_authorize=True) # ...code... ``` -------------------------------- ### Connect to device using environment variables Source: https://bdragon300.github.io/pyzkaccess Configure connection parameters like IP address, port, timeout, and password using environment variables when direct command-line arguments are not suitable. ```bash PYZKACCESS_CONNECT_IP or PYZKACCESS_CONNECT_CONNSTR PYZKACCESS_CONNECT_MODEL ``` -------------------------------- ### datetime Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Gets or sets the current date and time of the device. ```APIDOC ## Get/Set datetime ### Description Retrieves or sets the current date and time on the device. ### Method GET/PUT ### Endpoint `/parameters/datetime` ### Parameters #### Request Body (for PUT) - **datetime** (string) - Required - The new date and time in ISO 8601 format (e.g., "YYYY-MM-DDTHH:MM:SS"). ### Request Example (PUT) ```json { "datetime": "2023-10-27T10:30:00" } ``` ### Response #### Success Response (200) - **datetime** (string) - The current date and time in ISO 8601 format. ### Response Example (GET) ```json { "datetime": "2023-10-27T10:30:00" } ``` ``` -------------------------------- ### Get Door Relays Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/door.html Retrieves the RelayList associated with this door. ```python @property def relays(self) -> RelayList: return self._relays ``` -------------------------------- ### Initialize and Use DocDict Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/common.html Demonstrates initializing DocDict with typed values and accessing its docstrings. Values are wrapped in DocValue objects. ```python >>> d = DocDict[int, str]({1: 'Docstring 1', '2': 'Docstring 2'}) >>> print(repr(d[1]), repr(d['2'])) 1 '2' >>> print(type(d[1]), type(d['2'])) >>> print(d[1] == 1) True >>> print(d['2'] == '2') True >>> print(isinstance(d[1], int), isinstance(d['2'], str)) True True >>> print(d[1].__doc__, ',', d['2'].__doc__) Docstring 1 , Docstring 2 ``` -------------------------------- ### Using a specific device model Source: https://bdragon300.github.io/pyzkaccess Demonstrates how to initialize ZKAccess with a specific device model, such as ZK200, and access device parameters like IP address. ```APIDOC ## Using a certain device model _Default device model is`ZK400` (C3-400)._ ```python from pyzkaccess import ZKAccess, ZK200 connstr = 'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=' with ZKAccess(connstr=connstr, device_model=ZK200) as zk: print(zk.parameters.ip_address) ``` ``` -------------------------------- ### Device Property Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/main.html Get the current ZKDevice object that the SDK is connected with. ```APIDOC ## Device ### Description Returns the current `ZKDevice` object representing the device the SDK is connected to. This property is read-only. ### Raises - `RuntimeError`: If attempting to create the device object while not connected to the SDK. ### Returns - `ZKDevice`: The current device object. ``` -------------------------------- ### Get Door Parameters Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/door.html Retrieves the DoorParameters object related to this door. ```python @property def parameters(self) -> DoorParameters: """Device parameters related to this door""" return self._parameters ``` -------------------------------- ### Initialize ZKDevice with Raw String Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/device.html Create a ZKDevice object by passing a raw device string containing device attributes. ```python ZKDevice( "MAC=00:17:61:C8:EC:17,IP=192.168.1.201,SN=DGD9190019050335134,\n Device=C3-400,Ver=AC Ver 4.3.4 Apr 28 2017" ) ``` -------------------------------- ### Get Door Reader Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/door.html Retrieves the Reader object associated with this door. ```python @property def reader(self) -> Reader: """Reader that belongs to this door""" return self._reader ``` -------------------------------- ### Initialize ZKDevice with Attributes Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/device.html Create a ZKDevice object by passing device attributes as keyword arguments. ```python ZKDevice( mac="00:17:61:C8:EC:17", ip="192.168.1.201", serial_number="DGD9190019050335134", model=ZK400, version="AC Ver 4.3.4 Apr 28 2017" ) ``` -------------------------------- ### Get Door Auxiliary Input Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/door.html Retrieves the AuxInput object associated with this door. ```python @property def aux_input(self) -> AuxInput: """Aux input that belongs to this door""" return self._aux_input ``` -------------------------------- ### display_daylight_saving Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Gets or sets the display parameters for daylight saving time. This is a read-write property. ```APIDOC ## Get/Set display_daylight_saving ### Description Retrieves or sets the display parameters related to daylight saving time. ### Method GET/PUT ### Endpoint `/parameters/display_daylight_saving` ### Parameters #### Request Body (for PUT) - **display_daylight_saving** (any) - Required - The parameters to configure the daylight saving display. ### Request Example (PUT) ```json { "display_daylight_saving": { "enabled": true, "start_time": "02:00", "end_time": "02:00" } } ``` ### Response #### Success Response (200) - **display_daylight_saving** (any) - The current daylight saving display parameters. ### Response Example (GET) ```json { "display_daylight_saving": { "enabled": true, "start_time": "02:00", "end_time": "02:00" } } ``` ``` -------------------------------- ### Connect to a device using IP address Source: https://bdragon300.github.io/pyzkaccess Establish a connection to a ZKTeco device by providing its IP address to the connect command. ```bash pyzkaccess connect 192.168.1.201 ``` -------------------------------- ### List All Device Parameter Names Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html This command lists all available parameter names for the device. ```bash List all device parameter names: $ ... parameters list ``` -------------------------------- ### Getting the Number of Events Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/event.html Provides the total count of events, considering any active filters. ```APIDOC ## __len__ (Length) ### Description Returns the total number of events, taking into account any active filters. ### Signature def __len__(self) -> int: ### Returns - int - The total count of events. ``` -------------------------------- ### communication_password Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Gets or sets the password required to connect to the device. The password can be up to 15 characters long. ```APIDOC ## Get/Set communication_password ### Description Retrieves or sets the password for device communication. Maximum length is 15 symbols. ### Method GET/PUT ### Endpoint `/parameters/communication_password` ### Parameters #### Request Body (for PUT) - **communication_password** (string) - Required - The password for device communication. ### Request Example (PUT) ```json { "communication_password": "new_secret_password" } ``` ### Response #### Success Response (200) - **communication_password** (string) - The current communication password. ### Response Example (GET) ```json { "communication_password": "current_password" } ``` ``` -------------------------------- ### Get Combined Readers from DoorList Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/door.html Aggregates and returns a ReaderList containing all readers from all doors in the DoorList. ```python @property def readers(self) -> ReaderList: """Readers that belong to this door""" readers = [x.reader for x in self] return ReaderList(self._sdk, event_log=self._event_log, readers=readers) ``` -------------------------------- ### Initialize ZKAccess and Read All Users Source: https://bdragon300.github.io/pyzkaccess Connect to a ZKAccess device using TCP protocol and retrieve all user records from the 'User' table. This demonstrates basic connection and iteration over records. ```python from pyzkaccess import ZKAccess zk = ZKAccess('protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=') records = zk.table('User') for record in records: print(record) # prints all users from the table ``` -------------------------------- ### Get Combined Relays from DoorList Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/door.html Aggregates and returns a RelayList containing all relays from all doors in the DoorList. ```python @property def relays(self) -> RelayList: """Relays that belong to this doors""" relays = [relay for door in self for relay in door.relays] return RelayList(self._sdk, relays=relays) ``` -------------------------------- ### Search for devices and connect Source: https://bdragon300.github.io/pyzkaccess Discover devices on the local network using search_devices and connect to the first found device. The connection is managed using a context manager. ```python from pyzkaccess import ZKAccess found = ZKAccess.search_devices('192.168.1.255') print(len(found), 'devices found') if found: # Pick the first device device = found[0] with ZKAccess(device=device) as zk: print(zk.parameters.ip_address) ``` -------------------------------- ### CLI Initialization and Global Arguments Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html The CLI class handles initialization and global arguments like format, file, and dllpath. It sets up the environment for subsequent commands. ```APIDOC ## CLI Class ### Description Provides a command-line interface for PyZKAccess. It handles global arguments and initializes the connection parameters. ### Methods #### `__init__(self)` Initializes the CLI instance by calling `__call__`. #### `__call__(self, *, format: str = "ascii_table", file: str = None, dllpath: str = "plcommpro.dll")` Sets up global options for the CLI, including I/O format, file redirection, and the path to the PULL SDK DLL. It validates the format and directory for file operations. ### Global Arguments - **`format`** (str): Specifies the input/output format. Possible values are: `ascii_table`, `csv`. Defaults to `ascii_table`. - **`file`** (str): Path to a file for reading and writing data instead of stdin/stdout. Defaults to `None`. - **`dllpath`** (str): Path to the PULL SDK DLL file. Defaults to `"plcommpro.dll"`. ``` -------------------------------- ### Initialize ZKSDK Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/sdk.html Initializes the ZKSDK by loading the specified DLL. Ensure the DLL path is correct. ```python class ZKSDK: """This is machinery class which directly calls SDK functions. This is a wrapper around DLL functions of SDK, it incapsulates working with ctypes, handles errors and holds connection info. """ def __init__(self, dllpath: str) -> None: """ZKSDK constructor Args: dllpath (str): path to a DLL file. E.g. "plcommpro.dll" """ self.handle: Optional[int] = None self.dll = ctypes.WinDLL(dllpath) ``` -------------------------------- ### backup_hour Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Gets or sets the hour for the backup SD card operation. Accepts values from 1 to 24. ```APIDOC ## Get/Set backup_hour ### Description Retrieves or sets the hour (1-24) for the device's SD card backup operation. ### Method GET/PUT ### Endpoint `/parameters/backup_hour` ### Parameters #### Request Body (for PUT) - **backup_hour** (int) - Required - The hour (1-24) for the backup. ### Request Example (PUT) ```json { "backup_hour": 3 } ``` ### Response #### Success Response (200) - **backup_hour** (int) - The current backup hour setting. ### Response Example (GET) ```json { "backup_hour": 3 } ``` ``` -------------------------------- ### Initialize Door Object Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/door.html Used to create a Door instance. Requires SDK, event log, door number, relays, reader, auxiliary input, and door parameters. ```python class Door(DoorInterface): """A door""" def __init__( self, sdk: ZKSDK, event_log: EventLog, number: int, relays: RelayList, reader: Reader, aux_input: AuxInput, parameters: DoorParameters, ) -> None: self.number = number self._sdk = sdk self._event_log = event_log self._relays = relays self._reader = reader self._aux_input = aux_input self._parameters = parameters ``` -------------------------------- ### Datetime Parameter Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Allows getting and setting the current datetime of the device. The datetime is converted to and from the ZKTime format. ```APIDOC ## Datetime Property ### Description Represents the current datetime of the device. It can be read from the device or set to a new value. The library handles the conversion between Python's `datetime` object and the device's ZKTime format. ### Method `property` ### Parameters #### Get None #### Set - **value** (`datetime.datetime`) - Required - The new datetime to set for the device. ### Request Example (Setting Datetime) ```python from datetime import datetime # Assuming 'device' is an instance of your SDK class device.datetime = datetime(2023, 10, 27, 10, 30, 0) ``` ### Response (Getting Datetime) - **datetime** (`datetime.datetime`) - The current datetime of the device. ### Response Example (Getting Datetime) ```python current_time = device.datetime print(current_time) ``` ``` -------------------------------- ### Access Device Object Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/main.html Get the current ZKDevice object that the SDK is connected to. Raises a RuntimeError if the device is not connected. ```python zk.device ``` -------------------------------- ### List All Door Parameter Names Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Use this command to list all available parameter names for a specific door. Ensure you specify the door number. ```bash $ ... doors --numbers=1 parameters list ``` -------------------------------- ### Get Combined Auxiliary Inputs from DoorList Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/door.html Aggregates and returns an AuxInputList containing all auxiliary inputs from all doors in the DoorList. ```python @property def aux_inputs(self) -> AuxInputList: """Aux inputs that belong to this door""" aux_inputs = [x.aux_input for x in self] return AuxInputList(self._sdk, event_log=self._event_log, aux_inputs=aux_inputs) ``` -------------------------------- ### Count Table Records Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Get the total count of records in a table. This operation is efficient as it uses a dedicated SDK call. ```bash $ ... table User count ``` -------------------------------- ### List Door Parameter Names Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Use this command to list all available parameter names for doors. Specify door numbers if needed. ```bash List all door parameter names: $ ... doors --numbers=1 parameters list ``` -------------------------------- ### Connect to Device Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/main.html Establishes a connection to a device using a provided connection string. Ensure the connection string format is correct. ```python def connect(self, connstr: str) -> None: """Connect to a device using a connection string, ex: 'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd='" """Args: **`connstr`**: `str` device connection string """ ``` -------------------------------- ### ZKSDK Constructor Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/sdk.html Initializes the ZKSDK by loading the specified DLL and setting up the connection handle. ```APIDOC ## ZKSDK(dllpath: str) ### Description Initializes the ZKSDK by loading the specified DLL and setting up the connection handle. ### Parameters #### Path Parameters - **dllpath** (str) - Required - path to a DLL file. E.g. "plcommpro.dll" ### Returns - **ZKSDK** - An instance of the ZKSDK class. ``` -------------------------------- ### Interlock Rule Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Get or set the interlock rule for doors. This mode ensures that one door must be closed before the other can be opened. ```APIDOC ## Interlock Rule ### Description Get or set the interlock rule for doors. This mode ensures that one door must be closed before the other can be opened. ### Method GET / SET ### Parameters #### Get None #### Set - **value** (int) - Required - The interlock rule to set. Must be a valid rule for the device model. ### Request Example (Get) ```python rule = zk.parameters.interlock ``` ### Response Example (Get) ```python # Example output if rule is 0 0 ``` ### Request Example (Set) ```python zk.parameters.interlock = 1 ``` ### Response Example (Set) None ``` -------------------------------- ### Connect to Device Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html The `connect` command establishes a connection to a ZKAccess device using its IP address and model information. ```APIDOC ## connect ### Description Connects to a device using its IP address. The IP can be an IPv4 address or "ENV" to use environment variables for connection details. It also allows specifying the device model. ### Method `connect(ip: str, *, model: str = "ZK400") -> ZKCommand` ### Parameters #### Path Parameters - **`ip`** (str): IPv4 address of the device or "ENV" to use environment variables. #### Keyword Arguments - **`model`** (str): Device model. Possible values are: `ZK100`, `ZK200`, `ZK400`. Defaults to `"ZK400"`. ### Environment Variables for Connection - `PYZKACCESS_CONNECT_IP` or `PYZKACCESS_CONNECT_CONNSTR`: IPv4 address or the full connection string. Example connection string: `'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd='` - `PYZKACCESS_CONNECT_MODEL`: Device model. Possible values: `ZK100`, `ZK200`, `ZK400`. ``` -------------------------------- ### Get Fingerprint Version Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Retrieves the ZK fingerprint version from device parameters. Raises a ValueError if the version is not 9 or 10. ```python str_res = params["~ZKFPVersion"] if str_res == "": return 0 int_res = int(str_res) if int_res not in (9, 10): raise ValueError(f"Fingerprint version must be 9 or 10, got: {int_res}") return int_res ``` -------------------------------- ### Initialize ZKAccess Device Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/main.html Initializes the ZKAccess class, optionally connecting to a device via a connection string or a ZKDevice object. It configures the SDK and sets up event logging. Raises ZKSDKError on connection issues. ```python class ZKAccess: """ZKAccess device, the main class to work with ZKAccess devices. Makes connection to a device, provides access to its data tables, doors, readers, relays, aux inputs, and events.""" buffer_size: ClassVar[int] = 4096 """Size in bytes of underlying buffer for text results of PULL SDK functions""" query_buffer_size: ClassVar[Optional[int]] = None """Size in bytes of underlying buffer for data table query results. If None then the size will be guessed automatically. """ queryset_class: ClassVar[Type[QuerySet]] = QuerySet def __init__( self, connstr: Optional[str] = None, device: Optional[ZKDevice] = None, device_model: Type[ZKModel] = ZK400, dllpath: str = "plcommpro.dll", log_capacity: Optional[int] = None, ): """ZKAccess constructor Args: connstr (str, optional): Connection string. If given then we try to connect automatically to a device. Ex: 'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=' device (ZKDevice, optional): ZKDevice object to connect to. If given then we try to connect automatically to a device device_model (Type[ZKModel], default=ZK400): Device model. dllpath (str, default=plcommpro.dll): Full path to plcommpro.dll log_capacity (int, optional): Mixumum capacity of events log. By default size is not limited Raises: ZKSDKError: On connection error """ self.connstr = connstr self.device_model = device_model self.sdk = pyzkaccess.sdk.ZKSDK(dllpath) self._device = device self._event_log = EventLog(self.sdk, self.buffer_size, maxlen=log_capacity) if device: if not connstr: self.connstr = f"protocol=TCP,ipaddress={device.ip},port=4370,timeout=4000,passwd=" if not device_model: self.device_model = device.model if self.connstr: self.connect(self.connstr) ``` -------------------------------- ### Search Devices with Wine (*nix) Source: https://bdragon300.github.io/pyzkaccess Use Wine to execute the pyzkaccess search_devices command on *nix systems to find active C3 devices. ```bash wine pyzkaccess.exe search_devices ``` -------------------------------- ### Change IP settings Source: https://bdragon300.github.io/pyzkaccess Provides examples for changing the IP address, gateway IP address, and netmask of the ZKAccess device. ```APIDOC ## Change IP settings ```python from pyzkaccess import ZKAccess connstr = 'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=' with ZKAccess(connstr=connstr) as zk: zk.parameters.gateway_ip_address = '172.31.255.254' zk.parameters.netmask = '255.240.0.0' zk.parameters.ip_address = '172.17.10.2' ``` ``` -------------------------------- ### Initialize DoorList Object Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/door.html Creates a DoorList instance to manage a collection of doors for group operations. Requires SDK, event log, and an iterable of Door objects. ```python class DoorList(DoorInterface, UserTuple[Door]): """Door collection for group operations""" def __init__(self, sdk: ZKSDK, event_log: EventLog, doors: Iterable[Door]) -> None: super().__init__(doors) self._sdk = sdk self._event_log = event_log ``` -------------------------------- ### daylight_saving_mode Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Gets or sets the daylight saving mode for the device. Available values are 0 (mode 1) and 1 (mode 2). ```APIDOC ## Get/Set daylight_saving_mode ### Description Retrieves or sets the daylight saving mode. Available values: 0 (mode 1), 1 (mode 2). ### Method GET/PUT ### Endpoint `/parameters/daylight_saving_mode` ### Parameters #### Request Body (for PUT) - **daylight_saving_mode** (int) - Required - The daylight saving mode (0 or 1). ### Request Example (PUT) ```json { "daylight_saving_mode": 1 } ``` ### Response #### Success Response (200) - **daylight_saving_mode** (int) - The current daylight saving mode. ### Response Example (GET) ```json { "daylight_saving_mode": 0 } ``` ``` -------------------------------- ### Get Anti-Passback Rule Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Retrieves the anti-passback rule for doors. Validates the retrieved value against the device model's supported rules. ```python params = self._sdk.get_device_param(parameters=("AntiPassback",), buffer_size=self.buffer_size) int_res = int(params["AntiPassback"]) if int_res not in self.device_model.anti_passback_rules: raise ValueError( f"Value {int_res} not in possible values for {self.device_model.name}: " f"{self.device_model.anti_passback_rules.keys()}" ) return self.device_model.anti_passback_rules[int_res] ``` -------------------------------- ### Restart Device Method Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Restart the ZKAccess device. ```python def restart(self) """Restart a device.""" ``` -------------------------------- ### ZKAccess Constructor Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/main.html Initializes the ZKAccess class, establishing a connection to a ZKAccess device. It supports automatic connection via a connection string or a provided ZKDevice object. ```APIDOC ## ZKAccess Constructor ### Description Initializes the ZKAccess class, establishing a connection to a ZKAccess device. It supports automatic connection via a connection string or a provided ZKDevice object. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **connstr** (Optional[str]): Connection string for automatic connection. Example: 'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=' - **device** (Optional[ZKDevice]): A ZKDevice object to connect to. - **device_model** (Type[ZKModel], default=ZK400): The model of the ZKAccess device. - **dllpath** (str, default='plcommpro.dll'): The full path to the plcommpro.dll library. - **log_capacity** (Optional[int]): The maximum capacity of the events log. If None, the size is not limited. ### Raises - ZKSDKError: Raised on connection errors. ``` -------------------------------- ### Get All Auxiliary Input Events Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/main.html Retrieves events from all auxiliary inputs available on a device. This is the default behavior when accessing the aux_inputs property. ```python zk.aux_inputs.events ``` -------------------------------- ### Get Immutable Data Tuple Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/common.html Accesses the internal tuple containing the data. This property provides read-only access to the stored elements. ```python @property def data(self) -> Tuple[_DataT, ...]: return self._data ``` -------------------------------- ### Parameters List Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Lists all available parameter names for a device or door. ```APIDOC ## Parameters List ### Description Lists all available parameter names for a device or door. ### Method GET (Implicit) ### Endpoint `/parameters list` ### Usage Example ```bash $ ... parameters list ``` ### Parameters This command does not take any specific parameters for listing all available parameter names. ``` -------------------------------- ### Interlock Rule Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Get the interlock rule for doors. This determines the mode when opening the second door is dependent on the first door's state. ```APIDOC ## Get Interlock Rule ### Description Retrieves the current interlock rule for doors. This setting controls the sequence required for opening successive doors. ### Method GET ### Endpoint `/parameters/interlock` ### Response #### Success Response (200) - **interlock** (int) - The current interlock rule code. Refer to device-specific documentation for rule meanings. ``` -------------------------------- ### Set Device Parameters Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html Set one or more device parameters. Provide the parameter names and their new values. ```bash Set device parameters: $ ... parameters set --datetime="2021-05-08 00:04:00" --ip_address="192.168.128.1" ``` -------------------------------- ### Anti-Passback Rule Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Get or set the anti-passback rule for doors. This rule determines how access is managed between two doors to prevent unauthorized entry. ```APIDOC ## Anti-Passback Rule ### Description Get or set the anti-passback rule for doors. This rule determines how access is managed between two doors to prevent unauthorized entry. ### Method GET / SET ### Parameters #### Get None #### Set - **value** (int) - Required - The anti-passback rule to set. Must be a valid rule for the device model. ### Request Example (Get) ```python rule = zk.parameters.anti_passback_rule ``` ### Response Example (Get) ```python # Example output if rule is 0 0 ``` ### Request Example (Set) ```python zk.parameters.anti_passback_rule = 1 ``` ### Response Example (Set) None ``` -------------------------------- ### connect Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/sdk.html Establishes a connection to a ZK device using the provided connection string. ```APIDOC ## connect(connstr: str) ### Description Connect to a device. ### Method Connect() ### Parameters #### Path Parameters - **connstr** (str) - Required - connection string, see docs ### Raises - **ZKSDKError**: If the connection fails. ``` -------------------------------- ### Get Interlock Rule Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/param.html Retrieves the interlock rule for doors. Handles cases where the parameter might be empty and validates against device model rules. ```python res = self._sdk.get_device_param(parameters=("InterLock",), buffer_size=self.buffer_size) if not res: return self.device_model.interlock_rules[0] int_res = int(res["InterLock"]) if int_res not in self.device_model.interlock_rules: raise ValueError( f"Value {int_res} not in possible values for {self.device_model.name}: " f"{self.device_model.interlock_rules.keys()}" ) return self.device_model.interlock_rules[int_res] ``` -------------------------------- ### ZKAccess Constructor Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/main.html Initializes a ZKAccess device object. It can establish a connection automatically if a connection string or ZKDevice object is provided. ```APIDOC ## Class: ZKAccess ### Description ZKAccess device, the main class to work with ZKAccess devices. Makes connection to a device, provides access to its data tables, doors, readers, relays, aux inputs, and events. ### Constructor Signature `ZKAccess(connstr: Optional[str] = None, device: Optional[ZKDevice] = None, device_model: Type[ZKModel] = pyzkaccess.device.ZK400, dllpath: str = 'plcommpro.dll', log_capacity: Optional[int] = None)` ### Parameters #### `connstr` (str, optional) Connection string. If given then we try to connect automatically to a device. Ex: 'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=' #### `device` (ZKDevice, optional) ZKDevice object to connect to. If given then we try to connect automatically to a device. #### `device_model` (Type[ZKModel], optional, default=`ZK400`) Device model. #### `dllpath` (str, optional, default=`plcommpro.dll`) Full path to plcommpro.dll. #### `log_capacity` (int, optional) Maximum capacity of events log. By default, the size is not limited. ``` -------------------------------- ### Get Device Handle Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/main.html Retrieve the device handle, which is an integer representing an active connection. Returns None if no connection is active. This property is read-only. ```python zk.handle ``` -------------------------------- ### Use ZKAccess as a context manager Source: https://bdragon300.github.io/pyzkaccess Manage the connection to a ZKTeco device using a 'with' statement, ensuring the connection is properly opened and closed. ```python from pyzkaccess import ZKAccess connstr = 'protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=' with ZKAccess(connstr=connstr) as zk: print(zk.parameters.ip_address) ``` -------------------------------- ### List All Device Parameter Names Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/cli.html This command retrieves a list of all readable parameter names for the device. No specific parameters are required. ```bash $ ... parameters list ``` -------------------------------- ### EventLog.poll() Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/event.html Retrieves new events from the device in a live mode. This is a more convenient way to get events compared to manually calling refresh in a loop. ```APIDOC def poll(self) -> List[Event]: """Poll for new events from the device. Returns: List[Event]: list of new events """ # ZKAccess always returns single event with code 255 # on every log query if no other events occured. So, skip it new_events = [e for e in self._pull_events() if e.event_type != 255] self.data.extend(new_events) return [e for e in new_events if self._is_filtered(e)] ``` -------------------------------- ### Set Device Parameters (Python) Source: https://bdragon300.github.io/pyzkaccess/pyzkaccess/sdk.html Sets parameters on a ZK device. Sends parameters in batches of 20 due to device limitations. Raises ZKSDKError on SDK failure. ```python if not parameters: return # Device can accept maximum 20 parameters for one call. See SDK # docs. So send them in loop by bunches of 20 items keys = list(sorted(parameters.keys())) while keys: query_keys = keys[:20] query = ",".join(f"{k}={parameters[k]}" for k in query_keys).encode() del keys[:20] err = self.dll.SetDeviceParam(self.handle, query) if err < 0: raise ZKSDKError("SetDeviceParam failed", err) ```