modbus-cli 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/modbus-cli/commands_common.rb +20 -2
- data/lib/modbus-cli/read_command.rb +14 -2
- data/lib/modbus-cli/version.rb +1 -1
- data/spec/read_command_spec.rb +7 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bfc4ab5ae4c4ed48a369aaefccbee4b77de616a
|
4
|
+
data.tar.gz: 68b8ae930193f7e0496318ec397bde02c5ca4a97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58f0b3fa331dc2c2862006cf09022a2b9cff0fbfbfc0713f6b86c1c225b0319937731aaa3364fe7b18ca8fdc09fc99ec69c51d2296ea096e0eb02da3ff6bb73b
|
7
|
+
data.tar.gz: a72aeef88e8c9117620826487e8ba55a865765ed5f633f2af9d58f07b6904730c4c965e3a0dfb323f7b2676a021ddd860f7dea55fcaa945becc6bf6b3e534960
|
@@ -84,6 +84,10 @@ module Modbus
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
def addr_area
|
88
|
+
address[:area]
|
89
|
+
end
|
90
|
+
|
87
91
|
|
88
92
|
def schneider_match(address)
|
89
93
|
schneider_match = address.match /%M([FWD])?(\d+)/i
|
@@ -94,10 +98,13 @@ module Modbus
|
|
94
98
|
result[:datatype] = :bit
|
95
99
|
when 'W', 'w'
|
96
100
|
result[:datatype] = :word
|
101
|
+
result[:area] = :holding_registers
|
97
102
|
when 'F', 'f'
|
98
103
|
result[:datatype] = :float
|
104
|
+
result[:area] = :holding_registers
|
99
105
|
when 'D', 'd'
|
100
106
|
result[:datatype] = :dword
|
107
|
+
result[:area] = :holding_registers
|
101
108
|
end
|
102
109
|
end
|
103
110
|
end
|
@@ -109,9 +116,20 @@ module Modbus
|
|
109
116
|
offset = address.to_i
|
110
117
|
case offset
|
111
118
|
when 1..99999
|
112
|
-
{:offset => offset - 1,
|
119
|
+
{ :offset => offset - 1,
|
120
|
+
:datatype => :bit,
|
121
|
+
:format => :modicon }
|
122
|
+
# 100001..199999 inputs are not supported
|
123
|
+
when 300001..399999
|
124
|
+
{ :offset => offset - 300001,
|
125
|
+
:datatype => :word,
|
126
|
+
:format => :modicon,
|
127
|
+
:area => :input_registers }
|
113
128
|
when 400001..499999
|
114
|
-
{:offset => offset - 400001,
|
129
|
+
{ :offset => offset - 400001,
|
130
|
+
:datatype => :word,
|
131
|
+
:format => :modicon,
|
132
|
+
:area => :holding_registers }
|
115
133
|
end
|
116
134
|
end
|
117
135
|
end
|
@@ -110,7 +110,14 @@ module Modbus
|
|
110
110
|
|
111
111
|
def read_data_words(sl)
|
112
112
|
result = []
|
113
|
-
read_range.each_slice(MAX_READ_WORD_COUNT)
|
113
|
+
read_range.each_slice(MAX_READ_WORD_COUNT) do |slice|
|
114
|
+
case addr_area
|
115
|
+
when :input_registers
|
116
|
+
result += sl.read_input_registers(slice.first, slice.count)
|
117
|
+
else # assume holding registers
|
118
|
+
result += sl.read_holding_registers(slice.first, slice.count)
|
119
|
+
end
|
120
|
+
end
|
114
121
|
result
|
115
122
|
end
|
116
123
|
|
@@ -155,7 +162,12 @@ module Modbus
|
|
155
162
|
when :bit
|
156
163
|
(addr + 1).to_s
|
157
164
|
when :word, :int
|
158
|
-
|
165
|
+
case addr_area
|
166
|
+
when :input_registers
|
167
|
+
(addr + 300001).to_s
|
168
|
+
else # default :read_holding_registers
|
169
|
+
(addr + 400001).to_s
|
170
|
+
end
|
159
171
|
end
|
160
172
|
end
|
161
173
|
end
|
data/lib/modbus-cli/version.rb
CHANGED
data/spec/read_command_spec.rb
CHANGED
@@ -10,14 +10,19 @@ describe Modbus::Cli::ReadCommand do
|
|
10
10
|
stub_tcpip
|
11
11
|
end
|
12
12
|
|
13
|
-
it 'can read registers' do
|
13
|
+
it 'can read holding registers' do
|
14
14
|
client, slave = standard_connect_helper '1.2.3.4', 502
|
15
15
|
slave.should_receive(:read_holding_registers).with(100, 10).and_return((0..9).to_a)
|
16
16
|
cmd.run %w(read 1.2.3.4 %MW100 10)
|
17
17
|
stdout.should match(/^\s*%MW105\s*5$/)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
it 'can read input registers' do
|
21
|
+
client, slave = standard_connect_helper '1.2.3.4', 502
|
22
|
+
slave.should_receive(:read_input_registers).with(100, 10).and_return((0..9).to_a)
|
23
|
+
cmd.run %w(read 1.2.3.4 300101 10)
|
24
|
+
stdout.should match(/^\s*300106\s*5$/)
|
25
|
+
end
|
21
26
|
|
22
27
|
it 'can read floating point numbers' do
|
23
28
|
client, slave = standard_connect_helper '1.2.3.4', 502
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modbus-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tallak Tveide
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmodbus
|