rmodbus 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS.md CHANGED
@@ -1,13 +1,18 @@
1
- 2012-06-06 Release 1.1.3
2
- ==================================
1
+ ###2012-06-28 Release 1.1.4
2
+
3
+ 1. Fixed issue [#23](https://github.com/flipback/rmodbus/issues/23).
4
+ 2. Improved speed of the RTU\RTUViaTCP part.
5
+
6
+ ###2012-06-06 Release 1.1.3
7
+
3
8
  1. Fixed issue [#22](https://github.com/flipback/rmodbus/issues/22)
4
9
 
5
- 2012-05-12 Release 1.1.2
6
- ==================================
10
+ ###2012-05-12 Release 1.1.2
11
+
7
12
  1. Fixed issue [#20](https://github.com/flipback/rmodbus/issues/20)
8
13
 
9
- 2012-04-12 Release 1.1.1
10
- ==================================
14
+ ###2012-04-12 Release 1.1.1
15
+
11
16
  1. Fixed issue [#15](https://github.com/flipback/rmodbus/issues/15)
12
17
 
13
18
  2011-10-29 Release 1.1.0
@@ -31,26 +36,23 @@
31
36
 
32
37
  3. Deleted dependency with `serialport` gem. Install it manual for using RTU
33
38
 
34
- 2011-08-10 Release 1.0.4
35
- ====================================
39
+ ###2011-08-10 Release 1.0.4
40
+
36
41
  1. Fixed issue [#11](https://github.com/flipback/rmodbus/issues/11)
37
42
 
38
43
 
39
- 2011-07-17 Release 1.0.3
40
- ====================================
44
+ ###2011-07-17 Release 1.0.3
41
45
 
42
46
  1. Fixed issue #10
43
47
  2. Added new options for TCPServer#new and RTUViaTCPServer#new
44
48
  :host - ip of host server (default 127.0.0.1)
45
49
  :max_connection - maximum (client default 4)
46
50
 
47
- 2011-07-1 Release 1.0.2
48
- ====================================
51
+ ###2011-07-1 Release 1.0.2
49
52
 
50
53
  1. Fixed issue #9
51
54
 
52
- 2011-06-30 Release 1.0.1
53
- ====================================
55
+ ###2011-06-30 Release 1.0.1
54
56
 
55
57
  1. Fixed issue #8
56
58
 
data/README.md CHANGED
@@ -32,6 +32,7 @@ Download and install RModBus with the following
32
32
  Example
33
33
  ------------------------------------
34
34
 
35
+ ```ruby
35
36
  require 'rmodbus'
36
37
 
37
38
  ModBus::TCPClient.new('127.0.0.1', 8502) do |cl|
@@ -49,6 +50,7 @@ Example
49
50
  slave.holding_registers[16..20] = [1, 2, 3, 4, 5]
50
51
  end
51
52
  end
53
+ ```
52
54
 
53
55
  GitHub
54
56
  ----------------------------------
@@ -0,0 +1,55 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'../lib')
2
+
3
+ require 'rmodbus'
4
+ require 'benchmark'
5
+
6
+ include ModBus
7
+
8
+ TIMES = 1000
9
+
10
+ srv = ModBus::RTUViaTCPServer.new 1502
11
+ srv.coils = [0,1] * 50
12
+ srv.discrete_inputs = [1,0] * 50
13
+ srv.holding_registers = [0,1,2,3,4,5,6,7,8,9] * 10
14
+ srv.input_registers = [0,1,2,3,4,5,6,7,8,9] * 10
15
+ srv.start
16
+
17
+
18
+ cl = RTUViaTCPClient.new('127.0.0.1', 1502)
19
+ cl.with_slave(1) do |slave|
20
+ Benchmark.bmbm do |x|
21
+ x.report('Read coils') do
22
+ TIMES.times { slave.read_coils 0, 100 }
23
+ end
24
+
25
+ x.report('Read discrete inputs') do
26
+ TIMES.times { slave.read_discrete_inputs 0, 100 }
27
+ end
28
+
29
+ x.report('Read holding registers') do
30
+ TIMES.times { slave.read_holding_registers 0, 100 }
31
+ end
32
+
33
+ x.report('Read input registers') do
34
+ TIMES.times { slave.read_input_registers 0, 100 }
35
+ end
36
+
37
+ x.report('Write single coil') do
38
+ TIMES.times { slave.write_single_coil 0, 1 }
39
+ end
40
+
41
+ x.report('Write single register') do
42
+ TIMES.times { slave.write_single_register 100, 0xAAAA }
43
+ end
44
+
45
+ x.report('Write multiple coils') do
46
+ TIMES.times { slave.write_multiple_coils 0, [1,0] * 50 }
47
+ end
48
+
49
+ x.report('Write multiple registers') do
50
+ TIMES.times { slave.write_multiple_registers 0, [0,1,2,3,4,5,6,7,8,9] * 10 }
51
+ end
52
+ end
53
+ end
54
+ cl.close
55
+ srv.stop
data/lib/rmodbus/rtu.rb CHANGED
@@ -23,7 +23,6 @@ module ModBus
23
23
  msg = nil
24
24
  while msg.nil?
25
25
  msg = io.read(2)
26
- sleep(0.01)
27
26
  end
28
27
 
29
28
  function_code = msg.getbyte(1)
@@ -45,11 +44,22 @@ module ModBus
45
44
  end
46
45
  end
47
46
 
47
+ def clean_input_buff
48
+ begin
49
+ # Read up to 1500 bytes of trash.
50
+ @io.read_nonblock(1500)
51
+ rescue Errno::EAGAIN
52
+ # Ignore the fact we couldn't read.
53
+ rescue Exception => e
54
+ raise e
55
+ end
56
+ end
57
+
48
58
  def send_rtu_pdu(pdu)
49
59
  msg = @uid.chr + pdu
50
60
  msg << crc16(msg).to_word
51
61
 
52
- @io.read # Clean input buffer
62
+ clean_input_buff
53
63
  @io.write msg
54
64
 
55
65
  log "Tx (#{msg.size} bytes): " + logging_bytes(msg)
@@ -72,7 +82,6 @@ module ModBus
72
82
  end
73
83
  end
74
84
 
75
-
76
85
  def read_rtu_request(io)
77
86
  # Read the slave_id and function code
78
87
  msg = io.read(2)
@@ -112,7 +121,6 @@ module ModBus
112
121
  log "Server TX (#{resp.size} bytes): #{logging_bytes(resp)}"
113
122
  io.write resp
114
123
  end
115
- sleep(0.01)
116
124
  end
117
125
  end
118
126
 
@@ -57,7 +57,6 @@ module ModBus
57
57
  log "Server TX (#{resp.size} bytes): #{logging_bytes(resp)}"
58
58
  io.write resp
59
59
  end
60
- sleep(0.01)
61
60
  end
62
61
  end
63
62
  end
@@ -13,5 +13,5 @@
13
13
  # GNU General Public License for more details.
14
14
  module ModBus
15
15
  # Package version
16
- VERSION = '1.1.3'
16
+ VERSION = '1.1.4'
17
17
  end
data/spec/logging_spec.rb CHANGED
@@ -42,6 +42,7 @@ begin
42
42
  @sp = mock('Serial port')
43
43
  SerialPort.should_receive(:new).with("/dev/port1", 9600, 7, 2, SerialPort::ODD).and_return(@sp)
44
44
 
45
+ @sp.stub!(:read_timeout)
45
46
  @sp.stub!(:read_timeout=)
46
47
 
47
48
  @slave = ModBus::RTUClient.new("/dev/port1", 9600, :data_bits => 7, :stop_bits => 2, :parity => SerialPort::ODD).with_slave(1)
@@ -51,7 +52,7 @@ begin
51
52
  it 'should log rec\send bytes' do
52
53
  request = "\x3\x0\x1\x0\x1"
53
54
  @sp.should_receive(:write).with("\1#{request}\xd5\xca")
54
- @sp.should_receive(:read).and_return("\xff\xff") # Clean a garbage
55
+ @sp.should_receive(:read_nonblock).and_return("\xff\xff") # Clean a garbage
55
56
  @sp.should_receive(:read).with(2).and_return("\x1\x3")
56
57
  @sp.should_receive(:read).with(1).and_return("\x2")
57
58
  @sp.should_receive(:read).with(4).and_return("\xff\xff\xb9\xf4")
@@ -5,7 +5,8 @@ describe ModBus::RTUClient do
5
5
  @sp = mock('Serial port')
6
6
  SerialPort.should_receive(:new).with("/dev/port1", 9600, 8, 1, 0).and_return(@sp)
7
7
  @sp.stub!(:read_timeout=)
8
- @sp.stub!(:read)
8
+ @sp.stub!(:read_timeout)
9
+ @sp.stub!(:read_nonblock)
9
10
 
10
11
  @cl = ModBus::RTUClient.new("/dev/port1", 9600, :data_bits => 8, :stop_bits => 1, :parity => SerialPort::NONE)
11
12
  @slave = @cl.with_slave(1)
@@ -6,7 +6,7 @@ describe ModBus::RTUViaTCPClient do
6
6
  @sock = mock('Socked')
7
7
  TCPSocket.should_receive(:new).with("127.0.0.1", 10002).and_return(@sock)
8
8
  @sock.stub!(:read_timeout=)
9
- @sock.stub!(:read)
9
+ @sock.stub!(:read_nonblock)
10
10
 
11
11
  @cl = ModBus::RTUViaTCPClient.new("127.0.0.1")
12
12
  @slave = @cl.with_slave(1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmodbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-06 00:00:00.000000000 Z
12
+ date: 2012-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -107,6 +107,22 @@ dependencies:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
110
126
  - !ruby/object:Gem::Dependency
111
127
  name: pry
112
128
  requirement: !ruby/object:Gem::Requirement
@@ -140,7 +156,7 @@ dependencies:
140
156
  - !ruby/object:Gem::Version
141
157
  version: '0'
142
158
  - !ruby/object:Gem::Dependency
143
- name: guard-rspec
159
+ name: ruby-prof
144
160
  requirement: !ruby/object:Gem::Requirement
145
161
  none: false
146
162
  requirements:
@@ -163,48 +179,49 @@ extra_rdoc_files:
163
179
  - README.md
164
180
  - NEWS.md
165
181
  files:
166
- - lib/rmodbus/options.rb
167
- - lib/rmodbus/errors.rb
168
- - lib/rmodbus/rtu_server.rb
169
- - lib/rmodbus/client.rb
170
- - lib/rmodbus/debug.rb
171
182
  - lib/rmodbus/rtu_client.rb
172
- - lib/rmodbus/version.rb
173
- - lib/rmodbus/tcp.rb
174
- - lib/rmodbus/sp.rb
175
- - lib/rmodbus/rtu_slave.rb
176
- - lib/rmodbus/server.rb
177
- - lib/rmodbus/tcp_server.rb
178
183
  - lib/rmodbus/rtu_via_tcp_slave.rb
184
+ - lib/rmodbus/rtu_server.rb
185
+ - lib/rmodbus/tcp_server.rb
186
+ - lib/rmodbus/slave.rb
187
+ - lib/rmodbus/sp.rb
179
188
  - lib/rmodbus/rtu.rb
189
+ - lib/rmodbus/tcp_client.rb
190
+ - lib/rmodbus/version.rb
191
+ - lib/rmodbus/client.rb
192
+ - lib/rmodbus/tcp.rb
180
193
  - lib/rmodbus/ext.rb
181
- - lib/rmodbus/rtu_via_tcp_server.rb
182
194
  - lib/rmodbus/tcp_slave.rb
195
+ - lib/rmodbus/rtu_via_tcp_server.rb
196
+ - lib/rmodbus/server.rb
197
+ - lib/rmodbus/rtu_slave.rb
198
+ - lib/rmodbus/options.rb
183
199
  - lib/rmodbus/proxy.rb
184
- - lib/rmodbus/tcp_client.rb
185
200
  - lib/rmodbus/rtu_via_tcp_client.rb
186
- - lib/rmodbus/slave.rb
201
+ - lib/rmodbus/debug.rb
202
+ - lib/rmodbus/errors.rb
187
203
  - lib/rmodbus.rb
188
- - examples/perfomance_tcp.rb
189
- - examples/simple-xpca-gateway.rb
190
- - examples/use_tcp_modbus.rb
191
204
  - examples/use_rtu_via_tcp_modbus.rb
205
+ - examples/perfomance_rtu_via_tcp.rb
192
206
  - examples/perfomance_rtu.rb
193
- - spec/tcp_server_spec.rb
207
+ - examples/use_tcp_modbus.rb
208
+ - examples/simple-xpca-gateway.rb
209
+ - examples/perfomance_tcp.rb
210
+ - spec/response_mismach_spec.rb
211
+ - spec/rtu_server_spec.rb
194
212
  - spec/proxy_spec.rb
195
- - spec/rtu_via_tcp_server_spec.rb
196
- - spec/exception_spec.rb
213
+ - spec/spec_helper.rb
214
+ - spec/logging_spec.rb
215
+ - spec/client_spec.rb
216
+ - spec/slave_spec.rb
197
217
  - spec/rtu_via_tcp_client_spec.rb
218
+ - spec/rtu_via_tcp_server_spec.rb
219
+ - spec/tcp_server_spec.rb
220
+ - spec/tcp_client_spec.rb
198
221
  - spec/rtu_client_spec.rb
199
222
  - spec/read_rtu_response_spec.rb
200
- - spec/slave_spec.rb
201
- - spec/response_mismach_spec.rb
202
- - spec/tcp_client_spec.rb
223
+ - spec/exception_spec.rb
203
224
  - spec/ext_spec.rb
204
- - spec/logging_spec.rb
205
- - spec/client_spec.rb
206
- - spec/spec_helper.rb
207
- - spec/rtu_server_spec.rb
208
225
  - Rakefile
209
226
  - README.md
210
227
  - NEWS.md
@@ -233,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
250
  version: '0'
234
251
  requirements: []
235
252
  rubyforge_project:
236
- rubygems_version: 1.8.23
253
+ rubygems_version: 1.8.24
237
254
  signing_key:
238
255
  specification_version: 3
239
256
  summary: RModBus - free implementation of protocol ModBus