예제 #1
0
def main():
    """Main Read Tag Function"""

    try:
        # Try to open RFID device using default vid:pid (ffff:0035)
        rfid = RfidHid()
    except Exception as e:
        print(e)
        exit()

    # Initialize device
    print('Initializing device...')
    rfid.init()
    sleep(2)
    print('Ready to read a tag...\n')

    while True:
        payload_response = rfid.read_tag()
        if payload_response.has_id_data():
            uid = payload_response.get_tag_uid()
            cid = payload_response.get_tag_cid()
            print('uid: %s' % uid)
            print('customer_id: %s' % cid)
            print('CRC Sum: %s' % hex(payload_response.get_crc_sum()))
            w26 = payload_response.get_tag_w26()
            if w26:
                print('W26: facility code = %d, card number = %d' % w26)
            print('')
            result = raw_input('Copy this tag? (Y/n)').strip()
            if result in ['', 'y', 'Y']:
                break
            else:
                print('Ready to read a tag...\n')
        sleep(0.1)

    print('Ready to write tag...\n')
    while True:
        payload_response = rfid.read_tag()
        if payload_response.has_id_data():

            rfid.write_tag_from_cid_and_uid(cid, uid)
            sleep(0.1)  # you cannot immediately read after a write operation

            payload_response_w = rfid.read_tag()
            # Write verification
            if payload_response_w.get_tag_cid(
            ) == cid and payload_response_w.get_tag_uid() == uid:
                print('Write OK!')
            else:
                print('Write ERROR!')
            break
        sleep(0.1)
예제 #2
0
def main():
    try:
        # Try to open RFID device using default vid:pid (ffff:0035)
        rfid = RfidHid()
    except Exception as e:
        print(e)
        exit()

    # Initialize device
    print('Initializing device...')
    rfid.init()
    sleep(2)

    cmds = []

    payload = [0x00] * 0x03
    payload[0x01] = 0x01
    payload[0x02] = 0x01

    for cmd in range(0x00, 0xff):
        payload[0x00] = cmd
        buff = rfid._initialize_write_buffer(payload)

        # Write Feature Report 1
        response = rfid.hid.set_feature_report(1, buff)

        if response != rfid.BUFFER_SIZE:
            raise ValueError('Communication Error.')

        # Read from Feature Report 2
        response = rfid.hid.get_feature_report(2, rfid.BUFFER_SIZE).tolist()
        cmd_found = ""

        if response[12] != 143:
            cmd_found = "CMD FOUND! " + hex(cmd)
            cmds.append(cmd)

        print('CMD: ' + hex(cmd) + ' response: ' + str(response) + ' ' +
              cmd_found)
        sleep(0.02)

    print('Found ' + str(len(cmds)) + ' commands:')
    print([hex(x) for x in cmds])
예제 #3
0
def main():
    """Main Read Tag Function"""

    try:
        # Try to open RFID device using default vid:pid (ffff:0035)
        rfid = RfidHid()
    except Exception as e:
        print(e)
        exit()

    # Initialize device
    print('Initializing device...')
    rfid.init()
    sleep(2)
    print('Done!')
    print('Please hold a tag to the reader until you hear a beep...\n')

    id_temp = None

    while True:
        payload_response = rfid.read_tag()
        if payload_response.has_id_data():
            uid = payload_response.get_tag_uid()
            # Avoid processing the same tag (CID/UID) more than once in a row
            if uid != id_temp:
                id_temp = uid
                print('uid: %s' % uid)
                print('customer_id: %s' % payload_response.get_tag_cid())
                print('CRC Sum: %s' % hex(payload_response.get_crc_sum()))
                w26 = payload_response.get_tag_w26()
                if w26:
                    print('W26: facility code = %d, card number = %d' % w26)
                print('')
                rfid.beep()
        else:
            id_temp = None
        sleep(0.1)
예제 #4
0
 def connect(self, vid, pid):
     try:
         return RfidHid(vid, pid)
     except Exception as e:
         print(e)
         exit()
예제 #5
0
#!/usr/bin/env python
import time
import sys
import requests
import base64
import json
import RPi.GPIO as GPIO
from uuid import getnode as get_mac
from rfidhid.core import RfidHid

url = 'http://raffy-admin/iot/log-tag'

try:
    #rfid = RfidHid(0x16c0, 0x27db)
    rfid = RfidHid()
    print("Listening...")
except Exception as e:
    print("ERROR", e)
    exit()

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)
print("Control pins are set.")


def listen():
    try:
        while True:
            tag = rfid.read_tag()
            id = tag.get_tag_uid()
예제 #6
0
def main():
    """Main Write Tag Function"""

    # CID and UID to be written
    CID = 77
    UID = 1234567890

    try:
        # Try to open RFID device using default vid:pid (ffff:0035)
        rfid = RfidHid()
    except Exception as e:
        print(e)
        exit()

    # Initialize device
    print('Initializing device...')
    rfid.init()
    sleep(2)
    print('Done!')
    print('CID:UID to be written: %s:%s' % (CID, UID))
    print('Please hold a tag to the reader until you hear two beeps...\n')

    uid_temp = None

    while True:
        payload_response = rfid.read_tag()
        if payload_response.has_id_data():
            uid = payload_response.get_tag_uid()
            # Avoid processing the same tag (CID/UID) more than once in a row
            if uid != uid_temp:
                uid_temp = uid

                rfid.write_tag_from_cid_and_uid(CID, UID)
                sleep(
                    0.1)  # you cannot immediately read after a write operation

                payload_response_w = rfid.read_tag()
                # Write verification
                if payload_response_w.get_tag_cid(
                ) == CID and payload_response_w.get_tag_uid() == UID:
                    print('Write OK!')
                    print('uid: %s' % payload_response_w.get_tag_uid())
                    print('customer_id: %s' % payload_response.get_tag_cid())
                    print('CRC Sum: %s' % hex(payload_response.get_crc_sum()))
                    rfid.beep(2)
                else:
                    print('Write ERROR!')
                    rfid.beep(3)
        else:
            uid_temp = None
        sleep(0.1)