Class: Modbus::PDU::ReadRegistersRequest
- Inherits:
-
Modbus::PDU
- Object
- Modbus::PDU
- Modbus::PDU::ReadRegistersRequest
- Defined in:
- lib/modbus/pdu/read_registers.rb
Overview
Base class PDU for modbus register based functions (request message)
Direct Known Subclasses
Constant Summary
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) ⇒ ReadRegistersRequest
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) ⇒ ReadRegistersRequest
Initializes a new PDU instance. Decodes from protocol data if given.
19 20 21 22 23 |
# File 'lib/modbus/pdu/read_registers.rb', line 19 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.
12 13 14 |
# File 'lib/modbus/pdu/read_registers.rb', line 12 def reg_count @reg_count end |
#start_addr ⇒ Object
Returns the value of attribute start_addr.
12 13 14 |
# File 'lib/modbus/pdu/read_registers.rb', line 12 def start_addr @start_addr end |
Instance Method Details
#decode(data) ⇒ Object
Decodes a PDU from protocol data.
30 31 32 33 |
# File 'lib/modbus/pdu/read_registers.rb', line 30 def decode(data) @start_addr = data.shift_word @reg_count = data.shift_word end |
#encode ⇒ Modbus::ProtocolData
Encodes a PDU into protocol data.
40 41 42 43 44 45 |
# 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 ⇒ Integer
Returns the length of the PDU in bytes.
52 53 54 |
# File 'lib/modbus/pdu/read_registers.rb', line 52 def length 5 end |
#validate ⇒ Object
Validates the PDU. Raises exceptions if validation fails.
59 60 61 |
# 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 |