Class: NFC::Reader
- Inherits:
-
Object
- Object
- NFC::Reader
- Defined in:
- lib/nfc.rb
Overview
}}}
Instance Attribute Summary collapse
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#serialnr ⇒ Object
readonly
Returns the value of attribute serialnr.
Instance Method Summary collapse
-
#command(cmd) ⇒ Object
}}}.
-
#command_print(cmd) ⇒ Object
}}}.
-
#initialize(tty = "/dev/ttyUSB0") ⇒ Reader
constructor
{{{.
-
#poll(&bl) ⇒ Object
}}}.
-
#read_once ⇒ Object
}}}.
-
#stop_poll ⇒ Object
}}}.
Constructor Details
#initialize(tty = "/dev/ttyUSB0") ⇒ Reader
{{{
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/nfc.rb', line 81 def initialize(tty = "/dev/ttyUSB0") #{{{ @reader = NFC.nfc_reader_init(tty) @thread = nil @serialnr = nil command('x') # begin # @serialnr = command('b') # end while @serialnr == nil # @serialnr = @serialnr.unpack("C*").map{|e| "%02x" % e}.join Signal::trap("INT") do puts 'stopping...' if @thread stop_poll @thread.kill end end end |
Instance Attribute Details
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
79 80 81 |
# File 'lib/nfc.rb', line 79 def reader @reader end |
#serialnr ⇒ Object (readonly)
Returns the value of attribute serialnr.
80 81 82 |
# File 'lib/nfc.rb', line 80 def serialnr @serialnr end |
Instance Method Details
#command(cmd) ⇒ Object
}}}
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/nfc.rb', line 100 def command( cmd) #{{{ obj = Struct.new(@reader) temp = nil while temp.nil? do NFC.nfc_set_cmd(@reader,cmd) NFC.nfc_reader_do(@reader) if (obj[:reddit].read_string(obj[:reddit_len])[3..-3]== nil) temp = nil else temp=Result.new(obj[:reddit].read_string(obj[:reddit_len])[3..-3]) end temp = true if cmd=='x' end temp end |
#command_print(cmd) ⇒ Object
}}}
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/nfc.rb', line 116 def command_print(cmd) #{{{ obj = Struct.new(@reader) NFC.nfc_set_cmd(@reader,cmd) NFC.nfc_reader_do(@reader) if (obj[:reddit].read_string(obj[:reddit_len])[3..-3]== nil) temp = nil else temp=Result.new(obj[:reddit].read_string(obj[:reddit_len])[3..-3]) end p temp end |
#poll(&bl) ⇒ Object
}}}
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/nfc.rb', line 134 def poll(&bl) #{{{ pr = Proc.new do |obj| obj = Struct.new(@reader) bl.call(Result.new(obj[:reddit].read_string(obj[:reddit_len])[3..-3])) end NFC.nfc_reader_on_tag(@reader,pr) command('dp') NFC.nfc_reader_poll(@reader) @thread = Thread.new { Thread::stop } @thread.join end |
#read_once ⇒ Object
}}}
128 129 130 |
# File 'lib/nfc.rb', line 128 def read_once #{{{ NFC.nfc_reader_1_read(@reader) end |
#stop_poll ⇒ Object
}}}
131 132 133 |
# File 'lib/nfc.rb', line 131 def stop_poll #{{{ NFC.nfc_reader_stop_poll(@reader) end |