Class: GPSTool::Device
- Inherits:
-
Object
- Object
- GPSTool::Device
- Defined in:
- lib/gpstool/device.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_io ⇒ Object
- #close ⇒ Object
-
#initialize(io, options = {}) ⇒ Device
constructor
A new instance of Device.
- #read_message(&block) ⇒ Object
- #send_message(message) ⇒ Object
Constructor Details
#initialize(io, options = {}) ⇒ Device
Returns a new instance of Device.
11 12 13 14 15 16 |
# File 'lib/gpstool/device.rb', line 11 def initialize(io, = {}) @io = io @errors = 0 @options = end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
19 20 21 |
# File 'lib/gpstool/device.rb', line 19 def errors @errors end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
18 19 20 |
# File 'lib/gpstool/device.rb', line 18 def io @io end |
Class Method Details
.open(path, options = {}) ⇒ Object
7 8 9 |
# File 'lib/gpstool/device.rb', line 7 def self.open(path, = {}) return self.new(File.open(path, "rb+"), ) end |
Instance Method Details
#clear_io ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gpstool/device.rb', line 25 def clear_io # Consume any pre-existing data pipes = nil while (pipes = IO.select([@io], [], [], 0.1)) puts pipes.inspect buf = @io.read_nonblock(1024) $stderr.puts "(clear) -> " + buf.dump end end |
#close ⇒ Object
21 22 23 |
# File 'lib/gpstool/device.rb', line 21 def close @io.close end |
#read_message(&block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gpstool/device.rb', line 45 def (&block) = @options[:message_class] || Message while true begin = .read(@io, @options) return unless yield rescue @errors += 1 raise end end end |