Class: PlcAccess::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].freeze
- 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].freeze
PlcAccess::PlcDevice::ESC_SUFFIXES, PlcAccess::PlcDevice::NUMBER_TYPE_DEC, PlcAccess::PlcDevice::NUMBER_TYPE_DEC_HEX, PlcAccess::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.
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
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 36
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
elsif 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 = ::Regexp.last_match(1).upcase
@number = ::Regexp.last_match(2).to_i(p_adic_number)
elsif /(M|L|S|F|T|C|D|R|ZR)([0-9]+)/i =~ a
@suffix = ::Regexp.last_match(1).upcase
@number = ::Regexp.last_match(2).to_i(p_adic_number)
end
end
end
|
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
30
31
32
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 30
def number
@number
end
|
#suffix ⇒ Object
Returns the value of attribute suffix.
30
31
32
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 30
def suffix
@suffix
end
|
Instance Method Details
#+(other) ⇒ Object
103
104
105
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 103
def +(other)
self.class.new suffix, number + other
end
|
#-(other) ⇒ Object
107
108
109
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 107
def -(other)
self.class.new suffix, [number - other, 0].max
end
|
#bit_device? ⇒ Boolean
83
84
85
86
87
88
89
90
91
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 83
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
75
76
77
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 75
def name
@suffix + @number.to_s(p_adic_number).upcase
end
|
#next_device ⇒ Object
79
80
81
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 79
def next_device
self.class.new @suffix, @number + 1
end
|
#p_adic_number ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 66
def p_adic_number
case @suffix
when 'X', 'Y', 'B', 'W', 'SB', 'SW', 'DX', 'DY'
16
else
10
end
end
|
#suffix_code ⇒ Object
98
99
100
101
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 98
def suffix_code
index = SUFFIXES.index suffix
index ? SUFFIX_CODES[index] : 0
end
|
#suffix_for_code(code) ⇒ Object
93
94
95
96
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 93
def suffix_for_code(code)
index = SUFFIX_CODES.index code
index ? SUFFIXES[index] : nil
end
|
#valid? ⇒ Boolean
62
63
64
|
# File 'lib/plc_access/protocol/mitsubishi/qdevice.rb', line 62
def valid?
!!@suffix && !!@number
end
|