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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d4a4f49cb1b960fd3a81c184dbd1e84d29dc78d
4
- data.tar.gz: b35ddd07f62e4a52cba914312ca763241adc56b6
3
+ metadata.gz: 9bfc4ab5ae4c4ed48a369aaefccbee4b77de616a
4
+ data.tar.gz: 68b8ae930193f7e0496318ec397bde02c5ca4a97
5
5
  SHA512:
6
- metadata.gz: 570c55b4ca6753936afea1613deb8b73bd5f7a24d4e5eba5f852340255397ecf6ac9f88df16eebe0ea6249b35a8d65245d465b0ed721023a0c2622394eafb3ba
7
- data.tar.gz: ec1686f610240118875fe48d161cb8b77edc6281c84c31b8b310a934ac83142b36018a2b0ea6d941b1dd867af15798c5f3c58ddb21e985da71d9a071e6acd4cf
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, :datatype => :bit, :format => :modicon}
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, :datatype => :word, :format => :modicon}
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) {|slice| result += sl.read_holding_registers(slice.first, slice.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
- (addr + 400001).to_s
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
@@ -1,5 +1,5 @@
1
1
  module Modbus
2
2
  module Cli
3
- VERSION = "0.0.11"
3
+ VERSION = "0.0.12"
4
4
  end
5
5
  end
@@ -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.11
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-02-13 00:00:00.000000000 Z
11
+ date: 2017-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmodbus