ladder_converter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/ladder_converter +3 -0
- data/ladder_converter.gemspec +28 -0
- data/lib/ladder_converter.rb +7 -0
- data/lib/ladder_converter/kv_code.rb +149 -0
- data/lib/ladder_converter/ladder_converter.rb +3 -0
- data/lib/ladder_converter/mel2kv.rb +71 -0
- data/lib/ladder_converter/plc_code.rb +34 -0
- data/lib/ladder_converter/version.rb +3 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c46f0c84ae44923989d7908856041adfbed2fc8d
|
4
|
+
data.tar.gz: ee8d0b3d1e747e558ed7a892a7f1a34ba02ba1a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ebeb0336ba77049f5bdc9c86a77072f702e1e7308611b884f078f374977af5a61260851a6d3d2bbb430c42ba8e0e3e7e2d59be56a9f74e856389290e21507712
|
7
|
+
data.tar.gz: daccf79825b546d80b48d99e4bd49637f0535d92a1edbb2a0ce302d27e8f081da6803142f001fbd8630e125b2495bc4ab74e4bcd293dcf04137ff12cd9930756
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 ITO SOFT DESIGN Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,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
|
+
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
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require 'ladder_converter'
|
4
|
+
|
5
|
+
ENV['TESTOPTS'] = "--max-diff-target-string-size=2000"
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :test
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ladder_converter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ladder_converter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ladder_converter"
|
8
|
+
spec.version = LadderConverter::VERSION
|
9
|
+
spec.authors = ["Katsuyoshi Ito"]
|
10
|
+
spec.email = ["kito@itosoft.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{The Ladder converter is to convert a ladder program of PLC to another maker. }
|
13
|
+
spec.description = %q{The Ladder converter converts a PLC ladder program to another maker. Now we are trying to convert MITSUBISHI PLCs to Keyence PLCs.}
|
14
|
+
spec.homepage = "https://github.com/ito-soft-design/ladder_converter"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib", "lib/ladder_converter"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "csv"
|
27
|
+
spec.add_development_dependency "test-unit"
|
28
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'plc_code'
|
2
|
+
|
3
|
+
module LadderConverter
|
4
|
+
|
5
|
+
|
6
|
+
class KvCode < PlcCode
|
7
|
+
|
8
|
+
def initialize mnemonic, devices
|
9
|
+
super
|
10
|
+
case self.mnemonic
|
11
|
+
when 'LABEL'
|
12
|
+
@devices = [own_device(mnemonic)]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def becone_subroutin_label
|
17
|
+
@mnemonic = 'SBN'
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
return mnemonic if devices.empty?
|
22
|
+
([mnemonic] + devices).join(" ")
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def own_mnemonic mnemonic
|
28
|
+
mnemonic.upcase!
|
29
|
+
case mnemonic
|
30
|
+
|
31
|
+
|
32
|
+
when 'INC', 'DEC'
|
33
|
+
mnemonic
|
34
|
+
when /^(ADD|SUB|MUL|DIV)$/
|
35
|
+
{
|
36
|
+
"ADD" => "CAL+",
|
37
|
+
"SUB" => "CAL-",
|
38
|
+
"MUL" => "CAL*",
|
39
|
+
"DIV" => "CAL/",
|
40
|
+
}[mnemonic]
|
41
|
+
|
42
|
+
when /^(ADD|SUB|MUL|DIV|INC|DEC)P$/, /^@(ADD|SUB|MUL|DIV|INC|DEC)$/
|
43
|
+
"@#{own_mnemonic($1)}"
|
44
|
+
when /^D((ADD|SUB|MUL|DIV|INC|DEC)P)$/
|
45
|
+
"#{own_mnemonic($1)}.D"
|
46
|
+
|
47
|
+
when 'MPS', 'MRD', 'MPP'
|
48
|
+
mnemonic
|
49
|
+
|
50
|
+
|
51
|
+
when /^D(.+)/
|
52
|
+
"#{own_mnemonic($1)}.D"
|
53
|
+
|
54
|
+
when 'LDP', 'ORP'
|
55
|
+
mnemonic
|
56
|
+
when 'ANDP'
|
57
|
+
'ANP'
|
58
|
+
when /(.+)P$/
|
59
|
+
"@#{own_mnemonic($1)}"
|
60
|
+
|
61
|
+
when "PLF"
|
62
|
+
"DIFD"
|
63
|
+
when 'ANDF'
|
64
|
+
'ANF'
|
65
|
+
when /(.+)F$/
|
66
|
+
"#{own_mnemonic($1)}F"
|
67
|
+
|
68
|
+
when /^(LD|AND|OR)D([=<>]+)/
|
69
|
+
"#{$1}#{$2}.D"
|
70
|
+
|
71
|
+
when /^P(\d+)/
|
72
|
+
'LABEL'
|
73
|
+
|
74
|
+
when 'LD', 'OUT', 'END', 'AND', 'OR', 'SET',
|
75
|
+
'MOV',
|
76
|
+
'LD=', 'AND=', 'OR=',
|
77
|
+
'LD<>', 'AND<>', 'OR<>',
|
78
|
+
'LD<', 'AND<', 'OR<',
|
79
|
+
'LD>', 'AND>', 'OR>',
|
80
|
+
'LD<=', 'AND<=', 'OR<=',
|
81
|
+
'LD>=', 'AND>=', 'OR>=',
|
82
|
+
'CJ',
|
83
|
+
'CALL'
|
84
|
+
mnemonic
|
85
|
+
else
|
86
|
+
n = {
|
87
|
+
'LDI' => 'LDB',
|
88
|
+
"ANI" => "ANB",
|
89
|
+
"ORI" => "ORB",
|
90
|
+
"ANB" => "ANL",
|
91
|
+
"ORB" => "ORL",
|
92
|
+
"PLS" => "DIFU",
|
93
|
+
"PLF" => "DIFD",
|
94
|
+
"RST" => "RES",
|
95
|
+
|
96
|
+
"WAND" => "CAL&",
|
97
|
+
"WOR" => "CAL|",
|
98
|
+
|
99
|
+
'SRET' => 'RET',
|
100
|
+
|
101
|
+
"FEND" => "END",
|
102
|
+
|
103
|
+
}[mnemonic]
|
104
|
+
if n
|
105
|
+
n
|
106
|
+
else
|
107
|
+
raise "Unknown mnemonic #{mnemonic}!"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
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
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'kv_code'
|
3
|
+
|
4
|
+
module LadderConverter
|
5
|
+
class Mel2Kv
|
6
|
+
|
7
|
+
attr_reader :codes
|
8
|
+
attr_reader :converted
|
9
|
+
attr_reader :src, :dst
|
10
|
+
|
11
|
+
def initialize options={}
|
12
|
+
@src = options[:src]
|
13
|
+
@dst = options[:dst]
|
14
|
+
@codes = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def load
|
18
|
+
return false unless File.exist? @src
|
19
|
+
return true if @codes
|
20
|
+
|
21
|
+
@codes = []
|
22
|
+
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
|
31
|
+
@codes << KvCode.new(mnemonic, [device])
|
32
|
+
has_end = true
|
33
|
+
end
|
34
|
+
else
|
35
|
+
@codes << KvCode.new(mnemonic, [device])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def convert
|
41
|
+
load
|
42
|
+
@converted = <<EOS
|
43
|
+
DEVICE:132
|
44
|
+
;MODULE:Main
|
45
|
+
;MODULE_TYPE:0
|
46
|
+
EOS
|
47
|
+
# collect subrouten labels
|
48
|
+
sb_labels = codes.select{|c| c.mnemonic == "CALL"}.map{|c| c.devices.first}
|
49
|
+
# replace mnemonic LABLE to SBN if it's for subroutin.
|
50
|
+
codes.select{|c| c.mnemonic == "LABEL" && sb_labels.include?(c.device)}.each{|c| c.becone_subroutin_label }
|
51
|
+
|
52
|
+
# add kv codes string
|
53
|
+
@converted += codes.map(&:to_s).join("\n")
|
54
|
+
@converted += "\nENDH\n"
|
55
|
+
end
|
56
|
+
|
57
|
+
def save
|
58
|
+
return unless dst
|
59
|
+
convert
|
60
|
+
File.write dst, converted
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def kv_mnemonic mnemonic
|
67
|
+
mnemonic
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module LadderConverter
|
2
|
+
|
3
|
+
class PlcCode
|
4
|
+
|
5
|
+
attr_reader :mnemonic
|
6
|
+
attr_reader :devices
|
7
|
+
|
8
|
+
|
9
|
+
def initialize mnemonic, devices
|
10
|
+
@mnemonic = own_mnemonic mnemonic
|
11
|
+
@devices = devices.map{|d| own_device d}.select{|d| d && d.length != 0}
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_device device
|
15
|
+
@devices << own_device(device)
|
16
|
+
end
|
17
|
+
|
18
|
+
def device
|
19
|
+
devices.first
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def own_mnemonic mnemonic
|
25
|
+
mnemonic
|
26
|
+
end
|
27
|
+
|
28
|
+
def own_device device
|
29
|
+
device
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ladder_converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Katsuyoshi Ito
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: csv
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: The Ladder converter converts a PLC ladder program to another maker.
|
70
|
+
Now we are trying to convert MITSUBISHI PLCs to Keyence PLCs.
|
71
|
+
email:
|
72
|
+
- kito@itosoft.com
|
73
|
+
executables:
|
74
|
+
- ladder_converter
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- exe/ladder_converter
|
88
|
+
- ladder_converter.gemspec
|
89
|
+
- lib/ladder_converter.rb
|
90
|
+
- lib/ladder_converter/kv_code.rb
|
91
|
+
- lib/ladder_converter/ladder_converter.rb
|
92
|
+
- lib/ladder_converter/mel2kv.rb
|
93
|
+
- lib/ladder_converter/plc_code.rb
|
94
|
+
- lib/ladder_converter/version.rb
|
95
|
+
homepage: https://github.com/ito-soft-design/ladder_converter
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
- lib/ladder_converter
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.6.7
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: The Ladder converter is to convert a ladder program of PLC to another maker.
|
120
|
+
test_files: []
|