ladder_drive 0.6.3 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +7 -2
  3. data/Gemfile.lock +107 -62
  4. data/README.md +1 -0
  5. data/README_jp.md +2 -2
  6. data/ladder_drive.gemspec +12 -8
  7. data/lib/ladder_drive/cli.rb +16 -4
  8. data/lib/ladder_drive/config.rb +4 -1
  9. data/lib/ladder_drive/config_target.rb +1 -0
  10. data/lib/ladder_drive/plc_device.rb +11 -0
  11. data/lib/ladder_drive/protocol/keyence/kv_protocol.rb +1 -11
  12. data/lib/ladder_drive/protocol/mitsubishi/fx_protocol.rb +0 -11
  13. data/lib/ladder_drive/protocol/mitsubishi/mc_protocol.rb +1 -11
  14. data/lib/ladder_drive/protocol/omron/c_mode_protocol.rb +224 -0
  15. data/lib/ladder_drive/protocol/omron/fins_tcp_protocol.rb +380 -0
  16. data/lib/ladder_drive/protocol/omron/omron.rb +28 -0
  17. data/lib/ladder_drive/protocol/omron/omron_device.rb +139 -0
  18. data/lib/ladder_drive/protocol/protocol.rb +16 -5
  19. data/lib/ladder_drive/tasks/build.rb +1 -1
  20. data/lib/ladder_drive/version.rb +1 -1
  21. data/lib/ladder_drive.rb +3 -0
  22. data/lib/plc/emulator/emu_plc_server.rb +3 -1
  23. data/lib/plc/emulator/plc_plugins.rb +20 -13
  24. data/lib/plc/emulator/plugin_trigger_state.rb +152 -0
  25. data/plugins/ambient_plugin.rb +155 -0
  26. data/plugins/config/ambient.yaml.example +34 -0
  27. data/plugins/config/google_drive.yaml.example +39 -0
  28. data/plugins/config/ifttt.yaml.example +24 -0
  29. data/plugins/config/plc_mapper.yaml.example +36 -0
  30. data/plugins/config/slack.yaml.example +36 -0
  31. data/plugins/config/trello.yaml.example +41 -0
  32. data/plugins/ifttt_plugin.rb +4 -27
  33. data/plugins/plc_mapper_plugin.rb +27 -15
  34. data/plugins/slack_plugin.rb +14 -3
  35. data/plugins/trello_plugin.rb +30 -42
  36. metadata +72 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ebbe6a801c62fb7bf390b50e904186de6c8a54d4
4
- data.tar.gz: 65bc6883680145868f3bec1b333d76760fee2eb0
2
+ SHA256:
3
+ metadata.gz: 4b46aba6a1c2e5ec981226750e08bd8bf08bc30e8a26f6a225f2dcfd921e0262
4
+ data.tar.gz: 49c7ea2044feb923c3c2f905e20a653ec313195b04de2368ed1fca629cd800db
5
5
  SHA512:
6
- metadata.gz: 2a78ed56aecb16bb8a4bdf5275acdf6b5f551cc62bce2efd6512160e79aa5c0d9757eb9eed6419f419bb5eba4f13fcc44e6ead4d4b9cc6cdb4cb4277b8ad150b
7
- data.tar.gz: 885041e935159cc775be45f6f8d0d46a148f74739c7b24fea1ccf8c4f4e5627f3be0b0b1cbbdd2fb92c6176defefadb949e55cf8e25848a76d10dde54c577f49
6
+ metadata.gz: b7c62e3002101eccb744165505c4b86cda09e0584bafd47dea8d85c94a50c6f0f02f5e5ac8b40fbfad648b9b1073be578e9b6003262f8a76395544083d7364a5
7
+ data.tar.gz: ff89eac27a06e14e4fd1150a206a2602e9d70d0e73f279cbdad539a9f6b991122e3531e89cdc1c6fbed8782fa0c1faf272516ca2bc4234a793e1bdc014df578a
data/Gemfile CHANGED
@@ -3,9 +3,12 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in ladder_drive.gemspec
4
4
  gemspec
