class Modbus::PDU::ReadBitsResponse
Base class PDU
for modbus bit based functions (response message)
Attributes
bit_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_bits.rb, line 76 def initialize(data = nil, func_code = nil) @bit_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_bits.rb, line 116 def byte_count @bit_values.size 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_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()
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_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()
click to toggle source
Returns the length of the PDU
in bytes.
@return [Integer] The length.
# File lib/modbus/pdu/read_bits.rb, line 125 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_bits.rb, line 133 def validate end