Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/rmodbus/ext.rb
Instance Method Summary collapse
-
#getword(index) ⇒ Object
Get word by index.
-
#unpack_bits ⇒ Object
unpack a string of bytes into an array of integers (0 or 1) representing the bits in those bytes, according to how the ModBus protocol represents coils.
Instance Method Details
#getword(index) ⇒ Object
Get word by index
22 23 24 |
# File 'lib/rmodbus/ext.rb', line 22 def getword(index) self[index, 2].unpack1("n") end |
#unpack_bits ⇒ Object
unpack a string of bytes into an array of integers (0 or 1) representing the bits in those bytes, according to how the ModBus protocol represents coils.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rmodbus/ext.rb', line 7 def unpack_bits result = [] each_byte do |b| 8.times do # least significant bits first within each byte result << (b & 0x01) b >>= 1 end end result end |