Class: OneWire::Device

Inherits:
Object
  • Object
show all
Includes:
Retry
Defined in:
lib/one_wire/device.rb

Instance Method Summary collapse

Methods included from Retry

#with_retry

Constructor Details

#initialize(address, options = {}) ⇒ Device

Returns a new instance of Device.



5
6
7
8
9
# File 'lib/one_wire/device.rb', line 5

def initialize(address, options = {})
  @options = options
  @path = options[:uncached] ? "/uncached/#{address}" : "/#{address}"
  @path.squeeze!("/")
end

Instance Method Details

#dirObject



26
27
28
# File 'lib/one_wire/device.rb', line 26

def dir
  Directory.new(@path)
end

#present?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
# File 'lib/one_wire/device.rb', line 11

def present?
  Transaction.presence(@path, @options)
  true
rescue Errno::ENOENT
  false
end

#read(attribute) ⇒ Object



18
19
20
# File 'lib/one_wire/device.rb', line 18

def read(attribute)
  with_retry { Transaction.read("#{@path}/#{attribute}").response.data || raise(BadRead) }
end

#write(attribute, value) ⇒ Object



22
23
24
# File 'lib/one_wire/device.rb', line 22

def write(attribute, value)
  with_retry { Transaction.write("#{@path}/#{attribute}", value) }
end