test prepacked tcp data, and unlock door

This commit is contained in:
Arturo Hernandez 2018-06-06 15:10:18 -04:00
parent 4bfbcf6b49
commit 450e448713
4 changed files with 30 additions and 6 deletions

View File

@ -21,7 +21,7 @@ Just create a ZK object and you will be ready to call api.
from zk import ZK, const
conn = None
zk = ZK('192.168.1.201', port=4370, timeout=5)
zk = ZK('192.168.1.201', port=4370, timeout=5, password=0, force_udp=False, ommit_ping=False)
try:
print ('Connecting to device ...')
conn = zk.connect()
@ -207,6 +207,8 @@ optional arguments:
-r, --records Get attendance records
-u, --updatetime Update Date/Time
-l, --live-capture Live Event Capture
-o, --open-door Open door
-D DELETEUSER, --deleteuser DELETEUSER
Delete a User (uid)
-A ADDUSER, --adduser ADDUSER
@ -219,9 +221,7 @@ optional arguments:
```
# Related Project (TODO: chekc compatibility)
# Related Project (TODO: check compatibility)
* [zkcluster](https://github.com/fananimi/zkcluster/ "zkcluster project") is a django apps to manage multiple fingerprint devices.

View File

@ -5,7 +5,7 @@ sys.path.append("zk")
from zk import ZK, const
conn = None
zk = ZK('192.168.1.201', port=4370, timeout=5)
zk = ZK('192.168.1.201', port=4370, timeout=5, password=0, force_udp=False, ommit_ping=False)
try:
print ('Connecting to device ...')
conn = zk.connect()

View File

@ -39,6 +39,8 @@ parser.add_argument('-u', '--updatetime', action="store_true",
help='Update Date/Time')
parser.add_argument('-l', '--live-capture', action="store_true",
help='Live Event Capture')
parser.add_argument('-o', '--open-door', action="store_true",
help='Open door')
parser.add_argument('-D', '--deleteuser', type=int,
help='Delete a User (uid)', default=0)
parser.add_argument('-A', '--adduser', type=int,
@ -201,6 +203,11 @@ try:
print ('--- sizes & capacity ---')
conn.read_sizes()
print (conn)
if args.open_door:
print ('')
print ('--- Opening door 10s ---')
conn.unlock(10)
print (' -- done!---')
if args.live_capture:
print ('')
print ('--- Live Capture! (press ctrl+C to break) ---')

View File

@ -600,6 +600,20 @@ class ZK(object):
else:
raise ZKErrorResponse("can't read sizes")
def unlock(self, time=3):
'''
:param time: define time in seconds
:return:
thanks to https://github.com/SoftwareHouseMerida/pyzk/
'''
command = const.CMD_UNLOCK
command_string = pack("I",int(time)*10)
cmd_response = self.__send_command(command, command_string)
if cmd_response.get('status'):
return True
else:
raise ZKErrorResponse("can't open door")
def __str__(self):
""" for debug"""
return "ZK %s://%s:%s users[%i]:%i/%i fingers:%i/%i, records:%i/%i faces:%i/%i" % (
@ -1328,7 +1342,10 @@ class ZK(object):
size = self.__get_data_size()
if self.verbose: print ("recieve chunk:data size is", size)
if self.tcp:
data_recv = self.__sock.recv(size + 32)
if len(self.__data)>=(8+size): #prepare data with actual data! should be 8+size+32
data_recv = self.__data[8:] # test, maybe -32
else:
data_recv = self.__sock.recv(size + 32)
tcp_length = self.__test_tcp_top(data_recv)
if tcp_length == 0:
print ("Incorrect tcp packet")