class Modbus::PDU::ReadRegistersResponse
Base class PDU
for modbus register based functions (response message)
Attributes
reg_values[RW]
Public Class Methods
new(data = nil, func_code = nil)
click to toggle source
Initializes a new PDU
instance. Decodes from protocol data if given.
@param data [Modbus::ProtocolData] The protocol data to decode.
Calls superclass method
Modbus::PDU::new
# File lib/modbus/pdu/read_registers.rb, line 76 def initialize(data = nil, func_code = nil) @reg_values = [] super end
Public Instance Methods
byte_count()
click to toggle source
Returns the length of the register values in bytes.
@return [Integer] The length.
# File lib/modbus/pdu/read_registers.rb, line 108 def byte_count @reg_values.size * 2 end
decode(data)
click to toggle source
Decodes a PDU
from protocol data.
@param data [Modbus::ProtocolData] The protocol data to decode.
# 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()
click to toggle source
Encodes a PDU
into protocol data.
@return [Modbus::ProtocolData] The protocol data representation of this object.
Calls superclass method
Modbus::PDU#encode
# 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()
click to toggle source
Returns the length of the PDU
in bytes.
@return [Integer] The length.
# File lib/modbus/pdu/read_registers.rb, line 117 def length # +1 for func_code, +1 for byte_count byte_count + 2 end
validate()
click to toggle source
Validates the PDU
. Raises exceptions if validation fails.
# File lib/modbus/pdu/read_registers.rb, line 125 def validate end