test prepacked tcp data, and unlock door
This commit is contained in:
parent
4bfbcf6b49
commit
450e448713
@ -21,7 +21,7 @@ Just create a ZK object and you will be ready to call api.
|
|||||||
from zk import ZK, const
|
from zk import ZK, const
|
||||||
|
|
||||||
conn = None
|
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:
|
try:
|
||||||
print ('Connecting to device ...')
|
print ('Connecting to device ...')
|
||||||
conn = zk.connect()
|
conn = zk.connect()
|
||||||
@ -207,6 +207,8 @@ optional arguments:
|
|||||||
-r, --records Get attendance records
|
-r, --records Get attendance records
|
||||||
-u, --updatetime Update Date/Time
|
-u, --updatetime Update Date/Time
|
||||||
-l, --live-capture Live Event Capture
|
-l, --live-capture Live Event Capture
|
||||||
|
-o, --open-door Open door
|
||||||
|
|
||||||
-D DELETEUSER, --deleteuser DELETEUSER
|
-D DELETEUSER, --deleteuser DELETEUSER
|
||||||
Delete a User (uid)
|
Delete a User (uid)
|
||||||
-A ADDUSER, --adduser ADDUSER
|
-A ADDUSER, --adduser ADDUSER
|
||||||
@ -219,9 +221,7 @@ optional arguments:
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Related Project (TODO: check compatibility)
|
||||||
|
|
||||||
# Related Project (TODO: chekc compatibility)
|
|
||||||
|
|
||||||
* [zkcluster](https://github.com/fananimi/zkcluster/ "zkcluster project") is a django apps to manage multiple fingerprint devices.
|
* [zkcluster](https://github.com/fananimi/zkcluster/ "zkcluster project") is a django apps to manage multiple fingerprint devices.
|
||||||
|
|
||||||
|
2
test.py
2
test.py
@ -5,7 +5,7 @@ sys.path.append("zk")
|
|||||||
from zk import ZK, const
|
from zk import ZK, const
|
||||||
|
|
||||||
conn = None
|
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:
|
try:
|
||||||
print ('Connecting to device ...')
|
print ('Connecting to device ...')
|
||||||
conn = zk.connect()
|
conn = zk.connect()
|
||||||
|
@ -39,6 +39,8 @@ parser.add_argument('-u', '--updatetime', action="store_true",
|
|||||||
help='Update Date/Time')
|
help='Update Date/Time')
|
||||||
parser.add_argument('-l', '--live-capture', action="store_true",
|
parser.add_argument('-l', '--live-capture', action="store_true",
|
||||||
help='Live Event Capture')
|
help='Live Event Capture')
|
||||||
|
parser.add_argument('-o', '--open-door', action="store_true",
|
||||||
|
help='Open door')
|
||||||
parser.add_argument('-D', '--deleteuser', type=int,
|
parser.add_argument('-D', '--deleteuser', type=int,
|
||||||
help='Delete a User (uid)', default=0)
|
help='Delete a User (uid)', default=0)
|
||||||
parser.add_argument('-A', '--adduser', type=int,
|
parser.add_argument('-A', '--adduser', type=int,
|
||||||
@ -201,6 +203,11 @@ try:
|
|||||||
print ('--- sizes & capacity ---')
|
print ('--- sizes & capacity ---')
|
||||||
conn.read_sizes()
|
conn.read_sizes()
|
||||||
print (conn)
|
print (conn)
|
||||||
|
if args.open_door:
|
||||||
|
print ('')
|
||||||
|
print ('--- Opening door 10s ---')
|
||||||
|
conn.unlock(10)
|
||||||
|
print (' -- done!---')
|
||||||
if args.live_capture:
|
if args.live_capture:
|
||||||
print ('')
|
print ('')
|
||||||
print ('--- Live Capture! (press ctrl+C to break) ---')
|
print ('--- Live Capture! (press ctrl+C to break) ---')
|
||||||
|
19
zk/base.py
19
zk/base.py
@ -600,6 +600,20 @@ class ZK(object):
|
|||||||
else:
|
else:
|
||||||
raise ZKErrorResponse("can't read sizes")
|
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):
|
def __str__(self):
|
||||||
""" for debug"""
|
""" for debug"""
|
||||||
return "ZK %s://%s:%s users[%i]:%i/%i fingers:%i/%i, records:%i/%i faces:%i/%i" % (
|
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()
|
size = self.__get_data_size()
|
||||||
if self.verbose: print ("recieve chunk:data size is", size)
|
if self.verbose: print ("recieve chunk:data size is", size)
|
||||||
if self.tcp:
|
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)
|
tcp_length = self.__test_tcp_top(data_recv)
|
||||||
if tcp_length == 0:
|
if tcp_length == 0:
|
||||||
print ("Incorrect tcp packet")
|
print ("Incorrect tcp packet")
|
||||||
|
Loading…
Reference in New Issue
Block a user