rmodbus 1.3.3 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/NEWS.md +19 -0
  3. data/README.md +8 -8
  4. data/examples/perfomance_rtu.rb +55 -56
  5. data/examples/perfomance_rtu_via_tcp.rb +54 -55
  6. data/examples/perfomance_tcp.rb +54 -55
  7. data/examples/simple_xpca_gateway.rb +85 -0
  8. data/examples/use_rtu_via_tcp_modbus.rb +14 -11
  9. data/examples/use_tcp_modbus.rb +14 -11
  10. data/lib/rmodbus/client/slave.rb +333 -0
  11. data/lib/rmodbus/client.rb +15 -10
  12. data/lib/rmodbus/debug.rb +12 -15
  13. data/lib/rmodbus/errors.rb +26 -2
  14. data/lib/rmodbus/ext.rb +72 -51
  15. data/lib/rmodbus/options.rb +4 -1
  16. data/lib/rmodbus/proxy.rb +14 -9
  17. data/lib/rmodbus/rtu.rb +89 -125
  18. data/lib/rmodbus/rtu_client.rb +22 -2
  19. data/lib/rmodbus/rtu_server.rb +16 -12
  20. data/lib/rmodbus/rtu_slave.rb +26 -3
  21. data/lib/rmodbus/rtu_via_tcp_server.rb +12 -19
  22. data/lib/rmodbus/server/slave.rb +18 -0
  23. data/lib/rmodbus/server.rb +227 -84
  24. data/lib/rmodbus/sp.rb +10 -12
  25. data/lib/rmodbus/tcp.rb +9 -10
  26. data/lib/rmodbus/tcp_client.rb +3 -0
  27. data/lib/rmodbus/tcp_server.rb +41 -35
  28. data/lib/rmodbus/tcp_slave.rb +19 -18
  29. data/lib/rmodbus/version.rb +3 -2
  30. data/lib/rmodbus.rb +20 -21
  31. metadata +63 -50
  32. data/Rakefile +0 -29
  33. data/examples/simple-xpca-gateway.rb +0 -84
  34. data/lib/rmodbus/rtu_via_tcp_client.rb +0 -26
  35. data/lib/rmodbus/rtu_via_tcp_slave.rb +0 -29
  36. data/lib/rmodbus/slave.rb +0 -310
  37. data/spec/client_spec.rb +0 -88
  38. data/spec/exception_spec.rb +0 -119
  39. data/spec/ext_spec.rb +0 -52
  40. data/spec/logging_spec.rb +0 -89
  41. data/spec/proxy_spec.rb +0 -74
  42. data/spec/read_rtu_response_spec.rb +0 -92
  43. data/spec/response_mismach_spec.rb +0 -163
  44. data/spec/rtu_client_spec.rb +0 -86
  45. data/spec/rtu_server_spec.rb +0 -30
  46. data/spec/rtu_via_tcp_client_spec.rb +0 -76
  47. data/spec/rtu_via_tcp_server_spec.rb +0 -16
  48. data/spec/slave_spec.rb +0 -55
  49. data/spec/spec_helper.rb +0 -54
  50. data/spec/tcp_client_spec.rb +0 -88
  51. data/spec/tcp_server_spec.rb +0 -129
data/lib/rmodbus.rb CHANGED
@@ -1,24 +1,23 @@
1
- require 'rmodbus/ext'
2
- require 'rmodbus/proxy'
3
- require 'rmodbus/version'
1
+ # frozen_string_literal: true
2
+
3
+ require "rmodbus/ext"
4
+ require "rmodbus/proxy"
5
+ require "rmodbus/version"
4
6
 
5
7
  module ModBus
