From cdffacbfe202d6df528a9b4122bef5e5a8bf23bb Mon Sep 17 00:00:00 2001 From: Arturo Hernandez Date: Mon, 30 Apr 2018 10:25:43 -0400 Subject: [PATCH] complete docs and minor patches --- README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++--- zk/attendance.py | 4 +-- zk/base.py | 34 ++++++++++++++++++++----- zk/finger.py | 4 +-- zk/user.py | 2 +- 5 files changed, 94 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a2736c5..83772aa 100644 --- a/README.md +++ b/README.md @@ -67,22 +67,78 @@ conn.disable_device() conn.enable_device() ``` -* Ger Firmware Version +* Get and Set Time + +``` +from datetime import datetime + +zktime = conn.get_time() +print zktime + +newtime = datetime.today() +conn.set_time(newtime) +``` + + +* Ger Firmware Version and extra information ``` conn.get_firmware_version() +conn.get_serialnumber() +conn.get_platform() +conn.get_device_name() +conn.get_face_version() +conn.get_fp_version() +conn.get_extend_fmt() +conn.get_user_extend_fmt() +conn.get_face_fun_on() +conn.get_compat_old_firmware() +conn.get_network_params() +conn.get_mac() +conn.get_pin_width() +``` + +* Get Device use and free Space + +``` +conn.read_sizes() +print(conn) +#also: +conn.users +conn.fingers +conn.records +conn.users_cap +conn.fingers_cap +conn.records_cap ``` * User Operation ``` # Create user -conn.set_user(uid=1, name='Fanani M. Ihsan', privilege=const.USER_ADMIN, password='12345678', group_id='', user_id='123') +conn.set_user(uid=1, name='Fanani M. Ihsan', privilege=const.USER_ADMIN, password='12345678', group_id='', user_id='123', card=0) # Get all users (will return list of User object) users = conn.get_users() # Delete User conn.delete_user(uid=1) ``` +there is also an enroll_user() (but it doesn't work with some tcp ZK8 devices) + + +* Fingerprints + +``` +# Get a single Fingerprint (will return a Finger object) +template = conn.get_user_template(uid=1, temp_id=0) #temp_id is the finger to read 0~9 +# Get all fingers from DB (will return a list of Finger objects) +fingers = conn.get_templates() + +# to restore a finger, we need to assemble with the corresponding user +# pass a User object and a list of finger (max 10) to save + +conn.save_user_template(user, [fing1 ,fing2]) +``` + * Attendance Record ``` @@ -95,7 +151,7 @@ conn.clear_attendance() * Test voice ``` -conn.test_voice() +conn.test_voice(index=10) # beep or chirp ``` * Device Maintenance @@ -105,6 +161,8 @@ conn.test_voice() conn.power_off() # restart connected device conn.restart() +# clear buffer +conn.free_data() ``` # Related Project diff --git a/zk/attendance.py b/zk/attendance.py index 790f721..1fbb9d1 100644 --- a/zk/attendance.py +++ b/zk/attendance.py @@ -7,7 +7,7 @@ class Attendance(object): self.status = status def __str__(self): - return ': {}'.format(self.user_id) + return ': {}:{}'.format(self.user_id, self.timestamp) def __repr__(self): - return ': {}'.format(self.user_id) + return ': {}:{}'.format(self.user_id, self.timestamp) diff --git a/zk/base.py b/zk/base.py index d72c2a2..c40b3e1 100644 --- a/zk/base.py +++ b/zk/base.py @@ -45,6 +45,7 @@ def make_commkey(key, session_id, ticks=50): B, k[3] ^ B) return k + class ZK_helper(object): """ helper class """ def __init__(self, ip, port=4370): @@ -55,6 +56,7 @@ class ZK_helper(object): #self.password = password # passint #self.firmware = int(firmware) #TODO check minor version? #self.tcp = tcp + def test_ping(self): """ Returns True if host responds to a ping request @@ -70,15 +72,18 @@ class ZK_helper(object): stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=need_sh) == 0 + def test_tcp(self): self.client = socket(AF_INET, SOCK_STREAM) self.client.settimeout(10) # fixed test res = self.client.connect_ex(self.address) self.client.close() return res + def test_udp(self): self.client = socket(AF_INET, SOCK_DGRAM) self.client.settimeout(10) # fixed test + class ZK(object): """ Clase ZK """ def __init__(self, ip, port=4370, timeout=60, password=0, force_udp=False, ommit_ping=False): @@ -112,6 +117,7 @@ class ZK(object): self.__reply_id = const.USHRT_MAX-1 self.__data_recv = None self.__data = None + def __create_socket(self): """ based on self.tcp""" if self.tcp: @@ -119,13 +125,13 @@ class ZK(object): self.__sock.connect_ex(self.__address) else: self.__sock = socket(AF_INET, SOCK_DGRAM) - - + def __create_tcp_top(self, packet): """ witch the complete packet set top header """ length = len(packet) top = pack('= 1: + uid = users[0].uid #only one + else: # posibly empty + return False #can't enroll command_string = pack('hhb', int(uid), 0, temp_id) # el 0 es misterio self.cancel_capture() cmd_response = self.__send_command(command, command_string) diff --git a/zk/finger.py b/zk/finger.py index 4749576..1cfa264 100644 --- a/zk/finger.py +++ b/zk/finger.py @@ -17,7 +17,7 @@ class Finger(object): return pack("H%is" % (self.size), self.size+2, self.template) def __str__(self): - return " [u:%i, fid:%i, size:%i v:%i t:%s...]" % (self.uid, self.fid, self.size, self.valid, self.mark) + return " [uid:%i, fid:%i, size:%i v:%i t:%s...]" % (self.uid, self.fid, self.size, self.valid, self.mark) def __repr__(self): - return " [u:%i, fid:%i, size:%i v:%i t:%s...]" % (self.uid, self.fid, self.size, self.valid, self.mark) #.encode('hex') + return " [uid:%i, fid:%i, size:%i v:%i t:%s...]" % (self.uid, self.fid, self.size, self.valid, self.mark) #.encode('hex') diff --git a/zk/user.py b/zk/user.py index aecef39..265953f 100644 --- a/zk/user.py +++ b/zk/user.py @@ -20,4 +20,4 @@ class User(object): return ': [uid:{}, name:{} user_id:{}]'.format(self.uid, self.name, self.user_id) def __repr__(self): - return ': {}'.format(self.name) + return ': [uid:{}, name:{} user_id:{}]'.format(self.uid, self.name, self.user_id)