5
5
 
6
- gem "test-unit"
6
+ group :test do
7
+ gem "test-unit"
8
+ gem "test-unit-rr"
9
+ end
7
10
 
8
- gem "activesupport", '~> 5.0'
11
+ gem "activesupport", '>= 4.0'
9
12
 
10
13
  gem 'pi_piper', ">= 2.0.0"
11
14
  gem "ffi", "~> 1.9.24"
@@ -13,3 +16,5 @@ gem "ffi", "~> 1.9.24"
13
16
  gem 'serialport'
14
17
  gem 'google_drive'
15
18
  gem "ruby-trello"
19
+ gem 'ambient_iot', ">= 0.1.1"
20
+ gem 'dotenv'
data/Gemfile.lock CHANGED
@@ -1,125 +1,170 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ladder_drive (0.6.1)
5
- activesupport (~> 5.0)
6
- ffi (~> 1.9.24, >= 1.9.24)
4
+ ladder_drive (0.6.6)
5
+ activesupport (~> 6.0)
6
+ ambient_iot (~> 0.1, >= 0.1.1)
7
+ dotenv (~> 2.1)
8
+ ffi (~> 1.9, >= 1.9.24)
9
+ google_drive (~> 3.0, >= 3.0.3)
7
10
  pi_piper (~> 2.0, >= 2.0.0)
8
- serialport
11
+ ruby-trello (~> 2.1)
12
+ serialport (~> 1.3, >= 1.3.1)
9
13
  thor (~> 0)
10
14
 
11
15
  GEM
12
16
  remote: https://rubygems.org/
13
17
  specs:
14
- activemodel (5.2.3)
15
- activesupport (= 5.2.3)
16
- activesupport (5.2.3)
18
+ activemodel (6.1.4.1)
19
+ activesupport (= 6.1.4.1)
20
+ activesupport (6.1.4.1)
17
21
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (>= 0.7, < 2)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- addressable (2.6.0)
22
- public_suffix (>= 2.0.2, < 4.0)
23
- concurrent-ruby (1.1.5)
24
- declarative (0.0.10)
25
- declarative-option (0.1.0)
26
- domain_name (0.5.20180417)
22
+ i18n (>= 1.6, < 2)
23
+ minitest (>= 5.1)
24
+ tzinfo (~> 2.0)
25
+ zeitwerk (~> 2.3)
26
+ addressable (2.8.0)
27
+ public_suffix (>= 2.0.2, < 5.0)
28
+ ambient_iot (0.1.1)
29
+ concurrent-ruby (1.1.9)
30
+ declarative (0.0.20)
31
+ domain_name (0.5.20190701)
27
32
  unf (>= 0.0.5, < 1.0.0)
33
+ dotenv (2.7.6)
28
34
  eventmachine (1.0.9)
29
- faraday (0.15.4)
35
+ faraday (1.7.0)
36
+ faraday-em_http (~> 1.0)
37
+ faraday-em_synchrony (~> 1.0)
38
+ faraday-excon (~> 1.1)
39
+ faraday-httpclient (~> 1.0.1)
40
+ faraday-net_http (~> 1.0)
41
+ faraday-net_http_persistent (~> 1.1)
42
+ faraday-patron (~> 1.0)
43
+ faraday-rack (~> 1.0)
30
44
  multipart-post (>= 1.2, < 3)
45
+ ruby2_keywords (>= 0.0.4)
46
+ faraday-em_http (1.0.0)
47
+ faraday-em_synchrony (1.0.0)
48
+ faraday-excon (1.1.0)
49
+ faraday-httpclient (1.0.1)
50
+ faraday-net_http (1.0.1)
51
+ faraday-net_http_persistent (1.2.0)
52
+ faraday-patron (1.0.0)
53
+ faraday-rack (1.0.0)
31
54
  ffi (1.9.25)
