Skip to content

Commit 428c89c

Browse files
committed
New open_door method
1 parent 6e4e135 commit 428c89c

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Main Features
99
-----
1010

1111
- Programmatically add and remove users to/from the access control system
12+
- Programmatically trigger the relay to open the door
1213
- Convert the 10-digit format RFID numbers to comma format or vice versa
1314

1415
Hardware Requirement
@@ -57,13 +58,22 @@ Remove user (using 10-digit format RFID number):
5758

5859
client.remove_user(badge)
5960

61+
Open door #1:
62+
63+
from rfid import RFIDClient
64+
65+
ip_address = '192.168.1.20'
66+
controller_serial = 123106461
67+
client = RFIDClient(ip_address, controller_serial)
68+
69+
client.open_door(1)
70+
6071
TODO
6172
-----
6273
- Add an optional name parameter to add_user. The access controller also stores the user's name.
6374
- The controller also stores the user's 2-factor pin for when the keypad is enabled. Need to add an optional parameter to add_user for a pin.
6475
- Add a get_users method to RFIDClient that outputs a list of all the users currently in the controller.
6576
- Add a get_logs method to RFIDClient which outputs the card swipe logs.
66-
- Add an open_door method to RFIDClient.
6777

6878
Special Thanks
6979
-----

examples/open_door.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from rfid import RFIDClient
2+
3+
ip_address = '192.168.1.20'
4+
controller_serial = 123106461
5+
client = RFIDClient(ip_address, controller_serial)
6+
7+
client.open_door(1)

rfid.py

+15
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ def remove_user(self, badge):
128128
recv_data = binascii.b2a_hex(self.s.recv(1024))
129129
if (recv_data[:4] != '2321'):
130130
raise Exception("Unexpected Result Received: %s" % recv_data)
131+
132+
def open_door(self, door_number):
133+
if not isinstance(door_number, int):
134+
raise TypeError("RFID number must be set to an integer")
135+
if not (1 <= door_number <= 4):
136+
raise Exception("door_number must be 1 to 4")
137+
138+
door_number = str(door_number - 1).zfill(2)
139+
140+
open_door_packet = self.CRC_16_IBM("2040" + self.source_port + "0500000000000000" + self.controller_serial + "0000020001000000ffffffffffffffff" + door_number + "000000").decode('hex')
141+
self.s.send(self.start_transaction)
142+
self.s.send(open_door_packet)
143+
recv_data = binascii.b2a_hex(self.s.recv(1024))
144+
if (recv_data[:4] != '2041'):
145+
raise Exception("Unexpected Result Received: %s" % recv_data)
131146

132147
def __del__(self):
133148
"""

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
setup(
1212
name='Chinese-RFID-Access-Control-Library',
13-
version='0.0.4',
13+
version='0.0.5',
1414
description='A library for interfacing with one of the most common RFID Access Control System sold in China.',
1515
long_description=readme,
1616
author='Paul Brown',
1717
author_email='paul90brown@gmail.com',
1818
url='https://github.com/pawl/Chinese-RFID-Access-Control-Library',
1919
license=license,
20-
download_url = ['https://github.com/pawl/Chinese-RFID-Access-Control-Library/tarball/master#egg=package-0.0.4'],
20+
download_url = ['https://github.com/pawl/Chinese-RFID-Access-Control-Library/tarball/master#egg=package-0.0.5'],
2121
keywords = ['rfid', 'access control'],
2222
py_modules = ['rfid']
2323
)

0 commit comments

Comments
 (0)