Class: LadderDrive::Protocol::Mitsubishi::QDevice
Constant Summary
collapse
- SUFFIXES =
%w(SM SD X Y M L F V B D W TS TC TN SS SC SN CS CC CN SB SW S DX DY Z R ZR)
- SUFFIX_CODES =
[0x91, 0xa9, 0x9c, 0x9d, 0x90, 0x92, 0x93, 0x94, 0xa0, 0xa8, 0xb4, 0xc1, 0xc0, 0xc2, 0xc7, 0xc6, 0xc8, 0xc4, 0xc3, 0xc5, 0xa1, 0xb5, 0x98, 0xa2, 0xa3, 0xcc ,0xaf, 0xb0]
LadderDrive::PlcDevice::ESC_SUFFIXES, LadderDrive::PlcDevice::NUMBER_TYPE_DEC, LadderDrive::PlcDevice::NUMBER_TYPE_DEC_HEX, LadderDrive::PlcDevice::NUMBER_TYPE_HEX
Instance Attribute Summary collapse
#value
Instance Method Summary
collapse
#bool, #bool=, #device_by_suffix_number, #device_code, #input?, program_area_device, #reset, #set_text, status_from_plc_device, status_to_plc_device, #text, #text=
Constructor Details
#initialize(a, b = nil) ⇒ QDevice
Returns a new instance of QDevice.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# 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
|
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
30
31
32
|
# File 'lib/ladder_drive/protocol/mitsubishi/qdevice.rb', line 30
def number
@number
end
|
#suffix ⇒ Object
Returns the value of attribute suffix.
30
31
32
|
# File 'lib/ladder_drive/protocol/mitsubishi/qdevice.rb', line 30
def suffix
@suffix
end
|
Instance Method Details
#+(value) ⇒ Object
105
106
107
|
# File 'lib/ladder_drive/protocol/mitsubishi/qdevice.rb', line 105
def + value
self.class.new self.suffix, self.number + value
end
|
#-(value) ⇒ Object
109
110
111
|
# 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? ⇒ Boolean
85
86
87
88
89
90
91
92
93
|
# 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 ⇒ Object
76
77
78
|
# File 'lib/ladder_drive/protocol/mitsubishi/qdevice.rb', line 76
def name
@suffix + @number.to_s(p_adic_number).upcase
end
|
#next_device ⇒ Object
80
81
82
83
|
# 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 ⇒ Object
67
68
69
70
71
72
73
74
|
# 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 ⇒ Object
100
101
102
103
|
# 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) ⇒ Object
95
96
97
98
|
# 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? ⇒ Boolean
63
64
65
|
# File 'lib/ladder_drive/protocol/mitsubishi/qdevice.rb', line 63
def valid?
!!@suffix && !!@number
end
|