32
- google-api-client (0.28.7)
55
+ google-apis-core (0.4.1)
33
56
  addressable (~> 2.5, >= 2.5.1)
34
- googleauth (>= 0.5, < 0.10.0)
35
- httpclient (>= 2.8.1, < 3.0)
36
- mime-types (~> 3.0)
57
+ googleauth (>= 0.16.2, < 2.a)
58
+ httpclient (>= 2.8.1, < 3.a)
59
+ mini_mime (~> 1.0)
37
60
  representable (~> 3.0)
38
- retriable (>= 2.0, < 4.0)
39
- signet (~> 0.10)
40
- google_drive (3.0.2)
41
- google-api-client (>= 0.11.0, < 0.29.0)
61
+ retriable (>= 2.0, < 4.a)
62
+ rexml
63
+ webrick
64
+ google-apis-drive_v3 (0.13.0)
65
+ google-apis-core (>= 0.4, < 2.a)
66
+ google-apis-sheets_v4 (0.9.0)
67
+ google-apis-core (>= 0.4, < 2.a)
68
+ google_drive (3.0.7)
69
+ google-apis-drive_v3 (>= 0.5.0, < 1.0.0)
70
+ google-apis-sheets_v4 (>= 0.4.0, < 1.0.0)
42
71
  googleauth (>= 0.5.0, < 1.0.0)
43
72
  nokogiri (>= 1.5.3, < 2.0.0)
44
- googleauth (0.8.1)
45
- faraday (~> 0.12)
73
+ googleauth (0.17.0)
74
+ faraday (>= 0.17.3, < 2.0)
46
75
  jwt (>= 1.4, < 3.0)
47
76
  memoist (~> 0.16)
48
77
  multi_json (~> 1.11)
49
78
  os (>= 0.9, < 2.0)
50
- signet (~> 0.7)
51
- http-cookie (1.0.3)
79
+ signet (~> 0.14)
80
+ http-accept (1.7.0)
81
+ http-cookie (1.0.4)
52
82
  domain_name (~> 0.5)
53
83
  httpclient (2.8.3)
54
- i18n (1.6.0)
84
+ i18n (1.8.10)
55
85
  concurrent-ruby (~> 1.0)
56
- json (2.2.0)
57
- jwt (2.1.0)
58
- memoist (0.16.0)
59
- mime-types (3.2.2)
86
+ json (2.5.1)
87
+ jwt (2.2.3)
88
+ memoist (0.16.2)
89
+ mime-types (3.3.1)
60
90
  mime-types-data (~> 3.2015)
61
- mime-types-data (3.2019.0331)
62
- mini_portile2 (2.4.0)
63
- minitest (5.11.3)
64
- multi_json (1.13.1)
65
- multipart-post (2.0.0)
91
+ mime-types-data (3.2021.0704)
92
+ mini_mime (1.1.1)
93
+ mini_portile2 (2.6.1)
94
+ minitest (5.14.4)
95
+ multi_json (1.15.0)
96
+ multipart-post (2.1.1)
66
97
  netrc (0.11.0)
67
- nokogiri (1.10.3)
68
- mini_portile2 (~> 2.4.0)
69
- oauth (0.5.4)
70
- os (1.0.0)
98
+ nokogiri (1.12.3)
99
+ mini_portile2 (~> 2.6.1)
100
+ racc (~> 1.4)
101
+ oauth (0.5.6)
102
+ os (1.1.1)
71
103
  pi_piper (2.0.0)
72
104
  eventmachine (= 1.0.9)
73
105
  ffi
74
- power_assert (1.1.4)
75
- public_suffix (3.0.3)
106
+ power_assert (2.0.0)
107
+ public_suffix (4.0.6)
108
+ racc (1.5.2)
76
109
  rake (10.5.0)
77
- representable (3.0.4)
110
+ representable (3.1.1)
78
111
  declarative (< 0.1.0)
