Class: Snap7::DataBlock
- Inherits:
-
Object
- Object
- Snap7::DataBlock
- Defined in:
- lib/ffi-snap7/data_structures/data_block.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
- #add_variable(var) ⇒ Object
- #decode(data) ⇒ Object
-
#initialize(db_addr) ⇒ DataBlock
constructor
A new instance of DataBlock.
- #size ⇒ Object
Constructor Details
#initialize(db_addr) ⇒ DataBlock
Returns a new instance of DataBlock.
6 7 8 9 |
# File 'lib/ffi-snap7/data_structures/data_block.rb', line 6 def initialize(db_addr) @number = db_addr.scan(/\d+/).first.to_i @variables = [] end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
4 5 6 |
# File 'lib/ffi-snap7/data_structures/data_block.rb', line 4 def number @number end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
4 5 6 |
# File 'lib/ffi-snap7/data_structures/data_block.rb', line 4 def variables @variables end |
Instance Method Details
#add_variable(var) ⇒ Object
12 13 14 15 |
# File 'lib/ffi-snap7/data_structures/data_block.rb', line 12 def add_variable(var) var.db = self @variables << var end |
#decode(data) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/ffi-snap7/data_structures/data_block.rb', line 24 def decode(data) @variables.map do |var| { :ident => var.ident, :address => var.address, :value => var.decode(data) } end end |
#size ⇒ Object
18 19 20 21 |
# File 'lib/ffi-snap7/data_structures/data_block.rb', line 18 def size last_var = @variables.sort { |a,b| a.byte <=> b.byte }.last last_var.byte + last_var.byte_size end |