Class: Modbus::PDU::WriteMultipleRegistersResponse
- Inherits:
-
Modbus::PDU
- Object
- Modbus::PDU
- Modbus::PDU::WriteMultipleRegistersResponse
- Defined in:
- lib/modbus/pdu/write_multiple_registers.rb
Overview
PDU for modbus function “read holding register” (response message)
Constant Summary collapse
- FUNC_CODE =
0x10
Constants inherited from Modbus::PDU
Instance Attribute Summary collapse
-
#reg_count ⇒ Object
Returns the value of attribute reg_count.
-
#start_addr ⇒ Object
Returns the value of attribute start_addr.
Attributes inherited from Modbus::PDU
Instance Method Summary collapse
-
#decode(data) ⇒ Object
Decodes a PDU from protocol data.
-
#encode ⇒ Modbus::ProtocolData
Encodes a PDU into protocol data.
-
#initialize(data = nil, func_code = nil) ⇒ WriteMultipleRegistersResponse
constructor
Initializes a new PDU instance.
-
#length ⇒ Integer
Returns the length of the PDU in bytes.
-
#validate ⇒ Object
Validates the PDU.
Methods inherited from Modbus::PDU
Constructor Details
#initialize(data = nil, func_code = nil) ⇒ WriteMultipleRegistersResponse
Initializes a new PDU instance. Decodes from protocol data if given.
108 109 110 111 112 |
# File 'lib/modbus/pdu/write_multiple_registers.rb', line 108 def initialize(data = nil, func_code = nil) @start_addr = 0 @reg_count = 0 super end |
Instance Attribute Details
#reg_count ⇒ Object
Returns the value of attribute reg_count.
101 102 103 |
# File 'lib/modbus/pdu/write_multiple_registers.rb', line 101 def reg_count @reg_count end |
#start_addr ⇒ Object
Returns the value of attribute start_addr.
101 102 103 |
# File 'lib/modbus/pdu/write_multiple_registers.rb', line 101 def start_addr @start_addr end |
Instance Method Details
#decode(data) ⇒ Object
Decodes a PDU from protocol data.
119 120 121 122 |
# File 'lib/modbus/pdu/write_multiple_registers.rb', line 119 def decode(data) @start_addr = data.shift_word @reg_count = data.shift_word end |
#encode ⇒ Modbus::ProtocolData
Encodes a PDU into protocol data.
129 130 131 132 133 134 |
# File 'lib/modbus/pdu/write_multiple_registers.rb', line 129 def encode data = super data.push_word @start_addr data.push_word @reg_count data end |
#length ⇒ Integer
Returns the length of the PDU in bytes.
141 142 143 |
# File 'lib/modbus/pdu/write_multiple_registers.rb', line 141 def length 5 end |
#validate ⇒ Object
Validates the PDU. Raises exceptions if validation fails.
148 149 150 |
# File 'lib/modbus/pdu/write_multiple_registers.rb', line 148 def validate fail ClientError, "Register count must be in (1..127), got '#{@reg_count.inspect}'" unless (1..127).include?(@reg_count) end |