Class: Phidgets::RFID
- Inherits:
-
Object
- Object
- Phidgets::RFID
- Includes:
- Common
- Defined in:
- lib/phidgets-ffi/rfid.rb
Overview
This class represents a CPhidgetRFID.
Defined Under Namespace
Classes: RFIDOutputs
Constant Summary collapse
- Klass =
Phidgets::FFI::CPhidgetRFID
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
The attributes of a PhidgetRFID.
-
#outputs ⇒ RFIDOutputs
readonly
Collection of digital outputs.
Instance Method Summary collapse
-
#antenna ⇒ Boolean
Returns the antenna state of the Phidget.
-
#antenna=(new_state) ⇒ Boolean
Sets the antenna state of the Phidget.
-
#last_tag ⇒ String
Returns the last tag read by the reader.
-
#last_tag_protocol ⇒ Phidgets::FFI::RFIDTagProtocol
Returns the last tag protocol or raises an error.
-
#led ⇒ Boolean
Returns the LED state.
-
#led=(new_state) ⇒ Boolean
Sets the LED.
-
#on_output_change(obj = nil, &block) ⇒ Boolean
Sets an output change handler callback function.
-
#on_tag(obj = nil, &block) ⇒ Boolean
Sets a tag handler callback function.
-
#on_tag_lost(obj = nil, &block) ⇒ Boolean
Sets a tag lost handler callback function.
-
#tag_present ⇒ Boolean
Returns a value indicating whether or not a tag is on the reader, or raises an error.
-
#write(tag, protocol, lock = false) ⇒ Boolean
Writes to a tag.
Methods included from Common
#attached?, #attached_to_server?, attributes, #close, #detached?, #detached_to_server?, device_class, #device_class, device_id, #id, #initialize, #label, #label=, #name, #on_attach, #on_detach, #on_error, #on_server_connect, #on_server_disconnect, #on_sleep, #on_wake, #serial_number, #server_address, server_address, #server_id, server_id, server_status, #type, #version, #wait_for_attachment
Instance Attribute Details
#attributes ⇒ Object (readonly)
The attributes of a PhidgetRFID
16 17 18 |
# File 'lib/phidgets-ffi/rfid.rb', line 16 def attributes @attributes end |
#outputs ⇒ RFIDOutputs (readonly)
Collection of digital outputs
11 12 13 |
# File 'lib/phidgets-ffi/rfid.rb', line 11 def outputs @outputs end |
Instance Method Details
#antenna ⇒ Boolean
Returns the antenna state of the Phidget.
81 82 83 84 85 |
# File 'lib/phidgets-ffi/rfid.rb', line 81 def antenna ptr = ::FFI::MemoryPointer.new(:int) Klass.getAntennaOn(@handle, ptr) (ptr.get_int(0) == 0) ? false : true end |
#antenna=(new_state) ⇒ Boolean
Sets the antenna state of the Phidget. True turns the antenna on, false turns it off. The antenna if by default turned off, and needs to be explicitely activated before tags can be read. Control over the antenna allows multiple readers to be used in close proximity, as multiple readers will interfere with each other if their antenna’s are activated simultaneously.
90 91 92 93 94 |
# File 'lib/phidgets-ffi/rfid.rb', line 90 def antenna=(new_state) tmp = new_state ? 1 : 0 Klass.setAntennaOn(@handle, tmp) new_state end |
#last_tag ⇒ String
Returns the last tag read by the reader. This may or may not still be on the reader - use #tag_present to find out.
117 118 119 120 121 122 123 |
# File 'lib/phidgets-ffi/rfid.rb', line 117 def last_tag tag = ::FFI::MemoryPointer.new(:string) proto = ::FFI::MemoryPointer.new(:int) Klass.getLastTag2(@handle, tag, proto) strPtr = tag.get_pointer(0) strPtr.null? ? nil : strPtr.read_string end |
#last_tag_protocol ⇒ Phidgets::FFI::RFIDTagProtocol
Returns the last tag protocol or raises an error
128 129 130 131 132 133 |
# File 'lib/phidgets-ffi/rfid.rb', line 128 def last_tag_protocol tag = ::FFI::MemoryPointer.new(:string) proto = ::FFI::MemoryPointer.new(:int) Klass.getLastTag2(@handle, tag, proto) Phidgets::FFI::RFIDTagProtocol[proto.get_int(0)] end |
#led ⇒ Boolean
Returns the LED state.
99 100 101 102 103 |
# File 'lib/phidgets-ffi/rfid.rb', line 99 def led ptr = ::FFI::MemoryPointer.new(:int) Klass.getLEDOn(@handle, ptr) (ptr.get_int(0) == 0) ? false : true end |
#led=(new_state) ⇒ Boolean
Sets the LED. True turns the LED on, false turns it off. The LED is by default turned off.
108 109 110 111 112 |
# File 'lib/phidgets-ffi/rfid.rb', line 108 def led=(new_state) tmp = new_state ? 1 : 0 Klass.setLEDOn(@handle, tmp) new_state end |
#on_output_change(obj = nil, &block) ⇒ Boolean
Sets an output change handler callback function. This is called when a digital output on the PhidgetRFID board has changed.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
34 35 36 37 38 39 40 |
# File 'lib/phidgets-ffi/rfid.rb', line 34 def on_output_change(obj=nil, &block) @on_output_change_obj = obj @on_output_change = Proc.new { |device, obj_ptr, index, state| yield self, @outputs[index], (state == 0 ? false : true), object_for(obj_ptr) } Klass.set_OnOutputChange_Handler(@handle, @on_output_change, pointer_for(obj)) end |
#on_tag(obj = nil, &block) ⇒ Boolean
Sets a tag handler callback function. This is called when a new tag is seen by the reader. The event is only fired one time for a new tag, so the tag has to be removed and then replaced before another tag gained event will fire.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
52 53 54 55 56 57 58 |
# File 'lib/phidgets-ffi/rfid.rb', line 52 def on_tag(obj=nil, &block) @on_tag_obj = obj @on_tag = Proc.new { |device, obj_ptr, tag, proto| yield self, tag.read_string, object_for(obj_ptr) } Klass.set_OnTag2_Handler(@handle, @on_tag, pointer_for(obj)) end |
#on_tag_lost(obj = nil, &block) ⇒ Boolean
Sets a tag lost handler callback function. This is called when a tag is removed from the reader
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
70 71 72 73 74 75 76 |
# File 'lib/phidgets-ffi/rfid.rb', line 70 def on_tag_lost(obj=nil, &block) @on_tag_lost_obj = obj @on_tag_lost = Proc.new { |device, obj_ptr, tag, proto| yield self, tag.read_string, object_for(obj_ptr) } Klass.set_OnTagLost2_Handler(@handle, @on_tag_lost, pointer_for(obj)) end |
#tag_present ⇒ Boolean
Returns a value indicating whether or not a tag is on the reader, or raises an error
138 139 140 141 142 |
# File 'lib/phidgets-ffi/rfid.rb', line 138 def tag_present ptr = ::FFI::MemoryPointer.new(:int) Klass.getTagStatus(@handle, ptr) (ptr.get_int(0) == 0) ? false : true end |
#write(tag, protocol, lock = false) ⇒ Boolean
Writes to a tag.
150 151 152 153 154 |
# File 'lib/phidgets-ffi/rfid.rb', line 150 def write(tag, protocol, lock=false) tmp = lock ? 1 : 0 Klass.write(@handle, tag, Phidgets::FFI::RFIDTagProtocol[protocol], tmp) true end |