Class: McProtocolE::Frame1e::BatchWriteInWord

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mc_protocol_e/frame_1e/batch_write_in_word.rb

Overview

This class shows a command to batch read in word.

Constant Summary collapse

REQUEST_HEADER =
"\x03".b
RESPONSE_HEADER =
"\x83".b

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device_range:, values:) ⇒ BatchWriteInWord

Constructor.

Parameters:

  • device_range (DeviceRange)

    device range

  • values (Array<Integer>)

    values to write

Raises:

  • (ArgumentError)

    when arguments is invalid



20
21
22
23
24
25
26
# File 'lib/mc_protocol_e/frame_1e/batch_write_in_word.rb', line 20

def initialize(device_range:, values:)
  @request_header = REQUEST_HEADER
  @device_range = device_range
  @values = values

  validate
end

Instance Attribute Details

#request_headerObject (readonly)

Returns the value of attribute request_header.



14
15
16
# File 'lib/mc_protocol_e/frame_1e/batch_write_in_word.rb', line 14

def request_header
  @request_header
end

Instance Method Details

#parse(res) ⇒ Object

Returns array of word. @return array of word

Parameters:



31
32
33
# File 'lib/mc_protocol_e/frame_1e/batch_write_in_word.rb', line 31

def parse(res)
  res.data&.each_char&.each_slice(2)&.map(&:join)
end

#to_bString

Returns binary string.

Returns:

  • (String)

    binary string



37
38
39
# File 'lib/mc_protocol_e/frame_1e/batch_write_in_word.rb', line 37

def to_b
  @to_b ||= device_range.to_b + values.pack("v*")
end