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()
|
||||
```
|
||||
|
||||
* 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
|
||||
|
@ -7,7 +7,7 @@ class Attendance(object):
|
||||
self.status = status
|
||||
|
||||
def __str__(self):
|
||||
return '<Attendance>: {}'.format(self.user_id)
|
||||
return '<Attendance>: {}:{}'.format(self.user_id, self.timestamp)
|
||||
|
||||
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,
|
||||
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:
|
||||
@ -120,12 +126,12 @@ class ZK(object):
|
||||
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('<HHI', const.MACHINE_PREPARE_DATA_1, const.MACHINE_PREPARE_DATA_2, length)
|
||||
return top + packet
|
||||
|
||||
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
|
||||
@ -203,6 +209,7 @@ class ZK(object):
|
||||
'status': False,
|
||||
'code': self.__response
|
||||
}
|
||||
|
||||
def __ack_ok(self):
|
||||
""" event ack ok """
|
||||
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:
|
||||
raise ZKNetworkError(str(e))
|
||||
|
||||
|
||||
def __get_data_size(self):
|
||||
"""Checks a returned packet to see if it returned CMD_PREPARE_DATA,
|
||||
indicating that data packets are to be sent
|
||||
@ -748,8 +754,16 @@ class ZK(object):
|
||||
""" save user and template """
|
||||
#TODO: grabado global
|
||||
# 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):
|
||||
fingers =[Finger]
|
||||
fingers = [fingers]
|
||||
fpack = ""
|
||||
table = ""
|
||||
fnum = 0x10 # possibly flag
|
||||
@ -836,7 +850,7 @@ class ZK(object):
|
||||
raise ZKErrorResponse("can't delete user")
|
||||
self.refresh_data()
|
||||
|
||||
def get_user_template(self, uid, temp_id):
|
||||
def get_user_template(self, uid, temp_id=0):
|
||||
""" ZKFinger VX10.0 """
|
||||
command = 88 # comando secreto!!!
|
||||
command_string = pack('hb', uid, temp_id)
|
||||
@ -987,9 +1001,17 @@ class ZK(object):
|
||||
if len(users) == 1:
|
||||
user_id = users[0].user_id
|
||||
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
|
||||
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
|
||||
self.cancel_capture()
|
||||
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)
|
||||
|
||||
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):
|
||||
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)
|
||||
|
||||
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