刷卡门禁或PN532刷卡门禁

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 失败2
3:放置指纹边缘   VerifyUser()  成功 or 失败1  or 失败2 or 失败3
4:清除用户       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)有想了解指纹实现的效果,可以关注我的抖音(抖音号:1206268977)
(2)这是实现的web后台,可以点一下链接,详细看一下效果。(基于javaweb实现的后台,就是web的界面就可以命令指纹模块了)账号 :root 密码:root
web后台
(3)有感兴趣可以直接加我的微信 18847414978

发布了33 篇原创文章 · 获赞 14 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/baidu_38978508/article/details/89298188