最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

RFID Scanner in Python Returns Incomplete UID and Byte Data - Stack Overflow

programmeradmin2浏览0评论

I'm using a real RFID scanner with Python to read the unique ID (UID) of RFID tags, but the output is incomplete and sometimes appears in raw byte form instead of the full UID.

Expected Behavior: The scanner should return the full UID in a readable format.

Actual Behavior: The UID is cut off or incomplete. Sometimes, I receive raw byte data instead of a proper UID.

My Setup: Connection Type: [RS232 to USB adaptor] Library Used: [pyserial]

My Code:

import serial

def parse_epc(packet):
    if len(packet) < 23:
        return None
    epc_bytes = packet[3:15]
    epc = "".join("{:02X}".format(byte) for byte in epc_bytes)
    return epc

ser = serial.Serial(
    port='COM3',
    baudrate=9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
)

if not ser.is_open:
    ser.open()

print("Listening for RFID packets on COM4...")

try:
    while True:
        packet = ser.read(23)
        if packet:
            epc = parse_epc(packet)
            if epc:
                print("Tag EPC:", epc)
            else:
                print("Incomplete data")
                print(packet)
except KeyboardInterrupt:
    print("Exiting...")
finally:
    ser.close()
发布评论

评论列表(0)

  1. 暂无评论