6
- autoload :Errors, 'rmodbus/errors'
7
- autoload :Debug, 'rmodbus/debug'
8
- autoload :Options, 'rmodbus/options'
9
- autoload :SP, 'rmodbus/sp'
10
- autoload :RTU, 'rmodbus/rtu'
11
- autoload :TCP, 'rmodbus/tcp'
12
- autoload :Slave, 'rmodbus/slave'
13
- autoload :Client, 'rmodbus/client'
14
- autoload :Server, 'rmodbus/server'
15
- autoload :TCPSlave, 'rmodbus/tcp_slave'
16
- autoload :TCPClient, 'rmodbus/tcp_client'
17
- autoload :TCPServer, 'rmodbus/tcp_server'
18
- autoload :RTUSlave, 'rmodbus/rtu_slave'
19
- autoload :RTUClient, 'rmodbus/rtu_client'
20
- autoload :RTUServer, 'rmodbus/rtu_server'
21
- autoload :RTUViaTCPSlave, 'rmodbus/rtu_via_tcp_slave'
22
- autoload :RTUViaTCPClient, 'rmodbus/rtu_via_tcp_client'
23
- autoload :RTUViaTCPServer, 'rmodbus/rtu_via_tcp_server'
8
+ autoload :Errors, "rmodbus/errors"
9
+ autoload :Debug, "rmodbus/debug"
10
+ autoload :Options, "rmodbus/options"
11
+ autoload :SP, "rmodbus/sp"
12
+ autoload :RTU, "rmodbus/rtu"
13
+ autoload :TCP, "rmodbus/tcp"
14
+ autoload :Client, "rmodbus/client"
15
+ autoload :Server, "rmodbus/server"
16
+ autoload :TCPSlave, "rmodbus/tcp_slave"
17
+ autoload :TCPClient, "rmodbus/tcp_client"
18
+ autoload :TCPServer, "rmodbus/tcp_server"
19
+ autoload :RTUSlave, "rmodbus/rtu_slave"
20
+ autoload :RTUClient, "rmodbus/rtu_client"
21
+ autoload :RTUServer, "rmodbus/rtu_server"
22
+ autoload :RTUViaTCPServer, "rmodbus/rtu_via_tcp_server"
24
23
  end
metadata CHANGED
@@ -1,115 +1,143 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmodbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
- - A.Timin, J. Sanders, K. Reynolds, F. Luizão
7
+ - A.Timin, J. Sanders, K. Reynolds, F. Luizão, C. Cutrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-06 00:00:00.000000000 Z
11
+ date: 2024-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '10.4'
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '10.4'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: ccutrer-serialport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.7'
33
+ version: '1.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.7'
40
+ version: '1.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: gserver
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.99'
47
+ version: '0.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.99'
54
+ version: '0.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: guard-rspec
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.2'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.2'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: pry
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.10'
75
+ version: '3.11'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.10'
82
+ version: '3.11'
83
83
  - !ruby/object:Gem::Dependency
84
- name: serialport
84
+ name: rubocop-inst
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.3'
89
+ version: '1.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.3'
96
+ version: '1.0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: gserver
98
+ name: rubocop-rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.0'
103
+ version: '0.6'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.0'
110
+ version: '0.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: digest-crc
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.1'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.1'
111
139
  description:
112
- email: atimin@gmail.com
140
+ email: cody@cutrer.us
113
141
  executables: []
114
142
  extensions: []
115
143
  extra_rdoc_files:
@@ -118,15 +146,15 @@ extra_rdoc_files:
118
146
  files:
119
147
  - NEWS.md
120
148
  - README.md
121
- - Rakefile
122
149
  - examples/perfomance_rtu.rb
123
150
  - examples/perfomance_rtu_via_tcp.rb
124
151
  - examples/perfomance_tcp.rb
125
- - examples/simple-xpca-gateway.rb
152
+ - examples/simple_xpca_gateway.rb
126
153
  - examples/use_rtu_via_tcp_modbus.rb
127
154
  - examples/use_tcp_modbus.rb
128
155
  - lib/rmodbus.rb
129
156
  - lib/rmodbus/client.rb
157
+ - lib/rmodbus/client/slave.rb
130
158
  - lib/rmodbus/debug.rb
131
159
  - lib/rmodbus/errors.rb
132
160
  - lib/rmodbus/ext.rb
@@ -136,36 +164,22 @@ files:
136
164
  - lib/rmodbus/rtu_client.rb
137
165
  - lib/rmodbus/rtu_server.rb
138
166
  - lib/rmodbus/rtu_slave.rb
139
- - lib/rmodbus/rtu_via_tcp_client.rb
140
167
  - lib/rmodbus/rtu_via_tcp_server.rb
