Class: PlcUtil::Awl::BasicType

Inherits:
Object
  • Object
show all
Defined in:
lib/plcutil/siemens/awl/basic_type.rb

Constant Summary collapse

TYPES =
{
  :bool => 1,
  :byte => 8,
  :char => 8,
  :date => 16,
  :dint => 32,
  :dword => 32,
  :int => 16,
  :real => 32,
  :s5time => 16,
  :time => 32,
  :time_of_day => 32,
  :word => 16,
  :date_and_time => 32, # only in VAR_TEMP
  :timer => 1,          # only in FC calls
  :cont_c => 125 * 8
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bit_size, type_name) ⇒ BasicType

Returns a new instance of BasicType.



24
25
26
# File 'lib/plcutil/siemens/awl/basic_type.rb', line 24

def initialize(bit_size, type_name)
  @bit_size, @type_name = bit_size, type_name
end

Instance Attribute Details

#bit_sizeObject

Returns the value of attribute bit_size.



22
23
24
# File 'lib/plcutil/siemens/awl/basic_type.rb', line 22

def bit_size
  @bit_size
end

#type_nameObject

Returns the value of attribute type_name.



22
23
24
# File 'lib/plcutil/siemens/awl/basic_type.rb', line 22

def type_name
  @type_name
end

Class Method Details

.create(type_key) ⇒ Object



43
44
45
46
47
# File 'lib/plcutil/siemens/awl/basic_type.rb', line 43

def BasicType.create(type_key)
  b = TYPES[type_key]
  raise "Could not find type: #{type_key.to_s}" unless b
  BasicType.new b, type_key
end

Instance Method Details

#end_address(start_addr) ⇒ Object



39
40
41
# File 'lib/plcutil/siemens/awl/basic_type.rb', line 39

def end_address(start_addr)
  start_addr.skip bit_size
end

#skip_padding(addr) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/plcutil/siemens/awl/basic_type.rb', line 28

def skip_padding(addr)
  case bit_size
  when 1
    addr
  when 8
    addr.next_byte
  else
    addr.next_word
  end
end