Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rmodbus/ext.rb

Instance Method Summary collapse

Instance Method Details

#getbyte(index) ⇒ Object



4
5
6
# File 'lib/rmodbus/ext.rb', line 4

def getbyte(index)
  self[index].to_i
end

#getword(i) ⇒ Object

Get word by index

Parameters:

  • i (Integer)

    index first bytes of word

Returns:

  • unpacked word



20
21
22
# File 'lib/rmodbus/ext.rb', line 20

def getword(i)
  self[i,2].unpack('n')[0]
end

#unpack_bitsObject



9
10
11
12
13
14
15
# File 'lib/rmodbus/ext.rb', line 9

def unpack_bits
  array_bit = []
  self.unpack('b*')[0].each_char do |c|
      array_bit << c.to_i
  end
  array_bit
end