Class: McProtocolE::Frame3e::BatchWriteInWord

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/mc_protocol_e/frame_3e/batch_write_in_word.rb

Overview

This class shows a command to batch write in word.

Constant Summary collapse

COMMAND =
"\x01\x14\x00\x00".b

Instance Method Summary collapse

Constructor Details

#initialize(device_range:, values:) ⇒ BatchWriteInWord

Constructor.

Raises:

  • (ArgumentError)

    when arguments is invalid



16
17
18
19
20
21
22
# File 'lib/mc_protocol_e/frame_3e/batch_write_in_word.rb', line 16

def initialize(device_range:, values:)
  super(COMMAND)
  @device_range = device_range
  @values = values

  validate
end

Instance Method Details

#parse(res) ⇒ Object

Returns array of word. @return array of word



27
28
29
30
31
# File 'lib/mc_protocol_e/frame_3e/batch_write_in_word.rb', line 27

def parse(res)
  super(res)

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

#to_bString

Returns binary string.



35
36
37
# File 'lib/mc_protocol_e/frame_3e/batch_write_in_word.rb', line 35

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