class LadderDrive::Protocol::Mitsubishi::QDevice
Constants
- SUFFIXES
- SUFFIX_CODES
Attributes
number[R]
suffix[R]
Public Class Methods
new(a, b = nil)
click to toggle source
# File lib/ladder_drive/protocol/mitsubishi/qdevice.rb, line 35 def initialize a, b = nil case a when Array case a.size when 4 @suffix = suffix_for_code(a[3]) @number = ((a[2] << 8 | a[1]) << 8) | a[0] end when String if b @suffix = a.upcase @number = b else if a.length == 12 @suffix = [a[0,2].to_i(16), a[2,2].to_i(16)].pack "C*" @suffix.strip! @number = a[4,8].to_i(16) elsif /(X|Y|B|W|SB|SW|DX|DY)([0-9a-f]+)/i =~ a @suffix = $1.upcase @number = $2.to_i(p_adic_number) elsif /(M|L|S|F|T|C|D|R|ZR)([0-9]+)/i =~ a @suffix = $1.upcase @number = $2.to_i(p_adic_number) end end end end
Public Instance Methods
+(value)
click to toggle source
# File lib/ladder_drive/protocol/mitsubishi/qdevice.rb, line 105 def + value self.class.new self.suffix, self.number + value end
-(value)
click to toggle source
# File lib/ladder_drive/protocol/mitsubishi/qdevice.rb, line 109 def - value self.class.new self.suffix, [self.number - value, 0].max end
bit_device?()
click to toggle source
# File lib/ladder_drive/protocol/mitsubishi/qdevice.rb, line 85 def bit_device? case @suffix when "SM", "X", "Y", "M", "L", "F", "V", "B", "TS", "TC", "SS", "SC","CS", "CC", "SB", "S", "DX", "DY" true else false end end
name()
click to toggle source
# File lib/ladder_drive/protocol/mitsubishi/qdevice.rb, line 76 def name @suffix + @number.to_s(p_adic_number).upcase end
next_device()
click to toggle source
# File lib/ladder_drive/protocol/mitsubishi/qdevice.rb, line 80 def next_device d = self.class.new @suffix, @number + 1 d end
p_adic_number()
click to toggle source
# File lib/ladder_drive/protocol/mitsubishi/qdevice.rb, line 67 def p_adic_number case @suffix when "X", "Y", "B", "W", "SB", "SW", "DX", "DY" 16 else 10 end end
suffix_code()
click to toggle source
# File lib/ladder_drive/protocol/mitsubishi/qdevice.rb, line 100 def suffix_code index = SUFFIXES.index suffix index ? SUFFIX_CODES[index] : 0 end
suffix_for_code(code)
click to toggle source
# File lib/ladder_drive/protocol/mitsubishi/qdevice.rb, line 95 def suffix_for_code code index = SUFFIX_CODES.index code index ? SUFFIXES[index] : nil end
valid?()
click to toggle source
# File lib/ladder_drive/protocol/mitsubishi/qdevice.rb, line 63 def valid? !!@suffix && !!@number end