141
- - lib/rmodbus/rtu_via_tcp_slave.rb
142
168
  - lib/rmodbus/server.rb
143
- - lib/rmodbus/slave.rb
169
+ - lib/rmodbus/server/slave.rb
144
170
  - lib/rmodbus/sp.rb
145
171
  - lib/rmodbus/tcp.rb
146
172
  - lib/rmodbus/tcp_client.rb
147
173
  - lib/rmodbus/tcp_server.rb
148
174
  - lib/rmodbus/tcp_slave.rb
149
175
  - lib/rmodbus/version.rb
150
- - spec/client_spec.rb
151
- - spec/exception_spec.rb
152
- - spec/ext_spec.rb
153
- - spec/logging_spec.rb
154
- - spec/proxy_spec.rb
155
- - spec/read_rtu_response_spec.rb
156
- - spec/response_mismach_spec.rb
157
- - spec/rtu_client_spec.rb
158
- - spec/rtu_server_spec.rb
159
- - spec/rtu_via_tcp_client_spec.rb
160
- - spec/rtu_via_tcp_server_spec.rb
161
- - spec/slave_spec.rb
162
- - spec/spec_helper.rb
163
- - spec/tcp_client_spec.rb
164
- - spec/tcp_server_spec.rb
165
- homepage: http://www.rubydoc.info/github/rmodbus/rmodbus
176
+ homepage: https://github.com/rmodbus/rmodbus
166
177
  licenses:
167
178
  - BSD-3-Clause
168
- metadata: {}
179
+ metadata:
180
+ changelog_uri: https://github.com/rmodbus/rmodbus/blob/main/NEWS.md
181
+ source_code_uri: https://github.com/rmodbus/rmodbus
182
+ rubygems_mfa_required: 'true'
169
183
  post_install_message:
170
184
  rdoc_options:
171
185
  - "--title"
@@ -179,15 +193,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
193
  requirements:
180
194
  - - ">="
181
195
  - !ruby/object:Gem::Version
182
- version: '0'
196
+ version: '2.7'
183
197
  required_rubygems_version: !ruby/object:Gem::Requirement
184
198
  requirements:
185
199
  - - ">="
186
200
  - !ruby/object:Gem::Version
187
201
  version: '0'
188
202
  requirements: []
189
- rubyforge_project:
190
- rubygems_version: 2.6.11
203
+ rubygems_version: 3.5.11
191
204
  signing_key:
192
205
  specification_version: 4
193
206
  summary: RModBus - free implementation of protocol ModBus
