Class: Modbus::PDU::ReadBitsRequest
- Inherits:
-
Modbus::PDU
- Object
- Modbus::PDU
- Modbus::PDU::ReadBitsRequest
- Defined in:
- lib/modbus/pdu/read_bits.rb
Overview
Base class PDU for modbus bit based functions (request message)
Direct Known Subclasses
Constant Summary
Constants inherited from Modbus::PDU
Instance Attribute Summary collapse
-
#bit_count ⇒ Object
Returns the value of attribute bit_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) ⇒ ReadBitsRequest
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) ⇒ ReadBitsRequest
Initializes a new PDU instance. Decodes from protocol data if given.
19 20 21 22 23 |
# File 'lib/modbus/pdu/read_bits.rb', line 19 def initialize(data = nil, func_code = nil) @start_addr = 0 @bit_count = 0 super end |
Instance Attribute Details
#bit_count ⇒ Object
Returns the value of attribute bit_count.
12 13 14 |
# File 'lib/modbus/pdu/read_bits.rb', line 12 def bit_count @bit_count end |
#start_addr ⇒ Object
Returns the value of attribute start_addr.
12 13 14 |
# File 'lib/modbus/pdu/read_bits.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_bits.rb', line 30 def decode(data) @start_addr = data.shift_word @bit_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_bits.rb', line 40 def encode data = super data.push_word @start_addr data.push_word @bit_count data end |
#length ⇒ Integer
Returns the length of the PDU in bytes.
52 53 54 |
# File 'lib/modbus/pdu/read_bits.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_bits.rb', line 59 def validate fail ClientError, "Register count must be in (1..127), got '#{@bit_count.inspect}'" unless (1..127).include?(@bit_count) end |