Class: Modbus::WordRegister

Inherits:
Register show all
Defined in:
lib/modbus/register/word_register.rb

Instance Attribute Summary collapse

Attributes inherited from Register

#addr, #handler

Instance Method Summary collapse

Constructor Details

#initialize(addr) ⇒ WordRegister

Returns a new instance of WordRegister.



12
13
14
15
# File 'lib/modbus/register/word_register.rb', line 12

def initialize(addr)
  super
  @value = 0
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/modbus/register/word_register.rb', line 9

def value
  @value
end

Instance Method Details

#update(value) ⇒ Object



18
19
20
21
# File 'lib/modbus/register/word_register.rb', line 18

def update(value)
  fail ArgumentError unless (0..65535).include? value
  @value = value
end

#write(value) ⇒ Object



24
25
26
# File 'lib/modbus/register/word_register.rb', line 24

def write(value)
  @handler.write_values [{:addr => @addr.to_s, :value => value}] if @handler
end