Method: Modbus::ProtocolData#shift_word

Defined in:
lib/modbus/connection/protocol_data.rb

#shift_wordInteger, NilClass

Shifts two bytes off the from front of the array and interprets them as a word (network byte order).

Returns:

  • (Integer, NilClass)

    The shifted word or nil if there are not enough bytes.



31
32
33
34
35
# File 'lib/modbus/connection/protocol_data.rb', line 31

def shift_word
  return nil if size < 2
  # self.shift(2).pack('C2').unpack('n').first
  self.slice!(0,2).pack('C2').unpack('n').first
end