Skip to main content

ZK

Struct ZK 

Source
pub struct ZK {
    pub addr: String,
    pub timeout: Duration,
    pub user_packet_size: usize,
    pub encoding: &'static str,
    /* private fields */
}

Fields§

§addr: String§timeout: Duration§user_packet_size: usize§encoding: &'static str

Implementations§

Source§

impl ZK

Source

pub fn new(addr: &str, port: u16) -> Self

Source

pub fn set_password(&mut self, password: u32)

Sets the communication password for the device.

Source

pub fn set_legacy_checksum(&mut self, legacy: bool)

Forces use of the legacy checksum algorithm (Rust bitwise NOT).

By default, rustzk tries the default checksum first and automatically falls back to legacy on timeout. Call this before connect to skip the auto-detection and connect immediately with legacy checksum.

§Known firmware requiring legacy checksum
  • ZAM180_TFT (Ver 6.60 Aug 19 2021)
§Example
use rustzk::{ZK, ZKProtocol};
let mut zk = ZK::new("192.168.1.201", 4370);
zk.set_legacy_checksum(true); // Skip auto-detect, connect faster
zk.connect(ZKProtocol::TCP).unwrap();
Source

pub fn connect(&mut self, protocol: ZKProtocol) -> ZKResult<()>

Connect to the ZK device using the specified protocol. Supports TCP, UDP, or Auto-detection.

Returns an error if already connected. Call disconnect first.

Source

pub fn read_sizes(&mut self) -> ZKResult<()>

Fetches device capacity and usage statistics.

Source

pub fn decode_time(t: &[u8]) -> ZKResult<NaiveDateTime>

Source

pub fn encode_time(t: NaiveDateTime) -> u32

Source

pub fn get_users(&mut self) -> ZKResult<Vec<User>>

Retrieves all users from the device.

Source

pub fn get_attendance(&mut self) -> ZKResult<Vec<Attendance>>

Retrieves all attendance records from the device.

Source

pub fn get_firmware_version(&mut self) -> ZKResult<String>

Source

pub fn get_option_value(&mut self, key: &str) -> ZKResult<String>

Source

pub fn get_serial_number(&mut self) -> ZKResult<String>

Source

pub fn get_platform(&mut self) -> ZKResult<String>

Source

pub fn get_timezone(&mut self) -> ZKResult<i32>

Gets the device timezone adjustment (usually in hours).

Source

pub fn get_mac(&mut self) -> ZKResult<String>

Source

pub fn get_device_name(&mut self) -> ZKResult<String>

Source

pub fn get_face_version(&mut self) -> ZKResult<String>

Source

pub fn get_fp_version(&mut self) -> ZKResult<String>

Source

pub fn get_time(&mut self) -> ZKResult<DateTime<FixedOffset>>

Retrieves the current time from the device.

Note: This returns the time as configured on the device, mapped to the detected timezone offset. If the device time falls into a DST transition gap (non-existent time), this will return an error.

Source

pub fn set_time(&mut self, t: DateTime<FixedOffset>) -> ZKResult<()>

Source

pub fn set_option(&mut self, key: &str, value: &str) -> ZKResult<()>

Sets a device option by key and value.

Source

pub fn change_password(&mut self, new_password: u32) -> ZKResult<()>

Changes the communication password (CommKey) of the device. Note: After changing the password, you must use the new password for future connections.

Source

pub fn restart(&mut self) -> ZKResult<()>

Source

pub fn poweroff(&mut self) -> ZKResult<()>

Source

pub fn unlock(&mut self, seconds: u32) -> ZKResult<()>

Source

pub fn disconnect(&mut self) -> ZKResult<()>

Source

pub fn refresh_data(&mut self) -> ZKResult<()>

Refreshes the device’s internal data.

Source

pub fn set_user(&mut self, user: &User) -> ZKResult<()>

Creates or updates a user on the device. Ensures User ID uniqueness to prevent logic conflicts. Performance Note: This performs an O(N) fetch of all users first. For bulk operations, use set_user_unchecked.

Source

pub fn set_users_bulk(&mut self, users: &[User]) -> ZKResult<()>

Creates or updates multiple users on the device in a single operation. This is highly efficient as it fetches the user list and refreshes data only once. Performs safety checks for User ID uniqueness across the batch and existing users.

Source

pub fn set_user_unchecked(&mut self, user: &User) -> ZKResult<()>

Creates or updates a user on the device WITHOUT uniqueness checks. High performance, suitable for bulk syncing.

Source

pub fn delete_user(&mut self, uid: u16) -> ZKResult<()>

Deletes a specific user by UID.

Source

pub fn get_templates(&mut self) -> ZKResult<Vec<Finger>>

Retrieves all fingerprint templates from the device.

Source

pub fn get_user_template( &mut self, uid: u16, fid: u8, ) -> ZKResult<Option<Finger>>

Retrieves a specific fingerprint template for a user and finger ID.

Source

pub fn delete_user_template(&mut self, uid: u16, fid: u8) -> ZKResult<()>

Deletes a specific fingerprint template for a user and finger ID.

Source

pub fn reg_event(&mut self, flags: u32) -> ZKResult<()>

Registers for specific real-time events.

Source

pub fn listen_events( &mut self, ) -> ZKResult<impl Iterator<Item = ZKResult<Attendance>> + '_>

Listens for real-time events and yields attendance records as they occur. This is a blocking call that will yield None on timeout.

Source

pub fn get_next_free_uid(&mut self, start_uid: u16) -> ZKResult<u16>

Helper to find the next available UID on the device. start_uid: The UID to start searching from (useful for testing in high ranges).

Source

pub fn find_user_by_id(&mut self, user_id: &str) -> ZKResult<Option<User>>

Finds a user on the device by their alphanumeric User ID.

Source

pub fn timezone_offset(&self) -> i32

Returns the detected timezone offset in minutes.

Source

pub fn timezone_synced(&self) -> bool

Returns true if the timezone has been synchronized with the device.

Source

pub fn refresh_user_cache(&mut self) -> ZKResult<()>

Explicitly refreshes the internal user ID cache.

Source

pub fn users(&self) -> u32

Source

pub fn users_cap(&self) -> i32

Source

pub fn fingers(&self) -> u32

Source

pub fn fingers_cap(&self) -> i32

Source

pub fn records(&self) -> u32

Source

pub fn records_cap(&self) -> i32

Source

pub fn faces(&self) -> u32

Source

pub fn faces_cap(&self) -> i32

Source

pub fn cards(&self) -> i32

Source

pub fn is_connected(&self) -> bool

Source

pub fn user_packet_size(&self) -> usize

Source

pub fn session_id(&self) -> u16

Source

pub fn reply_id(&self) -> u16

Source

pub fn use_legacy_checksum(&self) -> bool

Trait Implementations§

Source§

impl Drop for ZK

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for ZK

§

impl RefUnwindSafe for ZK

§

impl Send for ZK

§

impl Sync for ZK

§

impl Unpin for ZK

§

impl UnsafeUnpin for ZK

§

impl UnwindSafe for ZK

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.