gotthardp / python-mercuryapi

Python wrapper for the ThingMagic Mercury API
MIT License
122 stars 63 forks source link

Gen2 Select Filtering #113

Open tberndt5 opened 4 years ago

tberndt5 commented 4 years ago

Hello, I am trying to use the gen2 select filtering as described in the documentation, but I keep getting "TypeError:reserved, epc, tid or user mask expected". I am not sure what I am doing wrong. Is there anyone that could present an example of the gen2 select filtering with all of the associated items in the dict.

Thanks

n8cutler commented 4 years ago

Hi,

I'm also struggling to get the Gen2 Select filtering working and could really use a working example. I've tried building a dictionary and list of dictionaries according to the fields defined. However, I can't seem to get the format right and I'm sure I'm missing something simple.

Any help would be appreciated. Thanks.


Update

I was able to get a single Gen2 Select filter to work when masking by EPC. See example below. However, I am not able to get this to work when using a mask for the user memory.

device = "/dev/ttyUSB2"
reader = mercury.Reader("tmr://{}".format(device), baudrate=115200, protocol="GEN2")
reader.set_region("NA2")

# Showing filtering by epc. This works.
# Showing a mask that doesn't match my tags beyond 16 bits to show that the offset and length work for EPC filter.
gen2_select = {
    'epc': b'E200FF',
    'bit': 32,
    'len': 16,
    }
reader.set_read_plan([1], "GEN2", epc_target=gen2_select, bank="user")
print("Filter using EPC:")
print(reader.read())

# Showing filtering by user bank mask. I can't get this to work.
# User bank offset starts at 0 instead of 32. Just trying to match the first 16 bits.
gen2_select = {
    'user': b'ABCD',
    'bit': 0,
    'len': 16,
    }
reader.set_read_plan([1], "GEN2", epc_target=gen2_select, bank="user")
print("Filter using user data:")
print(reader.read())

# Showing that the first 16 bits of the user memory data matches the filter I am attempting.
target = b'E200001C121501031080489B'
result = reader.read_tag_mem(3, 0x00, 16, epc_target=target)
print("Show user memory data:")
print(result)
reader.destroy()

Output:

Filter using EPC:
[EPC(b'E200001C121501031080489B'), EPC(b'E200001C121500931080405A')]
Filter using user data:
[]
Show user memory data:
bytearray(b'ABCDEF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

I would really appreciate a working example of filtering by user memory mask. Thanks.

amsimon commented 4 years ago

@n8cutler Did you get this to work?