Class: Modbus::PDU::ReadRegistersResponse
- Inherits:
-
Modbus::PDU
- Object
- Modbus::PDU
- Modbus::PDU::ReadRegistersResponse
- Defined in:
- lib/modbus/pdu/read_registers.rb
Overview
Base class PDU for modbus register based functions (response message)
Direct Known Subclasses
Constant Summary
Constants inherited from Modbus::PDU
Instance Attribute Summary collapse
-
#reg_values ⇒ Object
Returns the value of attribute reg_values.
Attributes inherited from Modbus::PDU
Instance Method Summary collapse
-
#byte_count ⇒ Integer
Returns the length of the register values in bytes.
-
#decode(data) ⇒ Object
Decodes a PDU from protocol data.
-
#encode ⇒ Modbus::ProtocolData
Encodes a PDU into protocol data.
-
#initialize(data = nil, func_code = nil) ⇒ ReadRegistersResponse
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) ⇒ ReadRegistersResponse
Initializes a new PDU instance. Decodes from protocol data if given.
76 77 78 79 |
# File 'lib/modbus/pdu/read_registers.rb', line 76 def initialize(data = nil, func_code = nil) @reg_values = [] super end |
Instance Attribute Details
#reg_values ⇒ Object
Returns the value of attribute reg_values.
69 70 71 |
# File 'lib/modbus/pdu/read_registers.rb', line 69 def reg_values @reg_values end |
Instance Method Details
#byte_count ⇒ Integer
Returns the length of the register values in bytes.
108 109 110 |
# File 'lib/modbus/pdu/read_registers.rb', line 108 def byte_count @reg_values.size * 2 end |
#decode(data) ⇒ Object
Decodes a PDU from protocol data.
86 87 88 89 |
# File 'lib/modbus/pdu/read_registers.rb', line 86 def decode(data) byte_count = data.shift_byte byte_count.div(2).times { @reg_values.push data.shift_word } end |
#encode ⇒ Modbus::ProtocolData
Encodes a PDU into protocol data.
96 97 98 99 100 101 |
# File 'lib/modbus/pdu/read_registers.rb', line 96 def encode data = super data.push_byte byte_count @reg_values.each { |value| data.push_word value } data end |
#length ⇒ Integer
Returns the length of the PDU in bytes.
117 118 119 120 |
# File 'lib/modbus/pdu/read_registers.rb', line 117 def length # +1 for func_code, +1 for byte_count byte_count + 2 end |
#validate ⇒ Object
Validates the PDU. Raises exceptions if validation fails.
125 126 127 |
# File 'lib/modbus/pdu/read_registers.rb', line 125 def validate end |