Class: Modbus::PDU::WriteSingleCoilRequest
- Inherits:
-
Modbus::PDU
- Object
- Modbus::PDU
- Modbus::PDU::WriteSingleCoilRequest
- Defined in:
- lib/modbus/pdu/write_single_coil.rb
Overview
PDU for modbus function “read single coil” (request message)
Direct Known Subclasses
Constant Summary collapse
- FUNC_CODE =
0x05
Constants inherited from Modbus::PDU
Instance Attribute Summary collapse
-
#start_addr ⇒ Object
Returns the value of attribute start_addr.
-
#value ⇒ Object
Returns the value of attribute value.
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) ⇒ WriteSingleCoilRequest
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) ⇒ WriteSingleCoilRequest
Initializes a new PDU instance. Decodes from protocol data if given.
21 22 23 24 25 |
# File 'lib/modbus/pdu/write_single_coil.rb', line 21 def initialize(data = nil, func_code = nil) @start_addr = 0 @value = 0 super end |
Instance Attribute Details
#start_addr ⇒ Object
Returns the value of attribute start_addr.
14 15 16 |
# File 'lib/modbus/pdu/write_single_coil.rb', line 14 def start_addr @start_addr end |
#value ⇒ Object
Returns the value of attribute value.
14 15 16 |
# File 'lib/modbus/pdu/write_single_coil.rb', line 14 def value @value end |
Instance Method Details
#decode(data) ⇒ Object
Decodes a PDU from protocol data.
32 33 34 35 |
# File 'lib/modbus/pdu/write_single_coil.rb', line 32 def decode(data) @start_addr = data.shift_word @value = data.shift_word end |
#encode ⇒ Modbus::ProtocolData
Encodes a PDU into protocol data.
42 43 44 45 46 47 |
# File 'lib/modbus/pdu/write_single_coil.rb', line 42 def encode data = super data.push_word @start_addr data.push_word @value data end |
#length ⇒ Integer
Returns the length of the PDU in bytes.
54 55 56 |
# File 'lib/modbus/pdu/write_single_coil.rb', line 54 def length 5 end |
#validate ⇒ Object
Validates the PDU. Raises exceptions if validation fails.
61 62 63 |
# File 'lib/modbus/pdu/write_single_coil.rb', line 61 def validate fail ClientError, "Value must be 0x0000 or 0xFF00, got '#{@value}'" unless [0x0000, 0xFF00].include?(@value) end |