rmodbus 1.1.5 → 1.2.0
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.
- data/NEWS.md +6 -0
- data/README.md +1 -1
- data/lib/rmodbus/ext.rb +1 -1
- data/lib/rmodbus/tcp_slave.rb +14 -10
- data/lib/rmodbus/version.rb +1 -1
- data/spec/client_spec.rb +1 -0
- data/spec/exception_spec.rb +1 -0
- data/spec/ext_spec.rb +1 -0
- data/spec/logging_spec.rb +17 -1
- data/spec/proxy_spec.rb +1 -0
- data/spec/read_rtu_response_spec.rb +1 -0
- data/spec/response_mismach_spec.rb +1 -0
- data/spec/rtu_client_spec.rb +1 -0
- data/spec/rtu_server_spec.rb +1 -0
- data/spec/rtu_via_tcp_client_spec.rb +1 -0
- data/spec/rtu_via_tcp_server_spec.rb +3 -1
- data/spec/slave_spec.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/tcp_client_spec.rb +15 -6
- data/spec/tcp_server_spec.rb +1 -0
- metadata +2 -18
data/NEWS.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
###2013-03-12 Release 1.2.0
|
2
|
+
|
3
|
+
1. Transaction number mismatch doesn't throw exception in TCPSlave#query method.
|
4
|
+
Now this method will wait correct transaction until timeout breaks waiting.
|
5
|
+
2. Added ruby-2.0 experemental compatibility
|
6
|
+
|
1
7
|
###2012-07-17 Release 1.1.5
|
2
8
|
|
3
9
|
1. Fixed issue [#24](https://github.com/flipback/rmodbus/issues/24) for RTUClient.
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ RModBus [](htt
|
|
5
5
|
|
6
6
|
Features
|
7
7
|
---------------------------
|
8
|
-
- Ruby 1.8, Ruby 1.9, JRuby (without serial ModBus RTU)
|
8
|
+
- Ruby 1.8.7, Ruby 1.9, Ruby 2.0 (experemntal), JRuby (without serial ModBus RTU)
|
9
9
|
- TCP, RTU, RTU over TCP protocols
|
10
10
|
- Client(master) and server(slave)
|
11
11
|
- 16, 32 -bit and float registers
|
data/lib/rmodbus/ext.rb
CHANGED
data/lib/rmodbus/tcp_slave.rb
CHANGED
@@ -47,17 +47,21 @@ module ModBus
|
|
47
47
|
# overide method for RTU over TCP implamentaion
|
48
48
|
# @see Slave#query
|
49
49
|
def read_pdu
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
loop do
|
51
|
+
header = @io.read(7)
|
52
|
+
if header
|
53
|
+
trn = header[0,2].unpack('n')[0]
|
54
|
+
len = header[4,2].unpack('n')[0]
|
55
|
+
msg = @io.read(len-1)
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
log "Rx (#{(header + msg).size} bytes): " + logging_bytes(header + msg)
|
58
|
+
|
59
|
+
if trn == @transaction
|
60
|
+
return msg
|
61
|
+
else
|
62
|
+
log "Transaction number mismatch. A packet is ignored."
|
63
|
+
end
|
64
|
+
end
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
data/lib/rmodbus/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
data/spec/exception_spec.rb
CHANGED
data/spec/ext_spec.rb
CHANGED
data/spec/logging_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: ascii
|
1
2
|
require 'rmodbus'
|
2
3
|
|
3
4
|
describe ModBus::TCPClient do
|
@@ -10,23 +11,38 @@ describe ModBus::TCPClient do
|
|
10
11
|
@sock.stub!(:read).with(0).and_return('')
|
11
12
|
|
12
13
|
@slave = ModBus::TCPClient.new('127.0.0.1', 1502).with_slave(@uid)
|
14
|
+
@slave.debug = true
|
13
15
|
end
|
14
16
|
|
15
17
|
it 'should log rec\send bytes' do
|
16
18
|
request, response = "\x3\x0\x6b\x0\x3", "\x3\x6\x2\x2b\x0\x0\x0\x64"
|
17
19
|
mock_query(request,response)
|
18
|
-
@slave.debug = true
|
19
20
|
$stdout.should_receive(:puts).with("Tx (12 bytes): [00][01][00][00][00][06][01][03][00][6b][00][03]")
|
20
21
|
$stdout.should_receive(:puts).with("Rx (15 bytes): [00][01][00][00][00][09][01][03][06][02][2b][00][00][00][64]")
|
21
22
|
@slave.query(request)
|
22
23
|
end
|
23
24
|
|
24
25
|
it "should don't logging if debug disable" do
|
26
|
+
@slave.debug = false
|
25
27
|
request, response = "\x3\x0\x6b\x0\x3", "\x3\x6\x2\x2b\x0\x0\x0\x64"
|
26
28
|
mock_query(request,response)
|
27
29
|
@slave.query(request)
|
28
30
|
end
|
29
31
|
|
32
|
+
it "should log warn message if transaction mismatch" do
|
33
|
+
@adu[0,2] = @slave.transaction.next.to_word
|
34
|
+
@sock.should_receive(:write).with(@adu)
|
35
|
+
@sock.should_receive(:read).with(7).and_return("\000\002\000\000\000\001" + @uid.chr)
|
36
|
+
@sock.should_receive(:read).with(7).and_return("\000\001\000\000\000\001" + @uid.chr)
|
37
|
+
|
38
|
+
$stdout.should_receive(:puts).with("Tx (7 bytes): [00][01][00][00][00][01][01]")
|
39
|
+
$stdout.should_receive(:puts).with("Rx (7 bytes): [00][02][00][00][00][01][01]")
|
40
|
+
$stdout.should_receive(:puts).with("Transaction number mismatch. A packet is ignored.")
|
41
|
+
$stdout.should_receive(:puts).with("Rx (7 bytes): [00][01][00][00][00][01][01]")
|
42
|
+
|
43
|
+
@slave.query('')
|
44
|
+
end
|
45
|
+
|
30
46
|
def mock_query(request, response)
|
31
47
|
@adu = @slave.transaction.next.to_word + "\x0\x0\x0\x9" + @uid.chr + request
|
32
48
|
@sock.should_receive(:write).with(@adu[0,4] + "\0\6" + @uid.chr + request)
|
data/spec/proxy_spec.rb
CHANGED
data/spec/rtu_client_spec.rb
CHANGED
data/spec/rtu_server_spec.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
# -*- coding: ascii
|
1
2
|
require "rmodbus"
|
3
|
+
|
2
4
|
describe ModBus::RTUViaTCPServer do
|
3
5
|
it "should have options :host" do
|
4
6
|
host = '192.168.0.1'
|
@@ -11,4 +13,4 @@ describe ModBus::RTUViaTCPServer do
|
|
11
13
|
srv = ModBus::RTUViaTCPServer.new(1010, 1, :max_connection => 5)
|
12
14
|
srv.maxConnections.should eql(max_conn)
|
13
15
|
end
|
14
|
-
end
|
16
|
+
end
|
data/spec/slave_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/tcp_client_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: ascii
|
1
2
|
require 'rmodbus'
|
2
3
|
|
3
4
|
describe ModBus::TCPClient do
|
@@ -20,17 +21,25 @@ describe ModBus::TCPClient do
|
|
20
21
|
@slave.query('').should == nil
|
21
22
|
end
|
22
23
|
|
23
|
-
it 'should throw exception if get other transaction' do
|
24
|
+
it 'should not throw exception and white next packet if get other transaction' do
|
24
25
|
@adu[0,2] = @slave.transaction.next.to_word
|
25
26
|
@sock.should_receive(:write).with(@adu)
|
26
27
|
@sock.should_receive(:read).with(7).and_return("\000\002\000\000\000\001" + @uid.chr)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
ex.class.should == ModBus::Errors::ModBusException
|
31
|
-
end
|
28
|
+
@sock.should_receive(:read).with(7).and_return("\000\001\000\000\000\001" + @uid.chr)
|
29
|
+
|
30
|
+
expect{ @slave.query('') }.to_not raise_error
|
32
31
|
end
|
33
32
|
|
33
|
+
it 'should throw timeout exception if do not get own transaction' do
|
34
|
+
@slave.read_retries = 2
|
35
|
+
@adu[0,2] = @slave.transaction.next.to_word
|
36
|
+
@sock.should_receive(:write).any_number_of_times.with(/\.*/)
|
37
|
+
@sock.should_receive(:read).any_number_of_times.with(7).and_return("\000\x3\000\000\000\001" + @uid.chr)
|
38
|
+
|
39
|
+
expect{ @slave.query('') }.to raise_error(ModBus::Errors::ModBusTimeout, "Timed out during read attempt")
|
40
|
+
end
|
41
|
+
|
42
|
+
|
34
43
|
it 'should return only data from PDU' do
|
35
44
|
request = "\x3\x0\x6b\x0\x3"
|
36
45
|
response = "\x3\x6\x2\x2b\x0\x0\x0\x64"
|
data/spec/tcp_server_spec.rb
CHANGED
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.
|
4
|
+
version: 1.2.0
|
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:
|
12
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -155,22 +155,6 @@ dependencies:
|
|
155
155
|
- - ! '>='
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
|
-
- !ruby/object:Gem::Dependency
|
159
|
-
name: ruby-prof
|
160
|
-
requirement: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
|
-
requirements:
|
163
|
-
- - ! '>='
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
version: '0'
|
166
|
-
type: :development
|
167
|
-
prerelease: false
|
168
|
-
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
|
-
requirements:
|
171
|
-
- - ! '>='
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
174
158
|
description:
|
175
159
|
email: atimin@gmail.com
|
176
160
|
executables: []
|