ladder_converter 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c46f0c84ae44923989d7908856041adfbed2fc8d
4
- data.tar.gz: ee8d0b3d1e747e558ed7a892a7f1a34ba02ba1a3
3
+ metadata.gz: bdbf1d8ffd40e261a76df93ba59bfa11bc2d01c3
4
+ data.tar.gz: 374b5bb33728e8a1dc270ff7134ccdcce9d34ce5
5
5
  SHA512:
6
- metadata.gz: ebeb0336ba77049f5bdc9c86a77072f702e1e7308611b884f078f374977af5a61260851a6d3d2bbb430c42ba8e0e3e7e2d59be56a9f74e856389290e21507712
7
- data.tar.gz: daccf79825b546d80b48d99e4bd49637f0535d92a1edbb2a0ce302d27e8f081da6803142f001fbd8630e125b2495bc4ab74e4bcd293dcf04137ff12cd9930756
6
+ metadata.gz: d353c76986aa8e88cf507af7fd920b9d5a50d75076c58d1bda1e25d7c89a1284a6e882f50ee1bf127db20f2fec0f5fb3556a08e7e99c659b091e11c9a498fce4
7
+ data.tar.gz: fb4a6eea270bbb0f7f488e7c8ae6e521e187ba4c097bf18eae7c2cbd56466861cd938294ccb1302b1319fae08a8aaca637fb86e6850bb74796e769adda97d401
data/README.md CHANGED
@@ -1,48 +1,63 @@
1
- # Ladder Converter
2
-
3
- The Ladder converter converts a PLC ladder program to another maker. Our first step is to convert MITSUBISHI PLCs to Keyence PLCs.
4
- (MITSUBISHI FX series to Keyence KV Nano series)
5
-
6
- ## Installation
7
-
8
- Add this line to your application's Gemfile:
9
-
10
- ```ruby
11
- gem 'ladder_converter'
12
- ```
13
-
14
- And then execute:
15
-
16
- $ bundle
17
-
18
- Or install it yourself as:
19
-
20
- $ gem install ladder_converter
21
-
22
- ## Usage
23
-
24
- 1. Export a mnemonic CSV file of MITSUBISHI PLC by GX Works
25
- (Now we trying FX series only.)
26
- 2. Execute below ruby code. It generates a mnemonic file for Keyence PLC located you specified to dst_path.
27
-
28
- ```
29
- require 'ladder_converter'
30
- include LadderConverter
31
- src_path = "path_to_mitsubishi_csv_file ..."
32
- dst_path = "path_to_store_keyence_mnm_file ..."
33
- @converter = Mel2Kv.new src:src_path, dst:dst_path
34
- @converter.save
35
- ```
36
-
37
- 3. Import the mnemonic file to KV STUDIO project.
38
-
39
-
40
- ## Contributing
41
-
42
- Bug reports and pull requests are welcome on GitHub at https://github.com/ito-soft-design/ladder_converter.
43
-
44
-
45
- ## License
46
-
47
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
48
-
1
+ # Ladder Converter
2
+
3
+ The Ladder converter converts a PLC ladder program to another maker. Our first step is to convert MITSUBISHI PLCs to Keyence PLCs.
4
+ (MITSUBISHI FX series to Keyence KV Nano series)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ladder_converter'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install ladder_converter
21
+
22
+ ## Usage
23
+
24
+ ### Commande
25
+
26
+ 1. Export a mnemonic CSV file of MITSUBISHI PLC by GX Works
27
+ (Now we trying FX series only.)
28
+
29
+ 2. Open a terminal. Execute ladder_converter command with source file (MITSUBISHI csv file) and target file (Keyence mnenonic file). It generates a Keyence mnemonic file.
30
+
31
+ ```
32
+ $ ladder_converter source_file target_file
33
+ ```
34
+
35
+ 3. Import the mnemonic file to KV STUDIO project.
36
+
37
+ ### Ruby script
38
+
39
+ 1. Export a mnemonic CSV file of MITSUBISHI PLC by GX Works
40
+ (Now we trying FX series only.)
41
+
42
+ 2. Execute below ruby code. It generates a mnemonic file for Keyence PLC located you specified to dst_path.
43
+
44
+ ```
45
+ require 'ladder_converter'
46
+ include LadderConverter
47
+ src_path = "path_to_mitsubishi_csv_file ..."
48
+ dst_path = "path_to_store_keyence_mnm_file ..."
49
+ converter = Mel2Kv.new src:src_path, dst:dst_path
50
+ converter.save
51
+ ```
52
+
53
+ 3. Import the mnemonic file to KV STUDIO project.
54
+
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ito-soft-design/ladder_converter.
59
+
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,81 @@
1
+ # Ladder Converter
2
+
3
+ ラダーコンバーターはPLCのラダーを他メーカーのラダーに変換します。
4
+ 最初のステップとして三菱電機製のPLCからキーエンス製のPLCのラダーに変換することを目指しています。
5
+ 具体的にはFXシリーズからKV Nanoシリーズへの変換を試みています。
6
+
7
+ ## Installation
8
+
9
+ Gemfileを使用している場合はGemfileに下の行を追加します。
10
+
11
+ ```ruby
12
+ gem 'ladder_converter'
13
+ ```
14
+
15
+ そしてbundleコマンドを実行します。
16
+
17
+ $ bundle
18
+
19
+ または、gemコマンドでinstallします。
20
+
21
+ $ gem install ladder_converter
22
+
23
+ ## 使い方
24
+
25
+ ### コマンドとして使用する場合
26
+
27
+ 1. 三菱電機製のPLCプロジェクトをCSVファイルに書き出します。
28
+ GX Works2で該当ラダーブログラムを表示し、編集メニューからCSVファイルへ書き込みを選択しCSVファイルを書き出せます。 (^1)
29
+
30
+ 2. ターミナル (^2) を開きます、下の様にladder_converterに 1 で書き出したCSVファイルを指定し、次に書き出すKeyenceのニーモニックファイルの保存先を指定し実行すると変換されます。
31
+
32
+ ```
33
+ $ ladder_converter source_file target_file
34
+ ```
35
+
36
+ 3. KV STUDIO で 2 で生成したファイルを読み込みます。
37
+ ファイルメニューからニーモニックリスト > 読出 を選択し2で保存したファイルを選択するとプロジェクトに取り込まれます。
38
+ Mainという名称で取り込まれますが、同名のプログラムが既にある場合は取り込まれません。元のMainプログラムを別の名称に変更するか可能なら削除してから行ってください。
39
+
40
+ ### Rubyスクリプトで変換する場合
41
+
42
+ 1. 三菱電機製のPLCプロジェクトをCSVファイルに書き出します。
43
+ GX Works2で該当ラダーブログラムを表示し、編集メニューからCSVファイルへ書き込みを選択しCSVファイルを書き出せます。(^1)
44
+
45
+ 2. 下のコードを記述すると変換できます。
46
+ src_pathには 1 で書き出したCSVファイルを指定します。dst_pathには書き出しすKeyenceのニーモニックファイルの保存先を指定します。
47
+
48
+ ```
49
+ require 'ladder_converter'
50
+ include LadderConverter
51
+
52
+ src_path = "path_to_mitsubishi_csv_file ..."
53
+ dst_path = "path_to_store_keyence_mnm_file ..."
54
+ converter = Mel2Kv.new src:src_path, dst:dst_path
55
+ converter.save
56
+ ```
57
+
58
+ 3. KV STUDIO で 2 で生成したファイルを読み込みます。
59
+ ファイルメニューからニーモニックリスト > 読出 を選択し2で保存したファイルを選択するとプロジェクトに取り込まれます。
60
+ Mainという名称で取り込まれますが、同名のプログラムが既にある場合は取り込まれません。元のMainプログラムを別の名称に変更するか可能なら削除してから行ってください。
61
+
62
+ ## 進捗状況
63
+
64
+ 現在FX2プロジェクトからKV Nanoプロジェクトへの変換を試みています。
65
+ 下のリンクにある、テストで用いたGX Works2プロジェクに含まれている基本的なラダーのみ変換可能です。
66
+ この中に含まれない命令が含まれている場合は変換できません。
67
+
68
+ https://github.com/ito-soft-design/ladder_converter/blob/master/test/files/src/FX2N.gxw
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ito-soft-design/ladder_converter.
73
+
74
+
75
+ ## ライセンス
76
+
77
+ [MIT License](http://opensource.org/licenses/MIT)
78
+
79
+
80
+ ^1: ラベルを使わずラダーのみのプロジェクトの場合に書き出せます。
81
+ ^2: Windowsの場合はコマンドプロンプトまたはWindows PowerShellを起動します。
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
  require 'ladder_converter'
4
+ require 'fileutils'
5
+
6
+ include FileUtils
4
7
 
5
8
  ENV['TESTOPTS'] = "--max-diff-target-string-size=2000"
6
9
  Rake::TestTask.new(:test) do |t|
@@ -9,4 +12,18 @@ Rake::TestTask.new(:test) do |t|
9
12
  t.test_files = FileList['test/**/*_test.rb']
10
13
  end
11
14
 
15
+ desc 'Generate exe file'
16
+ task :genexe do
17
+ begin
18
+ mkdir_p 'tmp'
19
+ `ocra exe/ladder_converter --output tmp/ldconv.exe`
20
+ rescue
21
+ puts '*' * 40
22
+ puts "If an error occurred, try this command."
23
+ puts "'gem install ocra'"
24
+ puts '*' * 40
25
+ raise
26
+ end
27
+ end
28
+
12
29
  task :default => :test
@@ -1,3 +1,42 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "ladder_converter"
1
+ #!/usr/bin/env ruby
2
+
3
+ require "ladder_converter"
4
+ require 'optparse'
5
+
6
+ include LadderConverter
7
+
8
+ @options = {ignore_unknown:true}
9
+
10
+ opt = OptionParser.new do |opt|
11
+ opt.banner = 'Usage: ladder_converter source_file target_file'
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.parse!(ARGV)
14
+ end
15
+
16
+ unless ARGV.size == 2
17
+ puts opt.help
18
+ exit -1
19
+ end
20
+
21
+ src_path = ARGV[0]
22
+ dst_path = ARGV[1]
23
+
24
+ unless File.exist? src_path
25
+ STDERR.puts "Source file #{File.basename(src_path)} is not found!"
26
+ exit -1
27
+ end
28
+
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
+ end
38
+ end
39
+
40
+
41
+ converter = Mel2Kv.new @options.merge(src:src_path, dst:dst_path)
42
+ converter.save
@@ -104,42 +104,46 @@ module LadderConverter
104
104
  if n
105
105
  n
106
106
  else
107
- raise "Unknown mnemonic #{mnemonic}!"
107
+ raise UnknownCodeError, "Unknown mnemonic \"#{mnemonic}\"."
108
108
  end
109
109
  end
110
110
  end
111
111
 
112
112
  def own_device device
113
- case device
114
- when /^M8000$/i # 常時ON
115
- "CR2002"
116
- when /^M8001$/i # 常時OFF
117
- "CR2003"
118
- when /^([A-Z]+.+)(Z\d+)/
119
- "#{$1}:#{conv_dev $2}"
120
- when /^Z(\d+)$/
121
- "Z#{($1.to_i + 1).to_s.rjust(2, '0')}"
122
- when /^MR|^DM/i
123
- device
124
- when /(^M)(\d+)/i
125
- n = $2.to_i
126
- "MR#{n/16}#{(n%16).to_s.rjust(2, '0')}"
127
- when /^X(\d+)/i
128
- "R#{$1}"
129
- when /^Y(\d+)/i
130
- "R#{$1.to_i + 500}"
131
- when /^D/i
132
- device.gsub(/^D+/i, "DM")
133
- when /^K\d+([A-Z]+.+)/i
134
- return conv_dev $1
135
- when /^K\d+$/i
136
- device.gsub(/^K+/i, "#")
137
- when /^H(.+)/
138
- "$#{$1}"
139
- when /^P(\d+)/
140
- "##{$1}"
141
- else
142
- device
113
+ begin
114
+ case device
115
+ when /^M8000$/i # 常時ON
116
+ "CR2002"
117
+ when /^M8001$/i # 常時OFF
118
+ "CR2003"
119
+ when /^([A-Z]+.+)(Z\d+)/
120
+ "#{$1}:#{conv_dev $2}"
121
+ when /^Z(\d+)$/
122
+ "Z#{($1.to_i + 1).to_s.rjust(2, '0')}"
123
+ when /^MR|^DM/i
124
+ device
125
+ when /(^M)(\d+)/i
126
+ n = $2.to_i
127
+ "MR#{n/16}#{(n%16).to_s.rjust(2, '0')}"
128
+ when /^X(\d+)/i
129
+ "R#{$1}"
130
+ when /^Y(\d+)/i
131
+ "R#{$1.to_i + 500}"
132
+ when /^D/i
133
+ device.gsub(/^D+/i, "DM")
134
+ when /^K\d+([A-Z]+.+)/i
135
+ return conv_dev $1
136
+ when /^K\d+$/i
137
+ device.gsub(/^K+/i, "#")
138
+ when /^H(.+)/
139
+ "$#{$1}"
140
+ when /^P(\d+)/
141
+ "##{$1}"
142
+ else
143
+ device
144
+ end
145
+ rescue
146
+ raise UnknownCodeError, "Unknown device \"#{device}\"."
143
147
  end
144
148
  end
145
149
 
@@ -8,9 +8,12 @@ class Mel2Kv
8
8
  attr_reader :converted
9
9
  attr_reader :src, :dst
10
10
 
11
+ attr_reader :ignore_unknown
12
+
11
13
  def initialize options={}
12
14
  @src = options[:src]
13
15
  @dst = options[:dst]
16
+ @ignore_unknown = options[:ignore_unknown]
14
17
  @codes = nil
15
18
  end
16
19
 
@@ -20,19 +23,24 @@ class Mel2Kv
20
23
 
21
24
  @codes = []
22
25
  has_end = false
23
- 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, l|
24
- mnemonic = row["命令"]
25
- device = row["I/O(デバイス)"]
26
- case mnemonic
27
- when ""
28
- @codes.last.add_device device
29
- when 'END', 'FEND'
30
- unless has_end
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
35
+ @codes << KvCode.new(mnemonic, [device])
36
+ has_end = true
37
+ end
38
+ else
31
39
  @codes << KvCode.new(mnemonic, [device])
32
- has_end = true
33
40
  end
34
- else
35
- @codes << KvCode.new(mnemonic, [device])
41
+ rescue UnknownCodeError => e
42
+ STDERR.puts "[WARN] SKIPPED! : line #{i+(3+1)} : #{e}"
43
+ raise unless ignore_unknown
36
44
  end
37
45
  end
38
46
  end
@@ -31,4 +31,7 @@ module LadderConverter
31
31
 
32
32
  end
33
33
 
34
+ class UnknownCodeError < StandardError
35
+ end
36
+
34
37
  end
@@ -1,3 +1,3 @@
1
- module LadderConverter
2
- VERSION = "0.1.0"
3
- end
1
+ module LadderConverter
2
+ VERSION = "0.1.1"
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.0
4
+ version: 0.1.1
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-14 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,9 +78,9 @@ files:
78
78
  - ".gitignore"
79
79
  - ".travis.yml"
80
80
  - Gemfile
81
- - Gemfile.lock
82
81
  - LICENSE.txt
83
82
  - README.md
83
+ - README_ja.md
84
84
  - Rakefile
85
85
  - bin/console
86
86
  - bin/setup