Class: PhidgetRfid::RfidHandler
- Inherits:
-
Object
- Object
- PhidgetRfid::RfidHandler
- Defined in:
- lib/phidget_rfid/rfid_handler.rb
Instance Attribute Summary collapse
-
#log ⇒ Object
Returns the value of attribute log.
Instance Method Summary collapse
- #device ⇒ Object
-
#initialize ⇒ RfidHandler
constructor
A new instance of RfidHandler.
- #protocol ⇒ Object
- #read ⇒ Object
- #write(value, protocol = nil, lock = false) ⇒ Object
Constructor Details
#initialize ⇒ RfidHandler
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/phidget_rfid/rfid_handler.rb', line 8 def initialize() @phidget = Phidgets::RFID.new @time = Time.new @prompt = "at #{@time.strftime("%Y-%m-%d %H:%M:%S")} \033[0m" @log = "" @phidget.on_detach do |device, obj| @log.append "\n#{device.attributes.inspect} removed" end @phidget.on_attach do |device, obj| @phidget.antenna = true @phidget.led = false end @phidget.on_error do |device, obj, code, description| @log << "\033[31m\nError #{code}: #{description} #{@prompt}" end @phidget.on_tag do |device, tag, obj| @phidget.led = true @log << "\n\033[32m[+] #{protocol} tag detected #{@prompt}" end @phidget.on_tag_lost do |device, tag, obj| @phidget.led = false @log << "\n\033[33m[-] #{protocol} tag removed #{@prompt}" end end |
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
6 7 8 |
# File 'lib/phidget_rfid/rfid_handler.rb', line 6 def log @log end |
Instance Method Details
#device ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/phidget_rfid/rfid_handler.rb', line 79 def device puts "Library Version: #{Phidgets::FFI.library_version}" puts "Class: #{@phidget.device_class}" puts "Id: #{@phidget.id}" puts "Serial number: #{@phidget.serial_number}" puts "Digital Outputs: #{@phidget.outputs.size}" end |
#protocol ⇒ Object
40 41 42 43 44 |
# File 'lib/phidget_rfid/rfid_handler.rb', line 40 def protocol if(@phidget.attached?) @phidget.last_tag_protocol end end |
#read ⇒ Object
46 47 48 49 50 |
# File 'lib/phidget_rfid/rfid_handler.rb', line 46 def read if(@phidget.attached?) @phidget.last_tag end end |
#write(value, protocol = nil, lock = false) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/phidget_rfid/rfid_handler.rb', line 52 def write(value, protocol = nil, lock = false) if (protocol == nil) protocol = if @phidget.tag_present @phidget.last_tag_protocol else "EM4100" end end if(@phidget.attached?) p = protocol.to_sym if lock puts "Data: #{value}" puts "Protocol: #{p}" puts "Are you sure you want to lock the RFID Tag? This will make it read-only (y/N)" r = gets.chomp @phidget.write(value, p, true) if r == "y" else @phidget.write(value, p) end end end |