class Escalator::PlcDevice
Constants
- ESC_SUFFIXES
- NUMBER_TYPE_DEC
- NUMBER_TYPE_DEC_HEX
- NUMBER_TYPE_HEX
- SUFFIXES_FOR_BIT
- SUFFIXES_FOR_DEC
- SUFFIXES_FOR_DEC_HEX
- SUFFIXES_FOR_HEX
- SUFFIXES_FOR_INPUT
Attributes
number[R]
suffix[R]
value[RW]
word[RW]
word=[RW]
Public Class Methods
new(a, b = nil)
click to toggle source
# File lib/escalator/plc_device.rb, line 53 def initialize a, b = nil @suffix = nil @value = 0 case a when Fixnum @suffix = ESC_SUFFIXES[a] @number = b when String if b @suffix = a.upcase @number = b else /([A-Z]+)?(\d+)/i =~ a @suffix = ($1 || "").upcase case number_type when NUMBER_TYPE_DEC_HEX n = $2.to_i @number = (n / 100) * 16 + (n % 100) when NUMBER_TYPE_HEX @number = $2.to_i(16) else @number = $2.to_i end end end end
program_area_device()
click to toggle source
# File lib/escalator/plc_device.rb, line 47 def program_area_device @program_area_device ||= new "PRG0" end
status_from_plc_device()
click to toggle source
# File lib/escalator/plc_device.rb, line 43 def status_from_plc_device @status_from_plc_device ||= new "SD1" end
status_to_plc_device()
click to toggle source
# File lib/escalator/plc_device.rb, line 39 def status_to_plc_device @status_to_plc_device ||= new "SD0" end
Public Instance Methods
+(value)
click to toggle source
# File lib/escalator/plc_device.rb, line 110 def + value self.class.new self.suffix, self.number + value end
-(value)
click to toggle source
# File lib/escalator/plc_device.rb, line 114 def - value self.class.new self.suffix, [self.number - value, 0].max end
bit_device?()
click to toggle source
# File lib/escalator/plc_device.rb, line 106 def bit_device? SUFFIXES_FOR_BIT.include? @suffix end
bool()
click to toggle source
# File lib/escalator/plc_device.rb, line 122 def bool case @value when Fixnum @value != 0 else !!@value end end
bool=(v;)
click to toggle source
# File lib/escalator/plc_device.rb, line 130 def bool= v; @value = v; end
device_code()
click to toggle source
# File lib/escalator/plc_device.rb, line 134 def device_code ESC_SUFFIXES.index @suffix end
input?()
click to toggle source
# File lib/escalator/plc_device.rb, line 118 def input? suffixes_for_input.include? @suffix end
name()
click to toggle source
# File lib/escalator/plc_device.rb, line 80 def name case number_type when NUMBER_TYPE_DEC "#{@suffix}#{@number}" when NUMBER_TYPE_DEC_HEX a = [@number / 16, @number % 16] ns = begin s = a.last.to_s.rjust(2, "0") s = a.first.to_s + s unless a.first == 0 s end "#{@suffix}#{ns}" when NUMBER_TYPE_HEX ns = @number.to_s(16) ns = "0" + ns unless /^[0-9]/ =~ ns "#{@suffix}#{ns}" else nil end end
next_device()
click to toggle source
# File lib/escalator/plc_device.rb, line 101 def next_device d = self.class.new @suffix, @number + 1 d end
reset()
click to toggle source
# File lib/escalator/plc_device.rb, line 138 def reset @value = 0 end
Private Instance Methods
number_type()
click to toggle source
# File lib/escalator/plc_device.rb, line 160 def number_type return NUMBER_TYPE_DEC if suffixes_for_dec.include? @suffix return NUMBER_TYPE_DEC_HEX if suffixes_for_dec_hex.include? @suffix return NUMBER_TYPE_HEX if suffixes_for_hex.include? @suffix nil end
suffixes()
click to toggle source
# File lib/escalator/plc_device.rb, line 156 def suffixes suffixes_for_dec + suffixes_for_dec_hex + suffixeds_for_hex end
suffixes_for_bit()
click to toggle source
# File lib/escalator/plc_device.rb, line 153 def suffixes_for_bit; SUFFIXES_FOR_BIT; end
suffixes_for_dec()
click to toggle source
# File lib/escalator/plc_device.rb, line 150 def suffixes_for_dec; SUFFIXES_FOR_DEC; end
suffixes_for_dec_hex()
click to toggle source
# File lib/escalator/plc_device.rb, line 151 def suffixes_for_dec_hex; SUFFIXES_FOR_DEC_HEX; end
suffixes_for_hex()
click to toggle source
# File lib/escalator/plc_device.rb, line 152 def suffixes_for_hex; SUFFIXES_FOR_HEX; end
suffixes_for_input()
click to toggle source
# File lib/escalator/plc_device.rb, line 154 def suffixes_for_input; SUFFIXES_FOR_INPUT; end