ladder_converter 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bdbf1d8ffd40e261a76df93ba59bfa11bc2d01c3
4
- data.tar.gz: 374b5bb33728e8a1dc270ff7134ccdcce9d34ce5
2
+ SHA256:
3
+ metadata.gz: 4235ce3af1d0bd3a947ee1f378ecd56d1fe5322ef6fb8c07401d14496810b896
4
+ data.tar.gz: 3360d36110694cd1d4efba24675a44fe0ae2858d798bca71dd50ca04839b804c
5
5
  SHA512:
6
- metadata.gz: d353c76986aa8e88cf507af7fd920b9d5a50d75076c58d1bda1e25d7c89a1284a6e882f50ee1bf127db20f2fec0f5fb3556a08e7e99c659b091e11c9a498fce4
7
- data.tar.gz: fb4a6eea270bbb0f7f488e7c8ae6e521e187ba4c097bf18eae7c2cbd56466861cd938294ccb1302b1319fae08a8aaca637fb86e6850bb74796e769adda97d401
6
+ metadata.gz: 81d69eeb8539a23d073ffc77a4be3c465ce29d0906fe6bbf33271c045a3cd463b5fa120db26e0474bb33058228ec9073d1f276dc00bfe644a9810494ac8d7e57
7
+ data.tar.gz: aa72168f6f99a5f8ab8e32cb51227abd19be6e45a7cc44c91a34a890904aabcac133af06790ba33a76304e25a470937b438dd2d7386e50b8d1b74ea03a10122f
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in ladder_converter.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ladder_converter.gemspec
4
+ gemspec
@@ -8,11 +8,19 @@ include LadderConverter
8
8
  @options = {ignore_unknown:true}
9
9
 
10
10
  opt = OptionParser.new do |opt|
11
- opt.banner = 'Usage: ladder_converter source_file target_file'
11
+ opt.banner = 'Usage: ladder_converter source_file target_file [options]'
12
12
  opt.on('--[no-]ignore-unknown', "Skip a code if it's an unknown mnemonic or device. If set no- quit converting immediately.") {|v| @options[:ignore_unknown] = v }
13
+ opt.on('-f', '--force-converting', "Convert codes without querying to overwrite the target file.") {|v| @options[:force_converting] = v }
14
+ opt.on('-l file', '--logging-file file', "Set a path to write a logging file.") {|v| @options[:logging_file] = v }
15
+ opt.on('-v', '--version', "print the version number, then exit.") {|v| @options[:version] = v }
13
16
  opt.parse!(ARGV)
14
17
  end
15
18
 
19
+ if @options[:version]
20
+ puts "Ladder Converter #{LadderConverter::VERSION}"
21
+ exit 0
22
+ end
23
+
16
24
  unless ARGV.size == 2
17
25
  puts opt.help
18
26
  exit -1
@@ -26,14 +34,16 @@ unless File.exist? src_path
26
34
  exit -1
27
35
  end
28
36
 
29
- while File.exist? dst_path
30
- print "Target file #{File.basename(dst_path)} is exist. Overwrite existing file (y/N) ? "
31
- case STDIN.gets.chomp
32
- when /^y$/i, /^yes$/i
33
- break
34
- when /^n$/i, /^no$/i
35
- STDERR.puts "Abort converting!"
36
- exit -1
37
+ unless @options[:force_converting]
38
+ while File.exist? dst_path
39
+ print "Target file #{File.basename(dst_path)} is exist. Overwrite existing file (y/N) ? "
40
+ case STDIN.gets.chomp
41
+ when /^y$/i, /^yes$/i
42
+ break
43
+ when /^n$/i, /^no$/i
44
+ STDERR.puts "Abort converting!"
45
+ exit -1
46
+ end
37
47
  end
38
48
  end
39
49
 
@@ -44,7 +44,7 @@ module LadderConverter
44
44
  when /^D((ADD|SUB|MUL|DIV|INC|DEC)P)$/
45
45
  "#{own_mnemonic($1)}.D"
46
46
 
47
- when 'MPS', 'MRD', 'MPP'
47
+ when 'MPS', 'MRD', 'MPP', 'NOP'
48
48
  mnemonic
49
49
 
50
50
 
@@ -80,7 +80,9 @@ module LadderConverter
80
80
  'LD<=', 'AND<=', 'OR<=',
81
81
  'LD>=', 'AND>=', 'OR>=',
82
82
  'CJ',
