Demonstration script.

This commit is contained in:
Mikaël Ates 2013-05-24 17:11:57 +02:00
parent 4c9152fe56
commit 0640ed9d99
1 changed files with 93 additions and 0 deletions

93
demo.py Executable file
View File

@ -0,0 +1,93 @@
#!/usr/bin/env python
'''
librfid - RFID EPC Class 1 Gen2 / ISO/IEC 18000-6C compliant library
Copyright (C) 2013 Entr'ouvert
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Demo
'''
import models
import utils
import core_standard
from stid_readers import core as stid_core
if __name__ == '__main__':
reader = models.RFIDReader()
try:
command = models.ReaderCommand(command_name='Get_RFSettings',
reader=reader)
response = reader.send(command)
command.pretty_print()
response.pretty_print()
logic_ports = stid_core.get_rfsettings(response)
i = 0
for logic_port in logic_ports:
if logic_port['ScanDelay'] or logic_port['PowerAnt']:
print "Logic port: %s" % i
print "\tScanDelay: %s ms" % logic_port['ScanDelay']
print "\tPowerAnt: %s dBm" % logic_port['PowerAnt']
print "\tAntNb: %s" % logic_port['AntNb']
i += 1
except Exception, err:
print str(err)
try:
logic_port = {\
'ScanDelay': 700,
'PowerAnt': 31,
'AntNb': 0,
}
logic_ports = [logic_port]
data = stid_core.set_rfsettings(logic_ports)
command = models.ReaderCommand(command_name='Set_RFSettings',
reader=reader, data=data)
response = reader.send(command)
command.pretty_print()
response.pretty_print()
except Exception, err:
print str(err)
try:
command = models.ReaderCommand(command_name='Get_RFSettings',
reader=reader)
response = reader.send(command)
command.pretty_print()
response.pretty_print()
logic_ports = stid_core.get_rfsettings(response)
i = 0
for logic_port in logic_ports:
if logic_port['ScanDelay'] or logic_port['PowerAnt']:
print "Logic port: %s" % i
print "\tScanDelay: %s ms" % logic_port['ScanDelay']
print "\tPowerAnt: %s dBm" % logic_port['PowerAnt']
print "\tAntNb: %s" % logic_port['AntNb']
i += 1
except Exception, err:
print str(err)
try:
command = models.Command(command_name='Inventory')
response = reader.send(command)
command.pretty_print()
response.pretty_print()
tags = core_standard.inventory(response)
for tag in tags:
print "Tag: %s" % tag['EPC'].encode('hex')
print "\t Read on logic port: %s" % tag['AntID']
print "\t Times read on all logic ports: %s" % tag['NbRead']
except Exception, err:
print str(err)