lib/ladder_drive/protocol/mitsubishi/qdevice.rb in ladder_drive-0.6.2 vs lib/ladder_drive/protocol/mitsubishi/qdevice.rb in ladder_drive-0.6.3
- old
+ new
@@ -23,11 +23,11 @@
module LadderDrive
module Protocol
module Mitsubishi
- class QDevice
+ class QDevice < PlcDevice
attr_reader :suffix, :number
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]
@@ -47,19 +47,22 @@
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)(.+)/i =~ a
+ elsif /(X|Y|B|W|SB|SW|DX|DY)([0-9a-f]+)/i =~ a
@suffix = $1.upcase
@number = $2.to_i(p_adic_number)
- else
- /(M|L|S|B|F|T|C|D|W|R|ZR)(.+)/i =~ a
+ 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
+
+ def valid?
+ !!@suffix && !!@number
end
def p_adic_number
case @suffix
when "X", "Y", "B", "W", "SB", "SW", "DX", "DY"