Class: Modbus::PDU::Exception

Inherits:
Modbus::PDU show all
Defined in:
lib/modbus/pdu/exception.rb

Overview

PDU for modbus exception (response message)

Constant Summary

Constants inherited from Modbus::PDU

REQ_PDU_MAP, RSP_PDU_MAP

Instance Attribute Summary collapse

Attributes inherited from Modbus::PDU

#creation_time, #func_code

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Modbus::PDU

#initialize

Constructor Details

This class inherits a constructor from Modbus::PDU

Instance Attribute Details

#exception_codeObject

Returns the value of attribute exception_code.



12
13
14
# File 'lib/modbus/pdu/exception.rb', line 12

def exception_code
  @exception_code
end

Class Method Details

.create(func_code, error) ⇒ Object



15
16
17
18
19
# 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

Instance Method Details

#decode(data) ⇒ Object

Decodes a PDU from protocol data.

Parameters:



26
27
28
# File 'lib/modbus/pdu/exception.rb', line 26

def decode(data)
  @exception_code = data.shift_byte
end

#encodeModbus::ProtocolData

Encodes a PDU into protocol data.

Returns:



35
36
37
38
39
# File 'lib/modbus/pdu/exception.rb', line 35

def encode
  data = super
  data.push_byte @exception_code
  data
end

#lengthInteger

Returns the length of the PDU in bytes.

Returns:

  • (Integer)

    The length.



46
47
48
# File 'lib/modbus/pdu/exception.rb', line 46

def length
  2
end