79
- declarative-option (< 0.2.0)
112
+ trailblazer-option (>= 0.1.1, < 0.2.0)
80
113
  uber (< 0.2.0)
81
- rest-client (2.0.2)
114
+ rest-client (2.1.0)
115
+ http-accept (>= 1.7.0, < 2.0)
82
116
  http-cookie (>= 1.0.2, < 2.0)
83
117
  mime-types (>= 1.16, < 4.0)
84
118
  netrc (~> 0.8)
85
119
  retriable (3.1.2)
86
- ruby-trello (2.1.0)
120
+ rexml (3.2.5)
121
+ rr (3.0.7)
122
+ ruby-trello (2.3.1)
87
123
  activemodel (>= 3.2.0)
88
124
  addressable (~> 2.3)
89
- json
125
+ json (>= 2.3.0)
90
126
  oauth (>= 0.4.5)
91
127
  rest-client (>= 1.8.0)
128
+ ruby2_keywords (0.0.5)
92
129
  serialport (1.3.1)
93
- signet (0.11.0)
130
+ signet (0.15.0)
94
131
  addressable (~> 2.3)
95
- faraday (~> 0.9)
132
+ faraday (>= 0.17.3, < 2.0)
96
133
  jwt (>= 1.5, < 3.0)
97
134
  multi_json (~> 1.10)
98
- test-unit (3.3.2)
135
+ test-unit (3.4.4)
99
136
  power_assert
137
+ test-unit-rr (1.0.5)
138
+ rr (>= 1.1.1)
139
+ test-unit (>= 2.5.2)
100
140
  thor (0.20.3)
101
- thread_safe (0.3.6)
102
- tzinfo (1.2.5)
103
- thread_safe (~> 0.1)
141
+ trailblazer-option (0.1.1)
142
+ tzinfo (2.0.4)
143
+ concurrent-ruby (~> 1.0)
104
144
  uber (0.1.0)
105
145
  unf (0.1.4)
106
146
  unf_ext
107
- unf_ext (0.0.7.6)
147
+ unf_ext (0.0.7.7)
148
+ webrick (1.7.0)
149
+ zeitwerk (2.4.2)
108
150
 
109
151
  PLATFORMS
110
152
  ruby
111
153
 
112
154
  DEPENDENCIES
113
- activesupport
114
- bundler (~> 1.11)
115
- ffi
155
+ activesupport (>= 4.0)
156
+ ambient_iot (>= 0.1.1)
157
+ bundler
158
+ dotenv
159
+ ffi (~> 1.9.24)
116
160
  google_drive
117
161
  ladder_drive!
118
- pi_piper
162
+ pi_piper (>= 2.0.0)
119
163
  rake (~> 10.0)
120
164
  ruby-trello
121
165
  serialport
122
166
  test-unit
167
+ test-unit-rr
123
168
 
124
169
  BUNDLED WITH
125
- 1.17.3
170
+ 2.1.4
data/README.md CHANGED
@@ -298,6 +298,7 @@ $ ladder_drive plugin plugin_name
298
298
  |plc_mapper|Share other PLCs data with Ladder drive device.|
299
299
  |slack|Cast the data to the Slack.|
300
300
  |trello|Move the card of Trello to specified list.|
301
+ |ambient|Writing data to Ambient.|
301
302
 
302
303
 
303
304
 
data/README_jp.md CHANGED
@@ -36,8 +36,7 @@ $ cd my_project
36
36
 
37
37
  ファイルの構成は下の様になっています。
38
38
  plc以下にLadderDriveを実行するPLCプロジェクトの雛形があります。
39
- 現在はエミュレーターと三菱電機のiQ-RシリーズR08CPUのみの対応となっています。
40
- 他メーカーや他の機種は今後追加する予定です。
39
+ 現在はエミュレーターと三菱電機のiQ-RシリーズR08CPU、キーエンスKV-5000のみの対応となっています。
41
40
 
42
41
 
