Class: NFC::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/nfc.rb

Overview

}}}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tty = "/dev/ttyUSB0", mem_len = 36) ⇒ Reader

{{{



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/nfc.rb', line 56

def initialize(tty = "/dev/ttyUSB0",mem_len=36) #{{{
  @reader = NFC.nfc_reader_init(tty,mem_len)
  @thread = nil
  @serialnr = nil
  command('x')

  begin
    @serialnr = command('b')
  end while @serialnr == nil
  p "SERIAL"
  p @serialnr
  p '-' * 24
  Signal::trap("INT") do
    puts 'stopping...'
    stop_poll
    @thread.kill
  end
end

Instance Attribute Details

#readerObject (readonly)

Returns the value of attribute reader.



54
55
56
# File 'lib/nfc.rb', line 54

def reader
  @reader
end

#serialnrObject

Returns the value of attribute serialnr.



55
56
57
# File 'lib/nfc.rb', line 55

def serialnr
  @serialnr
end

Instance Method Details

#command(cmd) ⇒ Object

}}}



75
76
77
78
79
80
# File 'lib/nfc.rb', line 75

def command( cmd) #{{{
  obj = Struct.new(@reader)
  NFC.nfc_set_cmd(@reader,cmd)
  NFC.nfc_reader_do(@reader)
  obj[:reddit].read_string(obj[:reddit_len])[3..-3] 
end

#command_print(cmd) ⇒ Object

}}}



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/nfc.rb', line 82

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

}}}



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/nfc.rb', line 100

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_onceObject

}}}



94
95
96
# File 'lib/nfc.rb', line 94

def read_once #{{{
  NFC.nfc_reader_1_read(@reader)
end

#stop_pollObject

}}}



97
98
99
# File 'lib/nfc.rb', line 97

def stop_poll #{{{
  NFC.nfc_reader_stop_poll(@reader)
end