Skip to content

Instantly share code, notes, and snippets.

@danasf
Created May 10, 2014 20:32
Show Gist options
  • Select an option

  • Save danasf/3693bcdf38b6e8cd4649 to your computer and use it in GitHub Desktop.

Select an option

Save danasf/3693bcdf38b6e8cd4649 to your computer and use it in GitHub Desktop.
Samsys RFID
# Work with the Samsys 2.8 RFID reader over serial, strip out dupe output
# Adapted from a threaded serial "chat" snippet
# http://stackoverflow.com/questions/10465952/python-chat-program-for-serial-port-connection-rs-232
#
# Default port and baudrate are /dev/serial/by-id/usb-Keyspan__a_division_of_InnoSys_Inc._Keyspan_USA-19H-if00-port0 and 57600
#
# Refer to CHUMP command reference for commands, include ! at end of your command
# http://www.sirit.com/Tech_Support_Downloads/CHUMP_Prot_Ref_Gd_v7.0[1].pdf
# in the future you can enable script to generate proper cmd checksum
#
# this is what the serial data looks like: (it repeats constantly while the tag is nearby)
# {Rd,d:3005FB63AC1F3841EC880467,t:EPC1G2,e:28;14
#
# Quiet a given tag from the output:
#}Ht,d:[ID]!
#
#Read a given memory block for any tag in field
#
#}Ra,a:[block],s:[offset](,l:[length])!
# More details: https://noisebridge.net/wiki/Rfid
#
from serial import *
from threading import Thread
class Receiver(Thread):
def __init__(self, serialPort):
Thread.__init__(self)
self.serialPort = serialPort
def run(self):
text = ""
oldText=""
while (text != "exit\n"):
text = serialPort.readline()
if(oldText != text):
print ("reader: " + text)
oldText = text;
self.serialPort.close()
class Sender(Thread):
def __init__(self, serialPort):
Thread.__init__(self)
self.serialPort = serialPort
def run(self):
text = ""
while(text != "exit\n"):
text = raw_input("Send your command>>")
# command + ; + first two chars of checksum + break
#sendMe = text + checksum(text) +"\r\n"
sendMe = text+"\n"
self.serialPort.write(sendMe)
self.serialPort.close()
# generate proper CHUMP command checksum, you need to add a ; after your cmd
#def checksum(str):
# chk=0;
# for c in str:
# tmp=ord(c)
# chk=chk+tmp
# chk = hex(chk)
# return chk[-2:]
serialPort = Serial("/dev/serial/by-id/usb-Keyspan__a_division_of_InnoSys_Inc._Keyspan_USA-19H-if00-port0 ",57600)
send = Sender(serialPort)
receive = Receiver(serialPort)
send.start()
receive.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment