首页 > 编程知识 正文

3M门禁卡,5577门禁卡

时间:2023-05-03 21:41:20 阅读:227342 作者:1193

1、材料准备
(1)PN532
(2)usb转ttl(串口通信)
(3)继电器
(4)电磁铁
(5)安卓线
2、电路连接
这个比较简单,将硬件的针脚与树莓派一一对应就好了。整体的链接就是PN532链接usb转ttl和USB转ttl链接树莓派。
连接图

3、代码

()ser = serial.Serial("/dev/ttyUSB0", 115200)# ***************************************************************************# @brief send a command, and wait for the response of module# ***************************************************************************/def TxAndRxCmd(command_buf, rx_bytes_need, timeout): """发送数据函数,等待回应 :param command_buf: 0x28, 0, 0, 1, 0, 获取用户数, 0.1 :param rx_bytes_need: 8 :param timeout: 0.1 :return: """ global g_rx_buf CheckSum = 0 tx_buf = [] tx = "" # tx_buf 0xF5 tx_buf.append(CMD_HEAD) # CMD_HEAD = 0xF5 for byte in command_buf: tx_buf.append(byte) CheckSum ^= byte tx_buf.append(CheckSum) tx_buf.append(CMD_TAIL) # CMD_TAIL = 0xF5 # tx_buf for i in tx_buf: tx += hex(i)[2:].zfill(2) # 返回一个参数i表示的字符串 ser.flushInput() # tx = bytes.fromhex(tx) ser.write(tx)def GetId(): tx = Get_Id ser.flushInput() # tx = bytes.fromhex(tx) ser.write(tx)# ***************************************************************************# @brief Analysis the command from PC terminal# ***************************************************************************/def Analysis_PC_Command(command): """选择模式1:查询用户数量2:添加指纹 AddUser() 成功 or 失败1 or 失败23:放置指纹边缘 VerifyUser() 成功 or 失败1 or 失败2 or 失败34:清除用户 ClearAllUser()5:睡眠6:唤醒 :param command: """ global Cmd_Select if command == "CMD1" : print("-" * 20) print("添加用户请刷卡") Cmd_Select = 1 GetId() elif command == "CMD2" : print("-" * 20) print("门禁模式已开启") Cmd_Select = 2 GetId() else: pass# ***************************************************************************# @brief If you enter the sleep mode, then open the Automatic wake-up function of the finger,# begin to check if the finger is pressed, and then start the module and match# ***************************************************************************/

部分代码
4后记

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。