class Modbus::PDU::ReadRegistersRequest
Base class PDU
for modbus register based functions (request message)
Attributes
reg_count[RW]
start_addr[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 19 def initialize(data = nil, func_code = nil) @start_addr = 0 @reg_count = 0 super end
Public Instance Methods
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 30 def decode(data) @start_addr = data.shift_word @reg_count = 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 40 def encode data = super data.push_word @start_addr data.push_word @reg_count 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 52 def length 5 end
validate()
click to toggle source
Validates the PDU
. Raises exceptions if validation fails.
# File lib/modbus/pdu/read_registers.rb, line 59 def validate fail ClientError, "Register count must be in (1..127), got '#{@reg_count.inspect}'" unless (1..127).include?(@reg_count) end