add example project

This commit is contained in:
Fanani M. Ihsan 2019-04-25 16:40:15 +07:00
parent b28bfef7d7
commit 70388ca62d
7 changed files with 202 additions and 0 deletions

View File

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
import os
import sys
CWD = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(CWD)
sys.path.append(ROOT_DIR)
from zk import ZK, const
conn = None
zk = ZK('192.168.2.201', port=4370)
try:
conn = zk.connect()
print ("-- Device Information --")
print (" Current Time : %s" % conn.get_time())
print (" Firmware Version : %s" % conn.get_firmware_version())
print (" Device Name : %s" % conn.get_device_name())
print (" Serial Number : %s" % conn.get_serialnumber())
print (" Mac Address : %s" % conn.get_mac())
print (" Face Algorithm Version : %s" % conn.get_face_version())
print (" Finger Algorithm : %s" % conn.get_fp_version())
print (" Platform Information : %s" % conn.get_platform())
#print (conn.get_extend_fmt())
#print (conn.get_user_extend_fmt())
#print (conn.get_face_fun_on())
#print (conn.get_compat_old_firmware())
network_info = conn.get_network_params()
print ("-- Network Information")
print (" IP : %s" % network_info.get('ip'))
print (" Netmask : %s" % network_info.get('mask'))
print (" Gateway : %s" % network_info.get('gateway'))
#print (conn.get_pin_width())
#print (conn.free_data())
#print (conn.refresh_data())
except Exception as e:
print ("Process terminate : {}".format(e))
finally:
if conn:
conn.disconnect()

View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
import os
import sys
CWD = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(CWD)
sys.path.append(ROOT_DIR)
from zk import ZK, const
conn = None
zk = ZK('192.168.2.201', port=4370)
try:
conn = zk.connect()
print ("-- Memory Information --")
conn.read_sizes()
print ("User (used/max) : %s/%s" % (conn.users, conn.users_cap))
print ("Fingerprint (used/max) : %s/%s" % (conn.fingers, conn.fingers_cap))
#print conn.dummy
#print conn.cards
#print conn.rec_cap
#print conn.fingers_av
#print conn.users_av
#print conn.rec_av
except Exception as e:
print ("Process terminate : {}".format(e))
finally:
if conn:
conn.disconnect()

39
example/get_users.py Normal file
View File

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
import os
import sys
CWD = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(CWD)
sys.path.append(ROOT_DIR)
from zk import ZK, const
conn = None
zk = ZK('192.168.2.201', port=4370)
try:
conn = zk.connect()
print ('Disabling device ...')
conn.disable_device()
print ('--- Get User ---')
users = conn.get_users()
for user in users:
privilege = 'User'
if user.privilege == const.USER_ADMIN:
privilege = 'Admin'
print ('+ UID #{}'.format(user.uid))
print (' Name : {}'.format(user.name))
print (' Privilege : {}'.format(privilege))
print (' Password : {}'.format(user.password))
print (' Group ID : {}'.format(user.group_id))
print (' User ID : {}'.format(user.user_id))
print ("Voice Test ...")
conn.test_voice()
print ('Enabling device ...')
conn.enable_device()
except Exception as e:
print ("Process terminate : {}".format(e))
finally:
if conn:
conn.disconnect()

View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
import os
import sys
CWD = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(CWD)
sys.path.append(ROOT_DIR)
from zk import ZK, const
conn = None
zk = ZK('192.168.2.201', port=4370)
try:
conn = zk.connect()
print ("Shutdown the device...")
conn.poweroff()
except Exception as e:
print ("Process terminate : {}".format(e))
finally:
if conn:
conn.disconnect()

22
example/restart_device.py Normal file
View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
import os
import sys
CWD = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(CWD)
sys.path.append(ROOT_DIR)
from zk import ZK, const
conn = None
zk = ZK('192.168.2.201', port=4370)
try:
conn = zk.connect()
print ("Restart Device...")
conn.restart()
except Exception as e:
print ("Process terminate : {}".format(e))
finally:
if conn:
conn.disconnect()

23
example/sync_time.py Normal file
View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
import os
import sys
from datetime import datetime
CWD = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(CWD)
sys.path.append(ROOT_DIR)
from zk import ZK, const
conn = None
zk = ZK('192.168.2.201', port=4370)
try:
conn = zk.connect()
print ("Syncing time...")
conn.set_time(datetime.now())
except Exception as e:
print ("Process terminate : {}".format(e))
finally:
if conn:
conn.disconnect()

25
example/test_voice.py Normal file
View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
import os
import sys
import time
CWD = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(CWD)
sys.path.append(ROOT_DIR)
from zk import ZK, const
conn = None
zk = ZK('192.168.2.201', port=4370)
try:
conn = zk.connect()
for i in range(0, 55):
print ("Voice number #%d" % i)
conn.test_voice(i)
time.sleep(3)
except Exception as e:
print ("Process terminate : {}".format(e))
finally:
if conn:
conn.disconnect()