首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >连续读id rfid

连续读id rfid
EN

Stack Overflow用户
提问于 2016-08-05 11:35:37
回答 1查看 1.3K关注 0票数 0

我有一个学校作业的项目,把身份证读到RFID RDM6300上这是我的代码

代码语言:javascript
复制
import serial

class Reader(object):
"""The RFID reader class. Reads cards and returns their id"""

def __init__(self, port_name, baudrate, string_length, timeout=1):
    """Constructor

    parameters:
    port_name : the device name of the serial port
    baudrate: baudrate to read at from the serial port
    string_length: the length of the string to read
    timeout: how to long to wait for data on the port
    """
    self.port = serial.Serial(port_name, baudrate=baudrate, timeout=timeout)
    self.string_length = string_length

def read(self):
    """Read from self.port"""
    rcv = self.port.read(self.string_length)

    if not rcv:
        return None

    try:
        # note : data from the RFID reader is in HEX. We'll return
        # as int.
        tag = { "raw" : rcv,
                "mfr" : int(rcv[1:5], 16),
                "id" : int(rcv[5:11], 16),
                "chk" : int(rcv[11:13], 16)}

        print "READ CARD : %s" % tag['id']

        return Card(tag)
    except:
        return None

class Card(object):

def __init__(self, tag):
    self.tag = tag

def get_id(self):
    """Return the id of the tag"""
    return self.tag['id']

def get_mfr(self):
    """Return the mfr of the tag"""
    return self.tag['mfr']

def get_chk(self):
    """Return the checksum of the tag"""
    return self.tag['chk']


def __repr__(self):
    return str(self.get_id())

def is_valid(self):
    """Uses the checksum to validate the RFID tag"""
    i2 = 0
    checksum = 0

    for i in range(0, 5):
        i2 = 2 * i
        checksum ^= int(self.tag.raw[i2 + 1:i2 + 3], 16)

    return checksum == tag['chk']

但是结果是它一次又一次地读取完全相同的id Screenshot of the same id repeated

EN

回答 1

Stack Overflow用户

发布于 2017-01-14 16:08:28

这个帖子真的很旧了.我不知道你是否弄明白了这一点,但也许下一个偶然发现这一点的人会发现这一点很有用。一遍又一遍读卡的原因是只要卡在天线附近,RDM6300就会不断发送数据。没有延迟。因此,你的串行缓冲区被填满了,你的程序一次从缓冲区读取一个条目……理想情况下,您应该从串行缓冲区中读取一个条目,然后通过清除缓冲区来丢弃其余条目。或者最好读取一个条目,根据卡id为您想要采取的任何操作留出时间,然后在代码准备好另一个条目时清除缓冲区……或者在两次读卡之间的实际时间量之后。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38780679

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档