43
42
  ```
@@ -310,6 +309,7 @@ Ladder DriveをIoT Gateway として機能させるプラグインになりま
310
309
  |plc_mapper|複数のPLCのデータをLadder Driveのメモリーに展開します。|
311
310
  |slack|Slackにデータの変化を記録します。|
312
311
  |trello|trelloのカードを指定のリストに移動します。|
312
+ |ambient|Ambientにデータの変化を記録します。|
313
313
 
314
314
  これらの用意されているプラグインをインストールするには
315
315
 
data/ladder_drive.gemspec CHANGED
@@ -14,21 +14,25 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/ito-soft-design/ladder_drive"
15
15
  spec.license = "MIT"
16
16
 
17
- spec.add_runtime_dependency 'thor', '~> 0'
18
- spec.add_runtime_dependency 'activesupport', '~> 5.0'#, '>= 4.2.7'
19
- spec.add_runtime_dependency 'ffi', '~> 1.9.24', '>= 1.9.24'
20
- spec.add_runtime_dependency 'pi_piper', '~> 2.0', '>= 2.0.0'
21
- spec.add_runtime_dependency 'serialport'
22
- spec.add_runtime_dependency 'google_drive', '~> 3.0'
23
- spec.add_runtime_dependency 'ruby-trello', '~>2.1'
17
+ spec.add_runtime_dependency 'thor', '~> 0'
18
+ spec.add_runtime_dependency 'activesupport', '~> 6.0'
19
+ spec.add_runtime_dependency 'ffi', '~> 1.9', '>= 1.9.24'
20
+ spec.add_runtime_dependency 'pi_piper', '~> 2.0', '>= 2.0.0'
24
21
 
22
+ spec.add_runtime_dependency 'serialport', '~> 1.3', '>= 1.3.1'
23
+ spec.add_runtime_dependency 'ambient_iot', '~> 0.1', '>= 0.1.1'
24
+ spec.add_runtime_dependency 'google_drive', '~> 3.0', '>= 3.0.3'
25
+ spec.add_runtime_dependency 'ruby-trello', '~>2.1'
26
+ spec.add_runtime_dependency 'dotenv', '~>2.1'
27
+
28
+ spec.required_ruby_version = '>= 2.3.3'
25
29
 
26
30
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
31
  spec.bindir = "exe"
28
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
33
  spec.require_paths = ["lib"]
30
34
 
31
- spec.add_development_dependency "bundler", "~> 1.11"
35
+ spec.add_development_dependency "bundler"
32
36
  spec.add_development_dependency "rake", "~> 10.0"
33
37
 
34
38
  end
@@ -54,11 +54,23 @@ module LadderDrive
54
54
  desc "plugin", "Install the specified plugin."
55
55
  def plugin(name)
56
56
  root_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
57
- plugins_path = File.join(root_dir, "plugins")
58
- path = File.join(plugins_path, "#{name}_plugin.rb")
59
- if File.exist? path
57
+
58
+ # copy plugin
59
+ plugins_dir = File.join(root_dir, "plugins")
60
+ plugin_path = File.join(plugins_dir, "#{name}_plugin.rb")
61
+ if File.exist? plugin_path
60
62
  mkdir_p "plugins"
61
- cp path, "plugins/#{name}_plugin.rb"
63
+ cp plugin_path, "plugins/#{name}_plugin.rb"
64
+ end
65
+
66
+ # copy sample settings
67
+ config_dir = File.join(plugins_dir, "config")
68
+ config_path = File.join(config_dir, "#{name}.yaml.example")
69
+ if File.exist? config_path
70
+ dst_dir = "config/plugins"
71
+ mkdir_p dst_dir
72
+ dst_path = "config/plugins/#{name}.yaml.example"
73
+ cp config_path, dst_path unless File.exist? dst_path
62
74
  end
63
75
  end
64
76
 
@@ -25,9 +25,11 @@ require 'active_support/core_ext/string/inflections'
25
25
  require 'yaml'
26
26
  require 'json'
27
27
  require 'protocol/protocol'
28
+ require 'erb'
28
29
 
29
30
  include LadderDrive::Protocol::Mitsubishi
30
31
  include LadderDrive::Protocol::Keyence
32
+ include LadderDrive::Protocol::Omron
31
33
  include LadderDrive::Protocol::Emulator
32
34
 
33
35
  module LadderDrive
@@ -45,7 +47,8 @@ module LadderDrive
45
47
  def load path
46
48
  h = {}
47
49
  if File.exist?(path)
48
- h = YAML.load(File.read(path))
50
+ erb = ERB.new File.read(path)
51
+ h = YAML.load(erb.result(binding))
49
52
  h = JSON.parse(h.to_json, symbolize_names: true)
50
53
  end
51
54
  new h || {}
@@ -27,6 +27,7 @@ require 'protocol/protocol'
27
27
 
28
28
  include LadderDrive::Protocol::Mitsubishi
29
29
  include LadderDrive::Protocol::Keyence
30
+ include LadderDrive::Protocol::Omron
30
31
  include LadderDrive::Protocol::Emulator
31
32
 
32
33
  module LadderDrive
@@ -125,6 +125,17 @@ module LadderDrive
125
125
  suffixes_for_input.include? @suffix
126
126
  end
127
127
 
128
+ def value
129
+ case @value
130
+ when true
131
+ 1
132
+ when false, nil
133
+ 0
134
+ else
135
+ @value
136
+ end
137
+ end
138
+
128
139
  def bool
129
140
  case @value
130
141
  when Integer
@@ -50,11 +50,6 @@ module Keyence
50
50
  @socket = nil
51
51
  end
52
52
 
53
- def get_bit_from_device device
54
- device = device_by_name device
55
- get_bits_from_device(1, device).first
56
- end
57
-
58
53
  def get_bits_from_device count, device
59
54
  c = (count + 15) / 16
60
55
  words = get_words_from_device c, device
@@ -89,11 +84,6 @@ module Keyence
89
84
  alias :set_bit_to_device :set_bits_to_device
90
85
 
91
86
 
92
- def get_word_from_device device
93
- device = device_by_name device
94
- get_words_from_device(1, device).first
95
- end
96
-
97
87
  def get_words_from_device(count, device)
98
88
  device = local_device device
99
89
  packet = "RDS #{device.name}.H #{count}\r\n"
@@ -134,7 +124,7 @@ module Keyence
134
124
  def receive
135
125
  res = ""
136
126
  begin
137
- Timeout.timeout(0.1) do
127
+ Timeout.timeout(TIMEOUT) do
138
128
  res = @socket.gets
139
129
  end
140
130
  rescue Timeout::Error
@@ -42,7 +42,6 @@ module Mitsubishi
42
42
  NAK = "\u0015"
43
43
 
44
44
  DELIMITER = "\r\n"
45
- TIMEOUT = 1.0
46
45
 
47
46
  def initialize options={}
48
47
  super
@@ -79,11 +78,6 @@ module Mitsubishi
79
78
  @comm = nil
80
79
  end
81
80
 
82
- def get_bit_from_device device
83
- device = device_by_name device
84
- get_bits_from_device(1, device).first
85
- end
86
-
87
81
  def get_bits_from_device count, device
88
82
  raise ArgumentError.new("A count #{count} must be between #{available_bits_range.first} and #{available_bits_range.last} for #{__method__}") unless available_bits_range.include? count
89
83
 
@@ -130,11 +124,6 @@ module Mitsubishi
130
124
  end
131
125
  end
132
126
 
133
- def get_word_from_device device
134
- device = device_by_name device
135
- get_words_from_device(1, device).first
136
- end
137
-
138
127
  def get_words_from_device(count, device)
139
128
  raise ArgumentError.new("A count #{count} must be between #{available_words_range.first} and #{available_words_range.last} for #{__method__}") unless available_words_range.include? count
140
129