Skip to main content

Python driver for NordicID UHF RFID readers wrapping NurApi

Project description

nurapi

PyPI - Version PyPI - Python Version OS

Table of Contents

Installation

pip install nurapi

Usage

Connect to the reader

# Create driver
reader = NUR()

# Connect
reader.ConnectSerialPortEx(port_name='COM8')
# or reader.ConnectSerialPort(port_numer=8)
# or reader.SetUsbAutoConnect(True)

# Check connection status just by checking physical layer status
reader.IsConnected()
# Check connection status checking full transport layer
reader.Ping()

... use the reader ...

# Disconnect reader
reader.Disconnect()

Get basic information about the reader

## GET INFO
reader_info = reader.GetReaderInfo()
device_caps = reader.GetDeviceCaps()

Sample response values:

reader_info = NurReaderInfo(serial='K134500382', alt_serial='K134700326', name='STIX', fcc_id='', hw_version='PWM0022', sw_ver_major=5, sw_ver_minor=10, dev_build=65, num_gpio=0, num_sensors=0, num_regions=21, num_antennas=1, max_antennas=1)

device_caps = NurDeviceCaps(dwSize=40, flagSet1=15696847, flagSet2=0, maxTxdBm=27, txAttnStep=1, maxTxmW=500, txSteps=20, szTagBuffer=630, curCfgMaxAnt=1, curCfgMaxGPIO=0, chipVersion=2, moduleType=3, moduleConfigFlags=4, v2Level=1, secChipMajorVersion=0, secChipMinorVersion=0, secChipMaintenanceVersion=0, secChipReleaseVersion=0)

Configure the reader

## MODULE SETUP
module_setup = NurModuleSetup()
module_setup.link_freq = SETUP_LINK_FREQ.BLF_160
module_setup.rx_decoding = SETUP_RX_DEC.FM0
desired_tx_level_dbm = 25
module_setup.tx_level = ((device_caps.maxTxdBm - desired_tx_level_dbm) *
                         device_caps.txAttnStep)
module_setup.antenna_mask_ex = 0b00000001  # Antenna 1 (BIT0)
module_setup.selected_antenna = -1  # Automatic selection
reader.SetModuleSetup(
    setup_flags=[
        NUR_MODULESETUP_FLAGS.NUR_SETUP_LINKFREQ,
        NUR_MODULESETUP_FLAGS.NUR_SETUP_RXDEC,
        NUR_MODULESETUP_FLAGS.NUR_SETUP_TXLEVEL,
        NUR_MODULESETUP_FLAGS.NUR_SETUP_ANTMASKEX,
        NUR_MODULESETUP_FLAGS.NUR_SETUP_SELECTEDANT
    ],
    module_setup=module_setup)

module_setup = reader.GetModuleSetup(
    setup_flags=[
        NUR_MODULESETUP_FLAGS.NUR_SETUP_LINKFREQ,
        NUR_MODULESETUP_FLAGS.NUR_SETUP_RXDEC,
        NUR_MODULESETUP_FLAGS.NUR_SETUP_TXLEVEL,
        NUR_MODULESETUP_FLAGS.NUR_SETUP_ANTMASKEX,
        NUR_MODULESETUP_FLAGS.NUR_SETUP_SELECTEDANT
    ])

Perform single synchronous inventory

# Trigger a simple inventory
inventory_response = reader.SimpleInventory()

if inventory_response.num_tags_mem > 0:
    # Fetch read tags to tag buffer including metadata
    tag_count = reader.FetchTags(include_meta=True)

    # Get data of read tags
    for idx in range(tag_count):
        tag_data = reader.GetTagData(idx=idx)

# Clear tag buffer
reader.ClearTags()

Perform continuous asynchronous inventory

def my_callback(inventory_stream_data: NurInventoryStreamData):
    global some_epc
    # If stream stopped, restart
    if inventory_stream_data.stopped:
        reader.StartInventoryStream(rounds=10, q=0, session=0)

    # Check number of tags read
    tag_count = reader.GetTagCount()
    # Get data of read tags
    for idx in range(tag_count):
        tag_data = reader.GetTagData(idx=idx)
        some_epc = tag_data.epc
    reader.ClearTags()


# Configure the callback
reader.set_notification_callback(notification_callback=my_callback)

# Start inventory stream
reader.StartInventoryStream(rounds=10, q=0, session=0)

# Do other stuff
time.sleep(1)

# Stop inventory stream
reader.StopInventoryStream()

Execute Read/Write operations

reader.WriteTagByEPC(
    epc=bytes.fromhex('010203040506070809101112'),
    secured=False, 
    passwd=0, 
    bank=NurBank.NUR_BANK_USER, 
    address=0, 
    byte_count=2, 
    data=bytearray([0x12, 0x34]))

data: bytearray = reader.ReadTagByEPC(
    epc=bytes.fromhex('010203040506070809101112'),
    secured=False, 
    passwd=0, 
    bank=NurBank.NUR_BANK_USER, 
    address=0, 
    byte_count=2)

License

nurapi is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nurapi-1.5.2.tar.gz (1.5 MB view hashes)

Uploaded Source

Built Distribution

nurapi-1.5.2-py3-none-any.whl (1.5 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page