Tuesday, 9 July 2013

Speedway Revolution 420 RFID Tag Reader in Python

So I recently was working on connecting a piece of software to a reader via a socket.

The vendors had a great script for connecting to it via ruby, as shown in the code below:

require 'socket'

s = TCPSocket.new '192.168.2.165', 14150

while line = s.gets
    puts line.chop
end

s.close


This code is available, you can see it here in the video:
http://learn.impinj.com/articles/en_US/RFID/Reading-Tags-over-TCP-IP-Socket-Using-Speedway-Connect-Software/

The site presents .NET code for connecting as well. However, as I do most of my work in python, I figured I'd keep things simple and convert their script to it.

---

The reason I'm writing this post is because I had one hell of a time getting to the point where it *would* read, because it would keep failing on the connect() method and from then on, I would have a Connection Refused error whenever I ran the python OR the ruby script. If you are having troubles with the Speedway Revolution 420 reader, know this:

* If you get Connection Refused errors, you need to browse to the ReaderConnect software, found at the reader ip address on port 8080. Click the save button, even if you haven't made any changes. This will allow connections to be received again, as I imagine it closes whatever broken connection python has left behind.
* You must use python 2.7 (or 2.x series, though I haven't tested beyond that) in order for it to run. When my code was failing, the header was "#!/usr/bin/env python", which on my linux mint system, would default to python 3. It was only until I *explicitly* stated "#!/usr/bin/env python2.7" that it miraculously worked. Here is the code:

#!/usr/bin/env python2.7

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.2.165", 14150))

data = s.recv(1024)
data = data.strip('\n')
while 1:
    print data
    data = s.recv(1024)
    data = data.strip('\n')
    
s.shutdown(socket.SHUT_RD)
s.close()


It makes two assumptions:

1. You want to read 1024 bytes. 0 does NOT work, it leaves me with an empty screen because the data variable does not get assigned to anything more than an empty string.
2. If you set the output to Linefeed, or Carriage Return Linefeed, this script will work. If you don't set the line ending value in the Output tab, there could be some issues.

Hopefully this script can help someone, someday.

5 comments:

  1. Nice script. Could you help me to store the tag directly to MySQL database. To be there as soon as it was read?

    Now I use the function "upload to web" in Speedway Connect, which can be repeated only by 1 sec. Thank you. Regards Jiri

    ReplyDelete
  2. Hi, I am a Solution Engineer with Impinj. I believe the reason you had to click 'Save' is because you did not have a valid Speedway Connect license so it was running in demo mode which allows for 500 tag reads and then disables until you hit 'Save' (or 'Apply' in the latest version) which then resets demo mode for another 500 reads.
    You can inquire with the vendor where you purchased your reader on aquiring a Speedway Connect license or, if you are an Impinj partner, or would like to become one, then email to support@impinj.com
    -Lou Parker

    ReplyDelete
  3. "If you get Connection Refused errors, you need to browse to the ReaderConnect software, found at the reader ip address on port 8080. Click the save button, even if you haven't made any changes." -Which software is reader connect. I have installed multireader. Also can you share any screenshot or explain in detail. I am getting connection refused error for python . Error 10061

    ReplyDelete
  4. you need to browse to the ReaderConnect software, found at the reader ip address on port 8080. RFID cards

    ReplyDelete
  5. i am getting below output only no proper tag read

    ? #?|???
    ??e3a\

    ReplyDelete