complete docs and minor patches
This commit is contained in:
parent
dc4629a1bc
commit
cdffacbfe2
64
README.md
64
README.md
@ -67,22 +67,78 @@ conn.disable_device()
|
|||||||
conn.enable_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_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
|
* User Operation
|
||||||
|
|
||||||
```
|
```
|
||||||
# Create user
|
# 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)
|
# Get all users (will return list of User object)
|
||||||
users = conn.get_users()
|
users = conn.get_users()
|
||||||
# Delete User
|
# Delete User
|
||||||
conn.delete_user(uid=1)
|
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
|
* Attendance Record
|
||||||
```
|
```
|
||||||
@ -95,7 +151,7 @@ conn.clear_attendance()
|
|||||||
* Test voice
|
* Test voice
|
||||||
|
|
||||||
```
|
```
|
||||||
conn.test_voice()
|
conn.test_voice(index=10) # beep or chirp
|
||||||
```
|
```
|
||||||
|
|
||||||
* Device Maintenance
|
* Device Maintenance
|
||||||
@ -105,6 +161,8 @@ conn.test_voice()
|
|||||||
conn.power_off()
|
conn.power_off()
|
||||||
# restart connected device
|
# restart connected device
|
||||||
conn.restart()
|
conn.restart()
|
||||||
|
# clear buffer
|
||||||
|
conn.free_data()
|
||||||
```
|
```
|
||||||
|
|
||||||
# Related Project
|
# Related Project
|
||||||
|
@ -7,7 +7,7 @@ class Attendance(object):
|
|||||||
self.status = status
|
self.status = status
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '<Attendance>: {}'.format(self.user_id)
|
return '<Attendance>: {}:{}'.format(self.user_id, self.timestamp)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Attendance>: {}'.format(self.user_id)
|
return '<Attendance>: {}:{}'.format(self.user_id, self.timestamp)
|
||||||
|
32
zk/base.py
32
zk/base.py
@ -45,6 +45,7 @@ def make_commkey(key, session_id, ticks=50):
|
|||||||
B,
|
B,
|
||||||
k[3] ^ B)
|
k[3] ^ B)
|
||||||
return k
|
return k
|
||||||
|
|
||||||
class ZK_helper(object):
|
class ZK_helper(object):
|
||||||
""" helper class """
|
""" helper class """
|
||||||
def __init__(self, ip, port=4370):
|
def __init__(self, ip, port=4370):
|
||||||
@ -55,6 +56,7 @@ class ZK_helper(object):
|
|||||||
#self.password = password # passint
|
#self.password = password # passint
|
||||||
#self.firmware = int(firmware) #TODO check minor version?
|
#self.firmware = int(firmware) #TODO check minor version?
|
||||||
#self.tcp = tcp
|
#self.tcp = tcp
|
||||||
|
|
||||||
def test_ping(self):
|
def test_ping(self):
|
||||||
"""
|
"""
|
||||||
Returns True if host responds to a ping request
|
Returns True if host responds to a ping request
|
||||||
@ -70,15 +72,18 @@ class ZK_helper(object):
|
|||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
shell=need_sh) == 0
|
shell=need_sh) == 0
|
||||||
|
|
||||||
def test_tcp(self):
|
def test_tcp(self):
|
||||||
self.client = socket(AF_INET, SOCK_STREAM)
|
self.client = socket(AF_INET, SOCK_STREAM)
|
||||||
self.client.settimeout(10) # fixed test
|
self.client.settimeout(10) # fixed test
|
||||||
res = self.client.connect_ex(self.address)
|
res = self.client.connect_ex(self.address)
|
||||||
self.client.close()
|
self.client.close()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def test_udp(self):
|
def test_udp(self):
|
||||||
self.client = socket(AF_INET, SOCK_DGRAM)
|
self.client = socket(AF_INET, SOCK_DGRAM)
|
||||||
self.client.settimeout(10) # fixed test
|
self.client.settimeout(10) # fixed test
|
||||||
|
|
||||||
class ZK(object):
|
class ZK(object):
|
||||||
""" Clase ZK """
|
""" Clase ZK """
|
||||||
def __init__(self, ip, port=4370, timeout=60, password=0, force_udp=False, ommit_ping=False):
|
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.__reply_id = const.USHRT_MAX-1
|
||||||
self.__data_recv = None
|
self.__data_recv = None
|
||||||
self.__data = None
|
self.__data = None
|
||||||
|
|
||||||
def __create_socket(self):
|
def __create_socket(self):
|
||||||
""" based on self.tcp"""
|
""" based on self.tcp"""
|
||||||
if self.tcp:
|
if self.tcp:
|
||||||
@ -120,12 +126,12 @@ class ZK(object):
|
|||||||
else:
|
else:
|
||||||
self.__sock = socket(AF_INET, SOCK_DGRAM)
|
self.__sock = socket(AF_INET, SOCK_DGRAM)
|
||||||
|
|
||||||
|
|
||||||
def __create_tcp_top(self, packet):
|
def __create_tcp_top(self, packet):
|
||||||
""" witch the complete packet set top header """
|
""" witch the complete packet set top header """
|
||||||
length = len(packet)
|
length = len(packet)
|
||||||
top = pack('<HHI', const.MACHINE_PREPARE_DATA_1, const.MACHINE_PREPARE_DATA_2, length)
|
top = pack('<HHI', const.MACHINE_PREPARE_DATA_1, const.MACHINE_PREPARE_DATA_2, length)
|
||||||
return top + packet
|
return top + packet
|
||||||
|
|
||||||
def __create_header(self, command, command_string, session_id, reply_id):
|
def __create_header(self, command, command_string, session_id, reply_id):
|
||||||
'''
|
'''
|
||||||
Puts a the parts that make up a packet together and packs them into a byte string
|
Puts a the parts that make up a packet together and packs them into a byte string
|
||||||
@ -203,6 +209,7 @@ class ZK(object):
|
|||||||
'status': False,
|
'status': False,
|
||||||
'code': self.__response
|
'code': self.__response
|
||||||
}
|
}
|
||||||
|
|
||||||
def __ack_ok(self):
|
def __ack_ok(self):
|
||||||
""" event ack ok """
|
""" event ack ok """
|
||||||
buf = self.__create_header(const.CMD_ACK_OK, b'', self.__session_id, const.USHRT_MAX - 1)
|
buf = self.__create_header(const.CMD_ACK_OK, b'', self.__session_id, const.USHRT_MAX - 1)
|
||||||
@ -215,7 +222,6 @@ class ZK(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ZKNetworkError(str(e))
|
raise ZKNetworkError(str(e))
|
||||||
|
|
||||||
|
|
||||||
def __get_data_size(self):
|
def __get_data_size(self):
|
||||||
"""Checks a returned packet to see if it returned CMD_PREPARE_DATA,
|
"""Checks a returned packet to see if it returned CMD_PREPARE_DATA,
|
||||||
indicating that data packets are to be sent
|
indicating that data packets are to be sent
|
||||||
@ -748,8 +754,16 @@ class ZK(object):
|
|||||||
""" save user and template """
|
""" save user and template """
|
||||||
#TODO: grabado global
|
#TODO: grabado global
|
||||||
# armar paquete de huellas
|
# armar paquete de huellas
|
||||||
|
if not isinstance(user, User):
|
||||||
|
#try uid
|
||||||
|
users = self.get_users()
|
||||||
|
users = filter(lambda x: x.uid==user, users)
|
||||||
|
if len(users) == 1:
|
||||||
|
user = users[0]
|
||||||
|
else:
|
||||||
|
raise ZKErrorResponse("Cant find user")
|
||||||
if isinstance(fingers, Finger):
|
if isinstance(fingers, Finger):
|
||||||
fingers =[Finger]
|
fingers = [fingers]
|
||||||
fpack = ""
|
fpack = ""
|
||||||
table = ""
|
table = ""
|
||||||
fnum = 0x10 # possibly flag
|
fnum = 0x10 # possibly flag
|
||||||
@ -836,7 +850,7 @@ class ZK(object):
|
|||||||
raise ZKErrorResponse("can't delete user")
|
raise ZKErrorResponse("can't delete user")
|
||||||
self.refresh_data()
|
self.refresh_data()
|
||||||
|
|
||||||
def get_user_template(self, uid, temp_id):
|
def get_user_template(self, uid, temp_id=0):
|
||||||
""" ZKFinger VX10.0 """
|
""" ZKFinger VX10.0 """
|
||||||
command = 88 # comando secreto!!!
|
command = 88 # comando secreto!!!
|
||||||
command_string = pack('hb', uid, temp_id)
|
command_string = pack('hb', uid, temp_id)
|
||||||
@ -987,9 +1001,17 @@ class ZK(object):
|
|||||||
if len(users) == 1:
|
if len(users) == 1:
|
||||||
user_id = users[0].user_id
|
user_id = users[0].user_id
|
||||||
else: #double? posibly empty
|
else: #double? posibly empty
|
||||||
return False #can't enrool
|
return False #can't enroll
|
||||||
command_string = pack('<24sbb',str(user_id), temp_id, 1) # el 1 es misterio
|
command_string = pack('<24sbb',str(user_id), temp_id, 1) # el 1 es misterio
|
||||||
else:
|
else:
|
||||||
|
if not uid:
|
||||||
|
#we need uid
|
||||||
|
users = self.get_users()
|
||||||
|
users = filter(lambda x: x.user_id==user_id, users)
|
||||||
|
if len(users) >= 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
|
command_string = pack('hhb', int(uid), 0, temp_id) # el 0 es misterio
|
||||||
self.cancel_capture()
|
self.cancel_capture()
|
||||||
cmd_response = self.__send_command(command, command_string)
|
cmd_response = self.__send_command(command, command_string)
|
||||||
|
@ -17,7 +17,7 @@ class Finger(object):
|
|||||||
return pack("H%is" % (self.size), self.size+2, self.template)
|
return pack("H%is" % (self.size), self.size+2, self.template)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "<Finger> [u:%i, fid:%i, size:%i v:%i t:%s...]" % (self.uid, self.fid, self.size, self.valid, self.mark)
|
return "<Finger> [uid:%i, fid:%i, size:%i v:%i t:%s...]" % (self.uid, self.fid, self.size, self.valid, self.mark)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Finger> [u:%i, fid:%i, size:%i v:%i t:%s...]" % (self.uid, self.fid, self.size, self.valid, self.mark) #.encode('hex')
|
return "<Finger> [uid:%i, fid:%i, size:%i v:%i t:%s...]" % (self.uid, self.fid, self.size, self.valid, self.mark) #.encode('hex')
|
||||||
|
@ -20,4 +20,4 @@ class User(object):
|
|||||||
return '<User>: [uid:{}, name:{} user_id:{}]'.format(self.uid, self.name, self.user_id)
|
return '<User>: [uid:{}, name:{} user_id:{}]'.format(self.uid, self.name, self.user_id)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<User>: {}'.format(self.name)
|
return '<User>: [uid:{}, name:{} user_id:{}]'.format(self.uid, self.name, self.user_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user