Class: Modbus::PDU::ReadBitsResponse
- Inherits:
-
Modbus::PDU
- Object
- Modbus::PDU
- Modbus::PDU::ReadBitsResponse
- Defined in:
- lib/modbus/pdu/read_bits.rb
Overview
Base class PDU for modbus bit based functions (response message)
Direct Known Subclasses
Constant Summary
Constants inherited from Modbus::PDU
Instance Attribute Summary collapse
-
#bit_values ⇒ Object
Returns the value of attribute bit_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) ⇒ ReadBitsResponse
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) ⇒ ReadBitsResponse
Initializes a new PDU instance. Decodes from protocol data if given.
76 77 78 79 |
# File 'lib/modbus/pdu/read_bits.rb', line 76 def initialize(data = nil, func_code = nil) @bit_values = [] super end |
Instance Attribute Details
#bit_values ⇒ Object
Returns the value of attribute bit_values.
69 70 71 |
# File 'lib/modbus/pdu/read_bits.rb', line 69 def bit_values @bit_values end |
Instance Method Details
#byte_count ⇒ Integer
Returns the length of the register values in bytes.
116 117 118 |
# File 'lib/modbus/pdu/read_bits.rb', line 116 def byte_count @bit_values.size end |
#decode(data) ⇒ Object
Decodes a PDU from protocol data.
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/modbus/pdu/read_bits.rb', line 86 def decode(data) byte_count = data.shift_byte byte_count.times do byte = data.shift_byte 8.times do |bit| @bit_values.push byte[bit] == 1 end end end |
#encode ⇒ Modbus::ProtocolData
Encodes a PDU into protocol data.
102 103 104 105 106 107 108 109 |
# File 'lib/modbus/pdu/read_bits.rb', line 102 def encode data = super data.push_byte byte_count @bit_values.each do |value| data.push_byte value end data end |
#length ⇒ Integer
Returns the length of the PDU in bytes.
125 126 127 128 |
# File 'lib/modbus/pdu/read_bits.rb', line 125 def length # +1 for func_code, +1 for byte_count byte_count + 2 end |
#validate ⇒ Object
Validates the PDU. Raises exceptions if validation fails.
133 134 135 |
# File 'lib/modbus/pdu/read_bits.rb', line 133 def validate end |