83
- 'CALL'
83
+ 'CALL',
84
+ 'FMOV', 'BMOV',
85
+ 'FOR', 'NEXT'
84
86
  mnemonic
85
87
  else
86
88
  n = {
@@ -117,7 +119,7 @@ module LadderConverter
117
119
  when /^M8001$/i # 常時OFF
118
120
  "CR2003"
119
121
  when /^([A-Z]+.+)(Z\d+)/
120
- "#{$1}:#{conv_dev $2}"
122
+ "#{own_device $1}:#{own_device $2}"
121
123
  when /^Z(\d+)$/
122
124
  "Z#{($1.to_i + 1).to_s.rjust(2, '0')}"
123
125
  when /^MR|^DM/i
@@ -132,7 +134,7 @@ module LadderConverter
132
134
  when /^D/i
133
135
  device.gsub(/^D+/i, "DM")
134
136
  when /^K\d+([A-Z]+.+)/i
135
- return conv_dev $1
137
+ return own_device $1
136
138
  when /^K\d+$/i
137
139
  device.gsub(/^K+/i, "#")
138
140
  when /^H(.+)/
@@ -1,3 +1,3 @@
1
- require 'plc_code'
2
- require 'kv_code'
1
+ require 'plc_code'
2
+ require 'kv_code'
3
3
  require 'mel2kv'
@@ -7,12 +7,14 @@ class Mel2Kv
7
7
  attr_reader :codes
8
8
  attr_reader :converted
9
9
  attr_reader :src, :dst
10
+ attr_reader :logging_file
10
11
 
11
12
  attr_reader :ignore_unknown
12
13
 
13
14
  def initialize options={}
14
15
  @src = options[:src]
15
16
  @dst = options[:dst]
17
+ @logging_file = options[:logging_file]
16
18
  @ignore_unknown = options[:ignore_unknown]
17
19
  @codes = nil
18
20
  end
@@ -21,27 +23,37 @@ class Mel2Kv
21
23
  return false unless File.exist? @src
22
24
  return true if @codes
23
25
 
24
- @codes = []
25
- has_end = false
26
- CSV.open(@src, "rb:BOM|UTF-16:UTF-8", headers:true, skip_lines:Regexp.new(/^[^\t]+$|PC情報:/), col_sep:"\t").each_with_index do |row, i|
27
- begin
28
- mnemonic = row["命令"]
29
- device = row["I/O(デバイス)"]
30
- case mnemonic
31
- when ""
32
- @codes.last.add_device device
33
- when 'END', 'FEND'
34
- unless has_end
26
+ begin
27
+ logfile = File.open(logging_file, "w") rescue nil
28
+
29
+ @codes = []
30
+ has_end = false
31
+ CSV.open(@src, "rb:BOM|UTF-16:UTF-8", headers:true, skip_lines:Regexp.new(/^[^\t]+$|PC情報:/), col_sep:"\t").each_with_index do |row, i|
32
+ begin
33
+ mnemonic = row["命令"]
34
+ device = row["I/O(デバイス)"]
35
+ case mnemonic
36
+ when 'NOP'
37
+ # Skip
38
+ when ""
39
+ @codes.last.add_device device
40
+ when 'END', 'FEND'
41
+ unless has_end
42
+ @codes << KvCode.new(mnemonic, [device])
43
+ has_end = true
44
+ end
45
+ else
35
46
  @codes << KvCode.new(mnemonic, [device])
36
- has_end = true
37
47
  end
38
- else
39
- @codes << KvCode.new(mnemonic, [device])
48
+ rescue UnknownCodeError => e
49
+ mes = "[WARN] SKIPPED! : line #{i+(3+1)} : #{e}"
50
+ STDERR.puts mes
51
+ logfile.puts mes if logfile
52
+ raise unless ignore_unknown
40
53
  end
41
- rescue UnknownCodeError => e
42
- STDERR.puts "[WARN] SKIPPED! : line #{i+(3+1)} : #{e}"
43
- raise unless ignore_unknown
44
54
  end
55
+ ensure
56
+ logfile.close if logfile
45
57
  end
46
58
  end
47
59
 
@@ -1,3 +1,3 @@
1
1
  module LadderConverter
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ladder_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuyoshi Ito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-17 00:00:00.000000000 Z
11
+ date: 2020-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,8 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.6.7
115
+ rubygems_version: 3.0.3
117
116
  signing_key:
118
117
  specification_version: 4
119
118
  summary: The Ladder converter is to convert a ladder program of PLC to another maker.