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 strImplementations§
Source§impl ZK
impl ZK
pub fn new(addr: &str, port: u16) -> Self
Sourcepub fn set_password(&mut self, password: u32)
pub fn set_password(&mut self, password: u32)
Sets the communication password for the device.
Sourcepub fn set_legacy_checksum(&mut self, legacy: bool)
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();Sourcepub fn connect(&mut self, protocol: ZKProtocol) -> ZKResult<()>
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.
Sourcepub fn read_sizes(&mut self) -> ZKResult<()>
pub fn read_sizes(&mut self) -> ZKResult<()>
Fetches device capacity and usage statistics.
pub fn decode_time(t: &[u8]) -> ZKResult<NaiveDateTime>
pub fn encode_time(t: NaiveDateTime) -> u32
Sourcepub fn get_attendance(&mut self) -> ZKResult<Vec<Attendance>>
pub fn get_attendance(&mut self) -> ZKResult<Vec<Attendance>>
Retrieves all attendance records from the device.
pub fn get_firmware_version(&mut self) -> ZKResult<String>
pub fn get_option_value(&mut self, key: &str) -> ZKResult<String>
pub fn get_serial_number(&mut self) -> ZKResult<String>
pub fn get_platform(&mut self) -> ZKResult<String>
Sourcepub fn get_timezone(&mut self) -> ZKResult<i32>
pub fn get_timezone(&mut self) -> ZKResult<i32>
Gets the device timezone adjustment (usually in hours).
pub fn get_mac(&mut self) -> ZKResult<String>
pub fn get_device_name(&mut self) -> ZKResult<String>
pub fn get_face_version(&mut self) -> ZKResult<String>
pub fn get_fp_version(&mut self) -> ZKResult<String>
Sourcepub fn get_time(&mut self) -> ZKResult<DateTime<FixedOffset>>
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.
pub fn set_time(&mut self, t: DateTime<FixedOffset>) -> ZKResult<()>
Sourcepub fn set_option(&mut self, key: &str, value: &str) -> ZKResult<()>
pub fn set_option(&mut self, key: &str, value: &str) -> ZKResult<()>
Sets a device option by key and value.
Sourcepub fn change_password(&mut self, new_password: u32) -> ZKResult<()>
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.
pub fn restart(&mut self) -> ZKResult<()>
pub fn poweroff(&mut self) -> ZKResult<()>
pub fn unlock(&mut self, seconds: u32) -> ZKResult<()>
pub fn disconnect(&mut self) -> ZKResult<()>
Sourcepub fn refresh_data(&mut self) -> ZKResult<()>
pub fn refresh_data(&mut self) -> ZKResult<()>
Refreshes the device’s internal data.
Sourcepub fn set_user(&mut self, user: &User) -> ZKResult<()>
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.
Sourcepub fn set_users_bulk(&mut self, users: &[User]) -> ZKResult<()>
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.
Sourcepub fn set_user_unchecked(&mut self, user: &User) -> ZKResult<()>
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.
Sourcepub fn delete_user(&mut self, uid: u16) -> ZKResult<()>
pub fn delete_user(&mut self, uid: u16) -> ZKResult<()>
Deletes a specific user by UID.
Sourcepub fn get_templates(&mut self) -> ZKResult<Vec<Finger>>
pub fn get_templates(&mut self) -> ZKResult<Vec<Finger>>
Retrieves all fingerprint templates from the device.
Sourcepub fn get_user_template(
&mut self,
uid: u16,
fid: u8,
) -> ZKResult<Option<Finger>>
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.
Sourcepub fn delete_user_template(&mut self, uid: u16, fid: u8) -> ZKResult<()>
pub fn delete_user_template(&mut self, uid: u16, fid: u8) -> ZKResult<()>
Deletes a specific fingerprint template for a user and finger ID.
Sourcepub fn reg_event(&mut self, flags: u32) -> ZKResult<()>
pub fn reg_event(&mut self, flags: u32) -> ZKResult<()>
Registers for specific real-time events.
Sourcepub fn listen_events(
&mut self,
) -> ZKResult<impl Iterator<Item = ZKResult<Attendance>> + '_>
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.
Sourcepub fn get_next_free_uid(&mut self, start_uid: u16) -> ZKResult<u16>
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).
Sourcepub fn find_user_by_id(&mut self, user_id: &str) -> ZKResult<Option<User>>
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.
Sourcepub fn timezone_offset(&self) -> i32
pub fn timezone_offset(&self) -> i32
Returns the detected timezone offset in minutes.
Sourcepub fn timezone_synced(&self) -> bool
pub fn timezone_synced(&self) -> bool
Returns true if the timezone has been synchronized with the device.
Sourcepub fn refresh_user_cache(&mut self) -> ZKResult<()>
pub fn refresh_user_cache(&mut self) -> ZKResult<()>
Explicitly refreshes the internal user ID cache.