class Modbus::PDU::Exception

PDU for modbus exception (response message)

Attributes

exception_code[RW]

Public Class Methods

create(func_code, error) click to toggle source
# File lib/modbus/pdu/exception.rb, line 15
def self.create(func_code, error)
  obj = self.new nil, func_code + 0x80
  obj.exception_code = error.code
  obj
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/exception.rb, line 26
def decode(data)
  @exception_code = data.shift_byte
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/exception.rb, line 35
def encode
  data = super
  data.push_byte @exception_code
  data
end
length() click to toggle source

Returns the length of the PDU in bytes.

@return [Integer] The length.

# File lib/modbus/pdu/exception.rb, line 46
def length
  2
end