gotthardp / python-mercuryapi Goto Github PK
View Code? Open in Web Editor NEWPython wrapper for the ThingMagic Mercury API
License: MIT License
Python wrapper for the ThingMagic Mercury API
License: MIT License
I've gotten to the point where I'm able to read the tags using the reader.Read method.
I create a reader using mercury.Reader("tmr:///COM6")
I set the region to "EU3"
I set the readplan:
rfid_reader.set_read_plan(rfid_reader.get_antennas(), "GEN2")
This works fine, I'm able to get some information from the API for example:
b'303A5E59000000000000DB96'
However, I'd like to get more of the information, so I tried adding the bank parameter to the set_read_plan
function like so:
rfid_reader.set_read_plan(rfid_reader.get_antennas(), "GEN2", "tid")
I've also tried adding a list of 1 and a list of multiple bank parameters like so:
rfid_reader.set_read_plan(rfid_reader.get_antennas(), "GEN2", ["tid"])
and
rfid_reader.set_read_plan(rfid_reader.get_antennas(), "GEN2", ["tid", "reserved"])
However, as soon as I set a bank parameter, I get the following error:
Traceback (most recent call last):
File "C:\ti-software\RFID\rfid\app.py", line 38, in start_action
self.read_timer.timeout.connect(self.update_list())
File "C:\ti-software\RFID\rfid\app.py", line 45, in update_list
tags = utils.rfid_read(self)
File "C:\ti-software\RFID\rfid\utils.py", line 42, in rfid_read
temp = mainWindow.rfid_reader.read()
RuntimeError: Invalid argument
just in case it matters, the reader is kept as a property of mainWindow.
I'm using the latest 32 bit release for python 3.6.
Any idea what is going on? Or what I should change to get more data back ?
thanks!
I want to get IP address of the machine where Thingmagic reader is connected over USB port using python code. Please help me.
Thank you so much in advance
I tried a test using the ThingMagic astra through IP and it worked, switched to USB and I get this error when running.
Traceback (most recent call last):
File "test.py", line 5, in
reader = mercury.Reader("tmr:///dev/ttyUSB0", baudrate=115200)
TypeError: Timeout
Hi,
Thanks for making this library available. I'm trying to integrate it into a project I'm working on, and I was wondering if there was any way to set a device's power and read mode in Python.
Thanks again.
We have labels being printed on Zebra RFID printers.
Was exploring an alternative way to scan the labels.
Is the only way to purchase this board, or is there an even cheaper way?
Is that possible to use python2 for this python wrapper?
I am using this code in ROS Indigo, but rospy supports only python2.
Hey! I'm using windows and i got that installer in the latest release link to install but i'm still getting the error when i try "setup.py install"
running build
running build_ext
building 'mercury' extension
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ibuild/mercuryapi/include -IC:\Users\HP\AppData\Local\Programs\Python\Python36\include -IC:\Users\HP\AppData\Local\Programs\Python\Python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tcmercury.c /Fobuild\temp.win-amd64-3.6\Release\mercury.obj
mercury.c
mercury.c(23): fatal error C1083: Cannot open include file: 'tm_reader.h': No such file or directory
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2"
could please help me with this?
Thanks.
Hi, I'm really interesting with how to build mercury api c library in windows. But the windows installer is not open source. I'm doing the research on how to write mercury api in C/C++. I'm not sure whether you can share the step how to build the library for windows? Thanks.
Hello,
Just wondering whether the rssi value returned in TagReadData objects from reader.read() when read_count > 1 is the average rssi value of all the readings or something else such as the last rssi value?
I've ben using your code for a while, and always been able to make it work.
Today I went again to install the code in a new computer, and follow your instructions for linux.
However, when trying to import mercury from my python code i get this error:
>>> import mercury
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-x86_64/egg/mercury.py", line 7, in <module>
File "build/bdist.linux-x86_64/egg/mercury.py", line 6, in __bootstrap__
ImportError: /home/username/.python-eggs/mercuryapi-0.4-py2.7-linux-x86_64.egg-tmp/mercury.so: undefined symbol: PyUnicode_AsUTF8
Any idea what is happening?
When a multiplexer is connected the reader.read command outputs no reads even though it would without the multiplexer. How do I set the GPIO pins high with the python wrapper? Is there anyway of this? If not, is there a way to change the built code?
Hey,
I am unfamiliar with wrapping C Librarys for python.
My plan was to use your wrap of the mercury api in a project.
So I would like to isolate all dependencies I will require.
I use a conda environment, python --version shows me that the correct python version is active. But if I follow your instructions on building the api wrapper for linux the api is installed on the python in the /usr/lib64/python2.7/ path instead of my home/anaconda3/.
Also I am unable to import mercury in my environment.
Is there any way to install your wrapper in a anaconda environment?
Hope you can help me and thanks in advance for your time!
Hello, I'm getting an error when calling the make command. The make process ends up with the following error:
Traceback (most recent call last) :
File "setup.py", line 3, in
from setuptools import setup Extension
ImportError: No module named 'setuptools'
Makefile:7: recipe for target 'all' failed
make: *** [all] Error 1
Windows 7 32 bit
Thank you
Hey,
I am running a flask based web application. In this apllication when visiting a specific page, the readprocess starts as a background thread.
If the index page is visited, the read should be stopped.
If the reader is busy reading, I can't stop the reader with reader.stop(). I get the following error massage:
Traceback (most recent call last): File "manStop.py", line 7, in <module> reader = mercury.Reader("tmr:///dev/ttyUSB0", baudrate=115200) TypeError: Timeout
Any ideas?
I get this error when running my code. Things work fine until the call to read. I'm assuming this has to do with the Tag buffer filling up for some reason, but I don't know how to clear it properly. I've tried setting different baud rates but no luck.
M6e Nano
[u'NA2', u'NA3', u'IN', u'JP', u'PRC', u'EU3', u'KR2', u'AU', u'NZ', u'open']
Traceback (most recent call last):
File "test.py", line 12, in <module>
print(reader.read(timeout=1000))
RuntimeError: Timeout
here is the code that I am running
from __future__ import print_function
import time
import mercury
reader = mercury.Reader("tmr:///dev/ttyUSB0", baudrate=115200)
print(reader.get_model())
print(reader.get_supported_regions())
reader.set_region("EU3")
reader.set_read_plan([1], "GEN2", read_power=1900)
print(reader.read(timeout=1000))
reader.start_reading(lambda tag: print(tag.epc, tag.antenna, tag.read_count, tag.rssi))
time.sleep(1)
reader.stop_reading()
Nice work on the code. I've been able to use it to get some initial reads with a ThingMagic Sargas UHF reader. I was wondering if you had any plans on adding support for gen2 settings (e.g. tari, BLF, session).
Thanks!
I'm currently attempting to read tag data banks with a networked Sargas reader, and the current implementation is failing to read the data banks. For example simply running:
reader = mercury.Reader("tmr://192.168.1.101")
reader.set_read_plan([1], "GEN2", bank=["epc"], read_power=3000)
tags = reader.read(timeout=1000)
for tag in tags:
print(tag.epc, tag.antenna, tag.read_count, tag.rssi, tag.epc_mem_data)
All of the tag parameters are correct, except for epc_mem_data which is None for every tag returned. The same None result applies for any other data bank, or if I'm attempting to get multiple instead of one.
After a little digging the source of the problem may be because the current bank read is implemented using embedded tag ops set in the read plan, combined with me using a networked reader accessed through an IP, not a serial connected reader. This is touched on in the MercuryAPI ProgrammerGuide:
Embedded TagOps are only supported with Gen2 (ISO18000-6C) protocol tags and when connected to readers of type SerialReader and RQLReader type M6.
This makes me think that for a networked reader I need to use direct invocation through Reader.ExecuteTagOp() that is mentioned in the programmer guide. I may take a stab at adding a method for this myself if I'm correct here.
To add an additional layer of confusion, the official Universal Reader Assistant program (which I presume still uses the Mercury API in the background) has an "Embedded ReadData" option that does work with my networked reader and the tags I'm testing with, which is in conflict with the above quote and leaves me wondering if I'm missing something else.
Has anyone else run into this kind of issue with the Mercury API before?
When running make
from on Mac OS, I get a lot of the following errors:
./ltkc_base.h:142:5: error: unknown type name 'llrp_u16_t'; did you mean 'llrp_u16v_t'?
Is building/installing from MacOS supported? And if not, what is required to allow for this?
Im having issue running the reader.start_reading call function when setting the read plan to include for the bank arguments. For example when I set: reader.set_readplan([1], "GEN2", bank=["epc", "reserved"], read_power=1400), the reader.start_reading call returns nothing. When I get rid of the bank argument it starts to work however the bank arguments will print as "None" such as the reserved, tid etc.
Attempting to install with
pip install python-mercury api
From here:
https://pypi.org/project/python-mercuryapi/
This is the output
Collecting python-mercuryapi
Using cached https://files.pythonhosted.org/packages/5f/b3/0ed60331a77de7fcc5f8dc55bd48a901a327a93052e2756868cd9ead2ac2/python-mercuryapi-0.4.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-s0UN60/python-mercuryapi/setup.py", line 8, in
long_description=open('README.md').read(),
IOError: [Errno 2] No such file or directory: 'README.md'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-s0UN60/python-mercuryapi/
When I build from source using python2, then try to import, it says it's already been imported and it just doesn't work at all.
Hi,
What device did you use with your Raspberry Pi ?
Thanks !
First, a big thank you for providing this library - it's really awesome! Unfortunately I've become stuck on a curious issue: I've got two Mercury M6e readers connected via USB, with a UDEV rule* assigning fixed references for each one - yet in a simple Python test the readers (or rather, their callback functions) keep swapping around, which makes it impossible to identify which antenna read which tag! This is my test program:
import mercury
from time import sleep
readerA = mercury.Reader("tmr:///dev/MercuryA", baudrate=9600)
readerB = mercury.Reader("tmr:///dev/MercuryB", baudrate=9600)
def detectA(tag):
print tag.epc + " A" + str(tag.antenna)
def detectB(tag):
print tag.epc + " B" + str(tag.antenna)
readerA.set_region("EU3")
readerA.set_read_plan([1,2,3,4], "GEN2", read_power=800)
readerB.set_region("EU3")
readerB.set_read_plan([1,2,3,4], "GEN2", read_power=800)
try:
readerA.start_reading(detectA)
readerB.start_reading(detectB)
while True:
sleep(0.1)
except(KeyboardInterrupt, SystemExit):
readerA.stop_reading()
readerB.stop_reading()
And here is some sample output, with a single tag resting directly on top of one of the antennas:
300ED89F335000400182120B A2
300ED89F335000400182120B A2
300ED89F335000400182120B B2
300ED89F335000400182120B A2
300ED89F335000400182120B A2
300ED89F335000400182120B B2
300ED89F335000400182120B A2
300ED89F335000400182120B B2
300ED89F335000400182120B A2
300ED89F335000400182120B A2
300ED89F335000400182120B A2
300ED89F335000400182120B A2
300ED89F335000400182120B A2
300ED89F335000400182120B B2
300ED89F335000400182120B B2
300ED89F335000400182120B A2
300ED89F335000400182120B A2
300ED89F335000400182120B A2
300ED89F335000400182120B B2
As you can see, readerA (or is it B!? how can I tell!?) randomly switches between calling the detectA() and detectB() callbacks! How can this be, when I've separately defined each reader, and its callback function!? I'm hoping this is just due to some silly mistake on my part :)
*) My UDEV rule (/etc/udev/rules.d/99-usb-serial.rules), for those playing along at home:
SUBSYSTEM=="tty", KERNELS=="1-1.1.2:1.0", SYMLINK+="MercuryA"
SUBSYSTEM=="tty", KERNELS=="1-1.1.3:1.0", SYMLINK+="MercuryB"
I downloaded the API from ThingMagic, and have it in the same folder as the github package you posted. I'm in Python 3.63 via Pycharm and when I try to run the setup folders: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
error: no commands supplied
then when I try to run the test.py: import mercury
ImportError: No module named 'mercury'
I'm on a 64 bit OS with Windows 10 and I'm new to coding..
Thanks for the help.
I'm not sure how pip works in terms of installing dependencies before installing the target library, but some necessary dependencies are apparently not present in Raspbian. Simply running
pip2 install python-mercuryapi
will fail unless first running
sudo apt-get install patch xsltproc gcc libreadline-dev python-dev python-setuptools
Like I wrote, I don't know how pip works but I thought it was possible to build in the installation of dependencies first, so maybe that could be added in.
Hey,
Is it possible to get the user memory data?
I tried to play with the code(of mercury.c) a little bit but with no luck.
Thank you.
Hello, When I run continous read mode the read_count for the tag remains at one, any chance this can be fixed? I'm using the test.py code.
Hi,
I used the mercuryapi-1.31.0.33 and visual studio 2017 to compile the code. It came with the error that out_ltkc.h is missing, may I ask how to solve this? thanks.
C:/Apps/mercuryapi-1.31.0.33/c/src/api/ltkc_win32/inc\ltkc.h(32): fatal error C1
083: Cannot open include file: 'out_ltkc.h': No such file or directory
Hi,
Great job for wrapping it in Python:)
Do you have any plans to add the user defined data to TagReadData (i.e., the data that can be written to tags)?
Hello Gotthardp,
thank for this project!
I've tried to use this project on a BeagleBone (ARM) with Debian.
I'm working with Sargas hardware, with 2 antennas.
Despite I had not some packets , I could making well the project and install.
Right now, I'm trying to connect the reader thought the network, so the uri is:
tmr://localhost
baudrate = 115200.
But, this instruction return me the message: "Key not found".
Have you any idea to how to resolv this?
Thanks a lot
Hi,
Did this wrapper include the support of the specific tag commands for SL900A chip?
Many thanks.
Best,
Bin
Hey @gotthardp
I tried the following:
#!/usr/bin/env python3
from __future__ import print_function
import mercury
reader = mercury.Reader("tmr://dev/ttyUSB0", baudrate=115200)
reader.set_region("EU3")
reader.set_read_plan(reader.get_antennas(), "GEN2", "user")
for tag in reader.read(timeout=450):
print("EPC", tag.epc)
print("Antenna", tag.antenna)
print("Count", tag.read_count)
print("RSSI", tag.rssi)
print("user", tag.user_mem_data)
Unfortunately I get the following results:
EPC b'E200001963020091231027DE'
Antenna 1
Count 7
RSSI -37
user bytearray(b'L18100117\r\n\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
EPC b'E2000017230C01961100AA8E'
Antenna 1
Count 7
RSSI -31
user None
As you can see, the second tag does not return user data. That is, if two tags are read at the same time. Both show the correct user data if read seperately.
Originally posted by @rasidmusic in #39 (comment)
Hello, is there anyway to get the TID number of the RFID tag?
Hi,
I have followed the installation instructions on Linux and everything ran successfully without any errors. Here are list of instructions I executed.
pi@raspberrypi: make -C mercuryapi-1.31.0.33/c/src/api make[1]: Entering directory '/home/pi/TM/PY/python-mercuryapi/mercuryapi-1.31.0.33/c/src/api' SOURCE_DIR=lib PATCH_DIR=lib XML_DIR=lib sh lib/install_LTKC.sh NULL lib lib/LTK directory already exists cd lib/LTK/LTKC/Library; make CC="cc -Ilib/LTK/LTKC/Library -Ilib/LTK/LTKC/Library/LLRP.org -I. -g -Wall -fPIC" STRIP="strip" make[2]: Entering directory '/home/pi/TM/PY/python-mercuryapi/mercuryapi-1.31.0.33/c/src/api/lib/LTK/LTKC/Library' cd LLRP.org; make all make[3]: Entering directory '/home/pi/TM/PY/python-mercuryapi/mercuryapi-1.31.0.33/c/src/api/lib/LTK/LTKC/Library/LLRP.org' make[3]: Nothing to be done for 'all'. make[3]: Leaving directory '/home/pi/TM/PY/python-mercuryapi/mercuryapi-1.31.0.33/c/src/api/lib/LTK/LTKC/Library/LLRP.org' make[2]: Leaving directory '/home/pi/TM/PY/python-mercuryapi/mercuryapi-1.31.0.33/c/src/api/lib/LTK/LTKC/Library' make[1]: Leaving directory '/home/pi/TM/PY/python-mercuryapi/mercuryapi-1.31.0.33/c/src/api' mkdir -p build/mercuryapi/include find mercuryapi-*/c/src/api -type f -name '*.h' ! -name '*_imp.h' | grep -v 'ltkc_win32' | xargs cp -t build/mercuryapi/include mkdir -p build/mercuryapi/lib find mercuryapi-*/c/src/api -type f -name '*.a' -or -name '*.so.1' | xargs cp -t build/mercuryapi/lib /usr/bin/python3 setup.py build running build running build_ext
Once its done, When I run the /usr/bin/python3 test.py, I get the import error: No module named mercury error. I am trying to connect a ThingMagic rfid reader to a Raspberry Pi and read some tags.
Title
Is it possible to get the RSSI and Antenna ID from the tag reads?
Hey! I got everything running, but I'm just not sure how to get the actual data off of the tags. How would you suggest about doing so?
Thanks!
Im getting 'ImportError: No module named 'mercury' when running python test.py
Great work writing well documented python wrapper !
I was trying to configure to read tag from multiple antenna, steps i followed are as follows
1). Since sparkfun have given access to GPIO1 of thingmagic 6E nano RFID , i have set it high to enable logical antenna 1 and 3 via antenna multiplexer.
2)and also set read plan as follows, which is also mentioned in the readme.md of this repo
reader.set_read_plan(antennas=[1,3],protocol="GEN2")
But this throws following error
TypeError : Invalid antenna configuration
What is the problem with the above steps ?
Best Regards
mundkur
When I run "sudo python3 setup.py install" I end up with the following error:
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
How can I resolve the problem? (Tnx)
I'm using Windows 10 and Python 3.6.6.
Installation from mercuryapi-0.3.win32-py3.6.exe
completes with no errors, but when attempting to import the mercury
package, I get the following error:
ImportError: DLL load failed: The specified module could not be found.
What (probably stupid) thing am I doing wrong here?
It would be good to be able to get the phase measurement from tags also
Any chance that this is a minor implementation to the current code?
Hello,
I encouter an issu with the function start_reading with the folling code:
import time as tm
import mercury
reader = mercury.Reader("tmr:///COM12")
''' paramètres'''
reader.set_read_powers([1, 2, 3, 4], [2100,2300,2200,2100])
reader.set_region("EU3")
reader.set_read_plan([1,2,3],"GEN2")
reader.set_gen2_session(0)
reader.set_gen2_q(0,2)
print("start")
reader.start_reading(lambda tag: print(tag.epc))
tm.sleep(2)
reader.stop_reading()
print("end")
I do not receive any error message however it forces us to restart the shell as shown in this image:
Do you have any idea how to fix it?
thank's
Hi,
it would be useful if the python api has a feature to read the chip temperature.
I think the c++ library has this feature, so maybe it is possible to support this in python too.
Regards,
Jan
Hi, when I try to connect the reader I get a message saying: "Key Error". In the previous version I could connect without problems. How do I connect a reader that is on a network, not connected to the computer? In the old version, i use the command: mercury.Reader("tmr://m6-2128e5"), but doesn't work anymore.
Hi, you're currently saving me a lot of work on my current project (thank you!), but I've got some issues with converting the list of byte strings.
I want to compare a list of known ID's with the tags that are being seen, and get the location of the seen tags in the known tags-list.
I keep running into the issue that the list with byte strings doesn't seem to be a real list, and it keeps referring to mercury.TagReadData (TypeError: 'mercury.TagReadData' object is not subscriptable). Also, doing it like this (below) also does not work, the output is always false. So I think the output from reader.read() might not be a normal list but something else?
# importing libraries
import threading
import time
import mercury
import collections
# set-up for the connected reader
reader = mercury.Reader("tmr:///dev/ttyS0", baudrate=115200)
print(reader.get_model()) # print the model to see if it's working
reader.set_region("EU3") # set a region to work with
reader.set_read_plan([1], "GEN2", read_power=1900)
# Below should be the IDs of the RFID tags!
knownIDs = [b'E2000015860E01451120AB56',
b'48656C6C6F2101591120AB75',
b'E2000015860E01601120AB6E',
b'E2000015860E01611120AB76']
def readTags():
threading.Timer(0.15, readTags).start()
# this reads all of them in one go within the given time limit, and puts them in the CurIDs list
incomingIDs = reader.read(timeout=100)
print (list(incomingIDs))
print ("length of list is", len(incomingIDs))
# comparing lists, output the location of the found IDs within knownIDs
print (b'E2000015860E01451120AB56' in incomingIDs)
readTags()
Thanks in advance!
Hey Guys,
I have achieved in reading epc asynchrouns.
In the How To i read that with the bank="user" parameter, I can read userdata that I have written to the tags.
But the following code just does nothing:
`import mercury
reader = mercury.Reader("tmr:///dev/ttyUSB0")
reader.set_region("EU3")
reader.set_read_plan([1], "GEN2", bank=["user"],read_power=500)
reader.start_reading(lambda tag: print(tag.user_mem_data))
`
Any ideas?
for the installation instruction, i tried and it showed:
better to run:
```python3 setup.py install
as well
Hi!
I already have runing in a Python proyect in Windows 10 and it's works perfect!
But... i need to have the same running in a Windows 10 IOT, but when i deploy form Visual Studio 2015 (the same proyecto what it's ok over Windows 10) i have a Error "mercury module not found"... i guest what i need a Raspberry compiled version of the wrapper.... any help?
Regards!!
PD: Grate job done with the library...
PD2: Sorry my terrible english
Hi, I tried the 3.5 installer and it works, but we need a 3.6 installer for our project.
Do you have this 3.6 installer or do you know how to make it works without create a parallel 3.5 service?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.