modbus-cli 0.0.5 → 0.0.6
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/lib/modbus-cli/commands_common.rb +4 -0
- data/lib/modbus-cli/dump_command.rb +3 -0
- data/lib/modbus-cli/read_command.rb +3 -0
- data/lib/modbus-cli/version.rb +1 -1
- data/lib/modbus-cli/write_command.rb +3 -0
- data/spec/dump_command_spec.rb +12 -0
- data/spec/read_command_spec.rb +7 -0
- data/spec/write_command_spec.rb +7 -0
- metadata +11 -10
|
@@ -31,6 +31,8 @@ module Modbus
|
|
|
31
31
|
o
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
debug_option
|
|
35
|
+
|
|
34
36
|
def execute
|
|
35
37
|
host_ids = files.map {|d| d[:host] }.sort.uniq
|
|
36
38
|
host_ids.each {|host_id| execute_host host_id }
|
|
@@ -45,6 +47,7 @@ module Modbus
|
|
|
45
47
|
|
|
46
48
|
def execute_slave(host_id, slave_id, client)
|
|
47
49
|
client.with_slave(slave_id) do |slave|
|
|
50
|
+
slave.debug = true if debug?
|
|
48
51
|
files.select {|d| d[:host] == host_id && d[:slave] == slave_id }.each do |file_data|
|
|
49
52
|
execute_single_file slave, file_data
|
|
50
53
|
end
|
|
@@ -17,6 +17,7 @@ module Modbus
|
|
|
17
17
|
host_option
|
|
18
18
|
address_parameter
|
|
19
19
|
option ["-o", "--output"], 'FILE', "write results to file FILE"
|
|
20
|
+
debug_option
|
|
20
21
|
|
|
21
22
|
parameter 'COUNT', 'number of data to read', :attribute_name => :count do |c|
|
|
22
23
|
result = Integer(c)
|
|
@@ -73,6 +74,8 @@ module Modbus
|
|
|
73
74
|
def execute
|
|
74
75
|
ModBus::TCPClient.connect(host, port) do |cl|
|
|
75
76
|
cl.with_slave(slave) do |sl|
|
|
77
|
+
sl.debug = true if debug?
|
|
78
|
+
|
|
76
79
|
if output then
|
|
77
80
|
case addr_type
|
|
78
81
|
when :bit
|
data/lib/modbus-cli/version.rb
CHANGED
|
@@ -13,6 +13,7 @@ module Modbus
|
|
|
13
13
|
host_parameter
|
|
14
14
|
host_option
|
|
15
15
|
address_parameter
|
|
16
|
+
debug_option
|
|
16
17
|
|
|
17
18
|
parameter 'VALUES ...', 'values to write, nonzero counts as true for discrete values', :attribute_name => :values do |vv|
|
|
18
19
|
case addr_type
|
|
@@ -35,6 +36,8 @@ module Modbus
|
|
|
35
36
|
def execute
|
|
36
37
|
ModBus::TCPClient.connect(host, port) do |cl|
|
|
37
38
|
cl.with_slave(slave) do |sl|
|
|
39
|
+
sl.debug = true if debug?
|
|
40
|
+
|
|
38
41
|
case addr_type
|
|
39
42
|
when :bit
|
|
40
43
|
write_coils sl
|
data/spec/dump_command_spec.rb
CHANGED
|
@@ -95,6 +95,18 @@ describe Modbus::Cli::DumpCommand do
|
|
|
95
95
|
slave.should_receive(:write_holding_registers).with(100, [4, 5, 6])
|
|
96
96
|
cmd.run %w(dump --offset %MW100 dump.yml)
|
|
97
97
|
end
|
|
98
|
+
|
|
99
|
+
it 'has a --debug flag' do
|
|
100
|
+
client = mock 'client'
|
|
101
|
+
slave = mock 'slave'
|
|
102
|
+
YAML.should_receive(:load_file).with('dump.yml').and_return(:host => '1.2.3.4', :port => 502, :slave => 5, :offset => 400123, :data => [4, 5, 6])
|
|
103
|
+
ModBus::TCPClient.should_receive(:connect).with('1.2.3.4', 502).and_yield(client)
|
|
104
|
+
client.should_receive(:with_slave).with(5).and_yield(slave)
|
|
105
|
+
slave.should_receive(:write_holding_registers).with(122, [4, 5, 6])
|
|
106
|
+
slave.should_receive(:debug=).with(true)
|
|
107
|
+
cmd.run %w(dump --debug dump.yml)
|
|
108
|
+
end
|
|
109
|
+
|
|
98
110
|
end
|
|
99
111
|
|
|
100
112
|
|
data/spec/read_command_spec.rb
CHANGED
|
@@ -155,6 +155,13 @@ describe Modbus::Cli::ReadCommand do
|
|
|
155
155
|
stdout.should_not match(/./)
|
|
156
156
|
end
|
|
157
157
|
|
|
158
|
+
it 'has a --debug flag' do
|
|
159
|
+
client, slave = standard_connect_helper '1.2.3.4', 502
|
|
160
|
+
slave.should_receive(:read_holding_registers).with(100, 10).and_return((0..9).to_a)
|
|
161
|
+
slave.should_receive(:debug=).with(true)
|
|
162
|
+
cmd.run %w(read --debug 1.2.3.4 %MW100 10)
|
|
163
|
+
end
|
|
164
|
+
|
|
158
165
|
|
|
159
166
|
end
|
|
160
167
|
|
data/spec/write_command_spec.rb
CHANGED
|
@@ -101,6 +101,13 @@ describe Modbus::Cli::WriteCommand do
|
|
|
101
101
|
cmd.run %w(write --slave 99 X 101 1)
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
+
it 'has a --debug flag' do
|
|
105
|
+
client, slave = standard_connect_helper 'HOST', 502
|
|
106
|
+
slave.should_receive(:debug=).with(true)
|
|
107
|
+
slave.should_receive(:write_multiple_coils)
|
|
108
|
+
cmd.run %w(write --debug HOST 101 1)
|
|
109
|
+
end
|
|
110
|
+
|
|
104
111
|
end
|
|
105
112
|
|
|
106
113
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.6
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,11 +9,11 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2012-01-02 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rmodbus
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &73951000 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ~>
|
|
@@ -21,10 +21,10 @@ dependencies:
|
|
|
21
21
|
version: '1.1'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *73951000
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: clamp
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &73950700 !ruby/object:Gem::Requirement
|
|
28
28
|
none: false
|
|
29
29
|
requirements:
|
|
30
30
|
- - ~>
|
|
@@ -32,10 +32,10 @@ dependencies:
|
|
|
32
32
|
version: '0.3'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements: *
|
|
35
|
+
version_requirements: *73950700
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: rspec
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &73950440 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ~>
|
|
@@ -43,10 +43,10 @@ dependencies:
|
|
|
43
43
|
version: '2.7'
|
|
44
44
|
type: :development
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *73950440
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: rake
|
|
49
|
-
requirement: &
|
|
49
|
+
requirement: &73950160 !ruby/object:Gem::Requirement
|
|
50
50
|
none: false
|
|
51
51
|
requirements:
|
|
52
52
|
- - ~>
|
|
@@ -54,7 +54,7 @@ dependencies:
|
|
|
54
54
|
version: '0.9'
|
|
55
55
|
type: :development
|
|
56
56
|
prerelease: false
|
|
57
|
-
version_requirements: *
|
|
57
|
+
version_requirements: *73950160
|
|
58
58
|
description: Command line interface to communicate over Modbus TCP
|
|
59
59
|
email:
|
|
60
60
|
- tallak@tveide.net
|
|
@@ -106,3 +106,4 @@ signing_key:
|
|
|
106
106
|
specification_version: 3
|
|
107
107
|
summary: Modbus command line
|
|
108
108
|
test_files: []
|
|
109
|
+
has_rdoc:
|