Class: String

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

Overview

RModBus - free implementation of ModBus protocol on Ruby.

Copyright (C) 2009 Timin Aleksey

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Instance Method Summary collapse

Instance Method Details

#getbyte(index) ⇒ Object



18
19
20
# File 'lib/rmodbus/ext.rb', line 18

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

#getword(i) ⇒ Object

Get word by index



34
35
36
# File 'lib/rmodbus/ext.rb', line 34

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

#unpack_bitsObject



23
24
25
26
27
28
29
# File 'lib/rmodbus/ext.rb', line 23

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