data/Rakefile DELETED
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
-
13
- require 'rake'
14
- require 'rspec/core'
15
- require 'rspec/core/rake_task'
16
- RSpec::Core::RakeTask.new(:spec) do |spec|
17
- spec.pattern = FileList['spec/**/*_spec.rb']
18
- begin
19
- require 'serialport'
20
- rescue LoadError => e
21
- spec.pattern.exclude("spec/rtu_client_spec.rb", "spec/rtu_server_spec.rb")
22
- end
23
- end
24
-
25
- task :default => :spec
26
-
27
- task :pry do
28
- sh "bundle exec pry -r ./lib/rmodbus.rb"
29
- end
@@ -1,84 +0,0 @@
1
- =begin
2
- It's very simple example of implementation XPCA gateway (see http://www.xpca.org)
3
- for communication with TCP ModBus devices
4
- It receives REST requests (e.g http://127.0.0.1:4567/mb/127.0.0.1/8502/1/coils/6/17 )
5
- and returns data in JSON format addr : data:
6
- {"coils": {
7
- "6":{
8
- "value":0,
9
- "timestamp":"2011-07-12 18:11:03 +0000",
10
- "quality":"good"
11
- },
12
- "7":{
13
- "value":0,
14
- "timestamp":"2011-07-12 18:11:03 +0000",
15
- "quality":"good"
16
- }
17
- ...
18
- }
19
-
20
- This code requies gems: rmodbus, sinatra and json
21
- 2011 (c) Aleksey Timin
22
- =end
23
-
24
- require 'rubygems'
25
- require 'rmodbus'
26
- require 'sinatra'
27
- require 'json'
28
-
29
- # Launche TCP ModBus server for test
30
- IP = '127.0.0.1'
31
- PORT = 8502
32
-
33
- @srv = ModBus::TCPServer.new(PORT,1)
34
-
35
- @srv.holding_registers = Array.new(100) { |i| i = i + 1 }
36
- @srv.input_registers = Array.new(100) { |i| i = i + 1 }
37
- @srv.coils = Array.new(100) { |i| i = 0 }
38
- @srv.discrete_inputs = Array.new(100) { |i| i = 0 }
39
-
40
- @srv.start
41
-
42
-
43
- # Calc a GET request
44
- # @example
45
- # http://127.0.0.1:4567/mb/127.0.0.1/8502/1/coils/6/17
46
- #
47
- # HTTP route: GET http://localhost/mb/:ip/:port/:slave/:dataplace/:firstaddr/:lastaddr
48
- #
49
- # :ip - ip addr of ModBus TCP Server
50
- # :port - port of ModBUs TCP Server
51
- # :slave - id of slave device
52
- # :dataplace - valid values: coils, discrete_inputs, input_registers, holding_registers
53
- # :firstaddr - first addr of registers(contacts)
54
- # :lastaddr - last addr of registers(contacts)
55
- get '/mb/:ip/:port/:slave/:dataplace/:firstaddr/:lastaddr' do
56
- resp = {}
57
- begin
58
- data = []
59
- ModBus::TCPClient.new(params[:ip].to_s, params[:port].to_i) do |cl|
60
- cl.with_slave(params[:slave].to_i) do |slave|
61
- slave.debug = true
62
- dataplace = slave.send params[:dataplace]
63
- data = dataplace[params[:firstaddr].to_i .. params[:lastaddr].to_i]
64
- end
65
- end
66
-
67
- resp = { params[:dataplace] => {}}
68
- data.each_with_index do |v,i|
69
- resp[params[:dataplace]][params[:firstaddr].to_i + i] = {
70
- :value => v,
71
- :timestamp => Time.now.utc.strftime("%Y-%m-%d %H:%M:%S %z"),
72
- :quality => "good"
73
- }
74
- end
75
- rescue Exception => e
76
- resp = { :error => {
77
- :type => e.class,
78
- :message => e.message }
79
- }
80
- end
81
-
82
- content_type "application/json"
83
- resp.to_json
84
- end
@@ -1,26 +0,0 @@
1
- module ModBus
2
- # RTU over TCP client implementation
3
- # @example
4
- # RTUViaTCPClient.connect('127.0.0.1', 10002) do |cl|
5
- # cl.with_slave(uid) do |slave|
6
- # slave.holding_registers[0..100]
7
- # end
8
- # end
9
- #
10
- # @see TCP#open_tcp_connection
11
- # @see Client#initialize
12
- class RTUViaTCPClient < Client
13
- include RTU
14
- include TCP
15
-
16
- protected
17
- # Open TCP\IP connection
18
- def open_connection(ipaddr, port = 10002, opts = {})
19
- io = open_tcp_connection(ipaddr, port, opts)
20
- end
21
-
22
- def get_slave(uid, io)
23
- RTUViaTCPSlave.new(uid, io)
24
- end
25
- end
26
- end
@@ -1,29 +0,0 @@
1
- module ModBus
2
- # RTU over TCP slave implementation
3
- # @example
4
- # RTUViaTCP.connect('127.0.0.1', 10002) do |cl|
5
- # cl.with_slave(uid) do |slave|
6
- # slave.holding_registers[0..100]
7
- # end
8
- # end
9
- #
10
- # @see RTUViaTCPClient#open_connection
11
- # @see Client#with_slave
12
- # @see Slave
13
- class RTUViaTCPSlave < Slave
14
- include RTU
15
-
16
- private
17
- # overide method for RTU implamentaion
18
- # @see Slave#query
19
- def send_pdu(pdu)
20
- send_rtu_pdu(pdu)
21
- end
22
-
23
- # overide method for RTU implamentaion
24
- # @see Slave#query
25
- def read_pdu
26
- read_rtu_pdu
27
- end
28
- end
29
- end