minor fix, added universal tester

This commit is contained in:
Arturo Hernandez 2018-04-19 20:23:23 -04:00
parent 5467d9dd36
commit 5a1ff7691b
2 changed files with 98 additions and 4 deletions

73
test_machine.py Normal file
View File

@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
import sys
import argparse
from zk import ZK, const
sys.path.append("zk")
conn = None
parser = argparse.ArgumentParser(description='ZK Basic Reading Tests')
parser.add_argument('-a', '--address',
help='ZK device Addres [192.168.1.201]', default='192.168.1.201')
parser.add_argument('-p', '--port', type=int,
help='device port', default=4370)
parser.add_argument('-T', '--timeout', type=int,
help='timeout', default=60)
parser.add_argument('-P', '--password', type=int,
help='Device code/password', default=0)
parser.add_argument('-f', '--firmware', type=int,
help='test firmware', default=8)
parser.add_argument('-t', '--templates', action="store_true",
help='get templates')
parser.add_argument('-r', '--records', action="store_true",
help='get records')
args = parser.parse_args()
zk = ZK(args.address, port=args.port, timeout=args.timeout, password=args.password, firmware=args.firmware)
try:
print 'Connecting to device ...'
conn = zk.connect()
print 'Disabling device ...'
conn.disable_device()
conn.read_sizes()
print conn
print 'Firmware Version: : {}'.format(conn.get_firmware_version())
print 'Platform: %s' % conn.get_platform()
print 'DeviceName: %s' % conn.get_device_name()
print 'Pin Width: %i' % conn.get_pin_width()
print 'Serial Number: %s' % conn.get_serialnumber()
print 'MAC: %s' % conn.get_mac()
print ''
print '--- Get User ---'
users = conn.get_users()
for user in users:
privilege = 'User'
if user.privilege == const.USER_ADMIN:
privilege = 'Admin'
print '-> UID #{:<8} Name : {:<8} Privilege : {}'.format(user.uid, user.name, privilege)
print ' Group ID : {:<8} User ID : {:<8} Password : {:<8} Card : {}'.format(user.group_id, user.user_id, user.password, user.card)
print ''
print "Voice Test ..."
conn.test_voice(10)
if args.templates:
print "Read Templates..."
templates = conn.get_templates()
for tem in templates:
print tem
if args.records:
print "Read Records..."
attendance = conn.get_attendance()
for att in attendance:
print "ATT: uid:{:>3}, t: {}".format(att.uid, att.timestamp)
print 'Enabling device ...'
conn.enable_device()
except Exception, e:
print "Process terminate : {}".format(e)
finally:
if conn:
conn.disconnect()

View File

@ -293,6 +293,21 @@ class ZK(object):
else:
raise ZKErrorResponse("can't get platform")
def get_mac(self):
'''
return the serial number
'''
command = const.CMD_OPTIONS_RRQ
command_string = 'MAC'
response_size = 1024
cmd_response = self.__send_command(command, command_string, response_size)
if cmd_response.get('status'):
mac = self.__data_recv[8:].split('=')[-1].split('\x00')[0]
return mac
else:
raise ZKErrorResponse("can't get mac")
def get_device_name(self):
'''
return the serial number
@ -660,7 +675,7 @@ class ZK(object):
size, uid, fid, valid = unpack('HHbb',templatedata[:6])
template = unpack("%is" % (size-6), templatedata[6:size])[0]
finger = Finger(size, uid, fid, valid, template)
print finger # test
#print finger # test
templates.append(finger)
templatedata = templatedata[size:]
total_size -= size
@ -818,8 +833,14 @@ class ZK(object):
cmd_response = self.__send_command(command, command_string)
if not cmd_response.get('status'):
raise ZKErrorResponse("cant' reg events %i" % flags)
def set_sdk_build_1(self):
""" """
command = const.CMD_OPTIONS_WRQ
command_string = "SDKBuild=1"
cmd_response = self.__send_command(command, command_string)
if not cmd_response.get('status'):
raise ZKErrorResponse("can't set sdk build ")
def enroll_user(self, uid, temp_id=0):
'''
start enroll user
@ -1033,7 +1054,7 @@ class ZK(object):
clear all attendance record
'''
command = const.CMD_CLEAR_ATTLOG
cmd_response = self.__send_command(command, command_string)
cmd_response = self.__send_command(command)
if cmd_response.get('status'):
return True
else: