modbus-cli 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,6 +37,10 @@ module Modbus
37
37
  end
38
38
  end
39
39
 
40
+ def host_option
41
+ option ["-p", "--port"], 'PORT', "use TCP port", :default => 502
42
+ end
43
+
40
44
  def output_option
41
45
  end
42
46
  end
@@ -12,6 +12,7 @@ module Modbus
12
12
  YAML.load_file(filename).dup.tap do |ff|
13
13
  #parameter takes presedence
14
14
  ff[:host] = host || ff[:host]
15
+ ff[:port] = port || ff[:port]
15
16
  ff[:slave] = slave || ff[:slave]
16
17
  ff[:offset] = offset || ff[:offset]
17
18
  end
@@ -19,6 +20,7 @@ module Modbus
19
20
  end
20
21
 
21
22
  option ["-h", "--host"], 'ADDR', "use the address/hostname ADDR instead of the stored one"
23
+ host_option
22
24
 
23
25
  option ["-s", "--slave"], 'ID', "use slave ID instead of the stored one" do |s|
24
26
  Integer(s).tap {|slave| raise ArgumentError 'Slave address should be in the range 0..255' unless (0..255).member? slave }
@@ -36,7 +38,7 @@ module Modbus
36
38
 
37
39
  def execute_host(host_id)
38
40
  slave_ids = files.select {|d| d[:host] == host_id }.map {|d| d[:slave] }.sort.uniq
39
- ModBus::TCPClient.connect(host_id) do |client|
41
+ ModBus::TCPClient.connect(host_id, port) do |client|
40
42
  slave_ids.each {|slave_id| execute_slave host_id, slave_id, client }
41
43
  end
42
44
  end
@@ -14,6 +14,7 @@ module Modbus
14
14
  format_options
15
15
  slave_option
16
16
  host_parameter
17
+ host_option
17
18
  address_parameter
18
19
  option ["-o", "--output"], 'FILE', "write results to file FILE"
19
20
 
@@ -58,7 +59,7 @@ module Modbus
58
59
 
59
60
  def write_data_to_file(data)
60
61
  File.open(output, 'w') do |file|
61
- file.puts({ :host => host, :slave => slave, :offset => address_to_s(addr_offset, :modicon), :data => data }.to_yaml)
62
+ file.puts({ :host => host, :port => port, :slave => slave, :offset => address_to_s(addr_offset, :modicon), :data => data }.to_yaml)
62
63
  end
63
64
  end
64
65
 
@@ -70,7 +71,7 @@ module Modbus
70
71
  end
71
72
 
72
73
  def execute
73
- ModBus::TCPClient.connect(host) do |cl|
74
+ ModBus::TCPClient.connect(host, port) do |cl|
74
75
  cl.with_slave(slave) do |sl|
75
76
  if output then
76
77
  case addr_type
@@ -1,5 +1,5 @@
1
1
  module Modbus
2
2
  module Cli
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -11,6 +11,7 @@ module Modbus
11
11
  format_options
12
12
  slave_option
13
13
  host_parameter
14
+ host_option
14
15
  address_parameter
15
16
 
16
17
  parameter 'VALUES ...', 'values to write, nonzero counts as true for discrete values', :attribute_name => :values do |vv|
@@ -32,7 +33,7 @@ module Modbus
32
33
 
33
34
 
34
35
  def execute
35
- ModBus::TCPClient.connect(host) do |cl|
36
+ ModBus::TCPClient.connect(host, port) do |cl|
36
37
  cl.with_slave(slave) do |sl|
37
38
  case addr_type
38
39
  when :bit
@@ -10,8 +10,8 @@ describe Modbus::Cli::DumpCommand do
10
10
  it 'reads the file and write the contents to the original device' do
11
11
  client = mock 'client'
12
12
  slave = mock 'slave'
13
- YAML.should_receive(:load_file).with('dump.yml').and_return(:host => '1.2.3.4', :slave => 5, :offset => 400123, :data => [4, 5, 6])
14
- ModBus::TCPClient.should_receive(:connect).with('1.2.3.4').and_yield(client)
13
+ 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])
14
+ ModBus::TCPClient.should_receive(:connect).with('1.2.3.4', 502).and_yield(client)
15
15
  client.should_receive(:with_slave).with(5).and_yield(slave)
16
16
  slave.should_receive(:write_holding_registers).with(122, [4, 5, 6])
17
17
  cmd.run %w(dump dump.yml)
@@ -25,8 +25,8 @@ describe Modbus::Cli::DumpCommand do
25
25
  yml = {:host => 'X', :slave => 5, :offset => 400010, :data => [99]}
26
26
  YAML.should_receive(:load_file).with('a.yml').and_return(yml)
27
27
  YAML.should_receive(:load_file).with('b.yml').and_return(yml.dup.tap {|y| y[:host] = 'Y' })
28
- ModBus::TCPClient.should_receive(:connect).with('X').and_yield(client1)
29
- ModBus::TCPClient.should_receive(:connect).with('Y').and_yield(client2)
28
+ ModBus::TCPClient.should_receive(:connect).with('X', 502).and_yield(client1)
29
+ ModBus::TCPClient.should_receive(:connect).with('Y', 502).and_yield(client2)
30
30
  client1.should_receive(:with_slave).with(5).and_yield(slave1)
31
31
  client2.should_receive(:with_slave).with(5).and_yield(slave2)
32
32
  slave1.should_receive(:write_holding_registers).with(9, [99])
@@ -41,7 +41,7 @@ describe Modbus::Cli::DumpCommand do
41
41
  yml = {:host => 'X', :slave => 5, :offset => 400010, :data => [99]}
42
42
  YAML.should_receive(:load_file).with('a.yml').and_return(yml)
43
43
  YAML.should_receive(:load_file).with('b.yml').and_return(yml.dup.tap {|y| y[:slave] = 99 })
44
- ModBus::TCPClient.should_receive(:connect).with('X').and_yield(client1)
44
+ ModBus::TCPClient.should_receive(:connect).with('X', 502).and_yield(client1)
45
45
  client1.should_receive(:with_slave).with(5).and_yield(slave1)
46
46
  client1.should_receive(:with_slave).with(99).and_yield(slave2)
47
47
  slave1.should_receive(:write_holding_registers).with(9, [99])
@@ -55,7 +55,7 @@ describe Modbus::Cli::DumpCommand do
55
55
  yml = {:host => 'X', :slave => 5, :offset => 400010, :data => [99]}
56
56
  YAML.should_receive(:load_file).with('a.yml').and_return(yml)
57
57
  YAML.should_receive(:load_file).with('b.yml').and_return(yml.dup)
58
- ModBus::TCPClient.should_receive(:connect).with('X').and_yield(client1)
58
+ ModBus::TCPClient.should_receive(:connect).with('X', 502).and_yield(client1)
59
59
  client1.should_receive(:with_slave).with(5).and_yield(slave1)
60
60
  slave1.should_receive(:write_holding_registers).with(9, [99])
61
61
  slave1.should_receive(:write_holding_registers).with(9, [99])
@@ -63,15 +63,15 @@ describe Modbus::Cli::DumpCommand do
63
63
  end
64
64
 
65
65
  it 'accepts the --host <hostname> parameter' do
66
- YAML.should_receive(:load_file).with('dump.yml').and_return(:host => '1.2.3.4', :slave => 5, :offset => 123, :data => [4, 5, 6])
67
- ModBus::TCPClient.should_receive(:connect).with('Y')
66
+ YAML.should_receive(:load_file).with('dump.yml').and_return(:host => '1.2.3.4', :port => 502, :slave => 5, :offset => 123, :data => [4, 5, 6])
67
+ ModBus::TCPClient.should_receive(:connect).with('Y', 502)
68
68
  cmd.run %w(dump --host Y dump.yml)
69
69
  end
70
70
 
71
71
  it 'accepts the --slave <id> parameter' do
72
72
  client = mock 'client'
73
- YAML.should_receive(:load_file).with('dump.yml').and_return(:host => '1.2.3.4', :slave => 5, :offset => 123, :data => [4, 5, 6])
74
- ModBus::TCPClient.should_receive(:connect).with('1.2.3.4').and_yield(client)
73
+ YAML.should_receive(:load_file).with('dump.yml').and_return(:host => '1.2.3.4', :port => 502, :slave => 5, :offset => 123, :data => [4, 5, 6])
74
+ ModBus::TCPClient.should_receive(:connect).with('1.2.3.4', 502).and_yield(client)
75
75
  client.should_receive(:with_slave).with(99)
76
76
  cmd.run %w(dump --slave 99 dump.yml)
77
77
  end
@@ -79,8 +79,8 @@ describe Modbus::Cli::DumpCommand do
79
79
  it 'accepts the --offset <n> parameter with modicon addressing' do
80
80
  client = mock 'client'
81
81
  slave = mock 'slave'
82
- YAML.should_receive(:load_file).with('dump.yml').and_return(:host => '1.2.3.4', :slave => 5, :offset => 123, :data => [4, 5, 6])
83
- ModBus::TCPClient.should_receive(:connect).with('1.2.3.4').and_yield(client)
82
+ YAML.should_receive(:load_file).with('dump.yml').and_return(:host => '1.2.3.4', :port => 502, :slave => 5, :offset => 123, :data => [4, 5, 6])
83
+ ModBus::TCPClient.should_receive(:connect).with('1.2.3.4', 502).and_yield(client)
84
84
  client.should_receive(:with_slave).with(5).and_yield(slave)
85
85
  slave.should_receive(:write_holding_registers).with(100, [4, 5, 6])
86
86
  cmd.run %w(dump --offset 400101 dump.yml)
@@ -89,8 +89,8 @@ describe Modbus::Cli::DumpCommand do
89
89
  it 'accepts the --offset <n> parameter with schneider addressing' do
90
90
  client = mock 'client'
91
91
  slave = mock 'slave'
92
- YAML.should_receive(:load_file).with('dump.yml').and_return(:host => '1.2.3.4', :slave => 5, :offset => 123, :data => [4, 5, 6])
93
- ModBus::TCPClient.should_receive(:connect).with('1.2.3.4').and_yield(client)
92
+ YAML.should_receive(:load_file).with('dump.yml').and_return(:host => '1.2.3.4', :port => 502, :slave => 5, :offset => 123, :data => [4, 5, 6])
93
+ ModBus::TCPClient.should_receive(:connect).with('1.2.3.4', 502).and_yield(client)
94
94
  client.should_receive(:with_slave).with(5).and_yield(slave)
95
95
  slave.should_receive(:write_holding_registers).with(100, [4, 5, 6])
96
96
  cmd.run %w(dump --offset %MW100 dump.yml)
@@ -11,7 +11,7 @@ describe Modbus::Cli::ReadCommand do
11
11
  end
12
12
 
13
13
  it 'can read registers' do
14
- client, slave = standard_connect_helper '1.2.3.4'
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$/)
@@ -20,28 +20,28 @@ describe Modbus::Cli::ReadCommand do
20
20
 
21
21
 
22
22
  it 'can read floating point numbers' do
23
- client, slave = standard_connect_helper '1.2.3.4'
23
+ client, slave = standard_connect_helper '1.2.3.4', 502
24
24
  slave.should_receive(:read_holding_registers).with(100, 4).and_return([52429, 17095, 52429, 17095])
25
25
  cmd.run %w(read 1.2.3.4 %MF100 2)
26
26
  stdout.should match(/^\s*%MF102\s*99[.]9(00[0-9]*)?$/)
27
27
  end
28
28
 
29
29
  it 'should display numbers with good precision' do
30
- client, slave = standard_connect_helper '1.2.3.4'
30
+ client, slave = standard_connect_helper '1.2.3.4', 502
31
31
  slave.should_receive(:read_holding_registers).and_return([1049, 16286])
32
32
  cmd.run %w(read 1.2.3.4 %MF100 1)
33
33
  stdout.should match(/^\s*%MF100\s*1[.]2345\d*$/)
34
34
  end
35
35
 
36
36
  it 'can read double word numbers' do
37
- client, slave = standard_connect_helper '1.2.3.4'
37
+ client, slave = standard_connect_helper '1.2.3.4', 502
38
38
  slave.should_receive(:read_holding_registers).with(100, 4).and_return([16959, 15, 16959, 15])
39
39
  cmd.run %w(read 1.2.3.4 %MD100 2)
40
40
  stdout.should match(/^\s*%MD102\s*999999$/)
41
41
  end
42
42
 
43
43
  it 'can read coils' do
44
- client, slave = standard_connect_helper '1.2.3.4'
44
+ client, slave = standard_connect_helper '1.2.3.4', 502
45
45
  slave.should_receive(:read_coils).with(100, 10).and_return([1, 0] * 5)
46
46
  cmd.run %w(read 1.2.3.4 %M100 10)
47
47
  stdout.should match(/^\s*%M105\s*0$/)
@@ -61,53 +61,53 @@ describe Modbus::Cli::ReadCommand do
61
61
  end
62
62
 
63
63
  it 'should split large reads into smaller chunks for words' do
64
- client, slave = standard_connect_helper '1.2.3.4'
64
+ client, slave = standard_connect_helper '1.2.3.4', 502
65
65
  slave.should_receive(:read_holding_registers).with(100, 125).and_return([1, 0] * 1000)
66
66
  slave.should_receive(:read_holding_registers).with(225, 25).and_return([1, 0] * 1000)
67
67
  cmd.run %w(read 1.2.3.4 %MW100 150)
68
68
  end
69
69
 
70
70
  it 'should split large reads into smaller chunks for coils' do
71
- client, slave = standard_connect_helper '1.2.3.4'
71
+ client, slave = standard_connect_helper '1.2.3.4', 502
72
72
  slave.should_receive(:read_coils).with(100, 2000).and_return([1, 0] * 1000)
73
73
  slave.should_receive(:read_coils).with(2100, 1000).and_return([1, 0] * 500)
74
74
  cmd.run %w(read 1.2.3.4 %M100 3000)
75
75
  end
76
76
 
77
77
  it 'can read registers as ints' do
78
- client, slave = standard_connect_helper '1.2.3.4'
78
+ client, slave = standard_connect_helper '1.2.3.4', 502
79
79
  slave.should_receive(:read_holding_registers).with(100, 1).and_return([0xffff])
80
80
  cmd.run %w(read --int 1.2.3.4 %MW100 1)
81
81
  stdout.should match(/^\s*%MW100\s*-1$/)
82
82
  end
83
83
 
84
84
  it 'can read registers as floats' do
85
- client, slave = standard_connect_helper '1.2.3.4'
85
+ client, slave = standard_connect_helper '1.2.3.4', 502
86
86
  slave.should_receive(:read_holding_registers).with(100, 2).and_return([0,0])
87
87
  cmd.run %w(read --float 1.2.3.4 %MW100 1)
88
88
  end
89
89
 
90
90
  it 'can read registers as dwords' do
91
- client, slave = standard_connect_helper '1.2.3.4'
91
+ client, slave = standard_connect_helper '1.2.3.4', 502
92
92
  slave.should_receive(:read_holding_registers).with(100, 2).and_return([0,0])
93
93
  cmd.run %w(read --dword 1.2.3.4 %MW100 1)
94
94
  end
95
95
 
96
96
  it 'can read registers as words' do
97
- client, slave = standard_connect_helper '1.2.3.4'
97
+ client, slave = standard_connect_helper '1.2.3.4', 502
98
98
  slave.should_receive(:read_holding_registers).with(100, 1).and_return([0])
99
99
  cmd.run %w(read --word 1.2.3.4 %MD100 1)
100
100
  end
101
101
 
102
102
  it 'accepts Modicon addresses for coils' do
103
- client, slave = standard_connect_helper '1.2.3.4'
103
+ client, slave = standard_connect_helper '1.2.3.4', 502
104
104
  slave.should_receive(:read_coils).with(100, 10).and_return([1, 0] * 5)
105
105
  cmd.run %w(read 1.2.3.4 101 10)
106
106
  stdout.should match(/^\s*106\s*0$/)
107
107
  end
108
108
 
109
109
  it 'accepts Modicon addresses for registers' do
110
- client, slave = standard_connect_helper '1.2.3.4'
110
+ client, slave = standard_connect_helper '1.2.3.4', 502
111
111
  slave.should_receive(:read_holding_registers).with(100, 10).and_return((0..9).to_a)
112
112
  cmd.run %w(read 1.2.3.4 400101 10)
113
113
  stdout.should match(/^\s*400106\s*5$/)
@@ -115,14 +115,14 @@ describe Modbus::Cli::ReadCommand do
115
115
 
116
116
 
117
117
  it 'should accept the --modicon option to force modicon output' do
118
- client, slave = standard_connect_helper '1.2.3.4'
118
+ client, slave = standard_connect_helper '1.2.3.4', 502
119
119
  slave.should_receive(:read_holding_registers).with(100, 10).and_return((0..9).to_a)
120
120
  cmd.run %w(read --modicon 1.2.3.4 %MW100 10)
121
121
  stdout.should match(/^\s*400106\s*5$/)
122
122
  end
123
123
 
124
124
  it 'should accept the --schneider option to force schneider output' do
125
- client, slave = standard_connect_helper '1.2.3.4'
125
+ client, slave = standard_connect_helper '1.2.3.4', 502
126
126
  slave.should_receive(:read_holding_registers).with(100, 10).and_return((0..9).to_a)
127
127
  cmd.run %w(read --schneider 1.2.3.4 400101 10)
128
128
  stdout.should match(/^\s*%MW105\s*5$/)
@@ -130,27 +130,27 @@ describe Modbus::Cli::ReadCommand do
130
130
 
131
131
  it 'has a --slave parameter' do
132
132
  client = mock 'client'
133
- ModBus::TCPClient.should_receive(:connect).with('X').and_yield(client)
133
+ ModBus::TCPClient.should_receive(:connect).with('X', 502).and_yield(client)
134
134
  client.should_receive(:with_slave).with(99)
135
135
  cmd.run %w(read --slave 99 X 101 1)
136
136
  end
137
137
 
138
138
  it 'can write the output from reading registers to a yaml file using the -o <filename> parameter' do
139
- client, slave = standard_connect_helper '1.2.3.4'
139
+ client, slave = standard_connect_helper '1.2.3.4', 502
140
140
  slave.should_receive(:read_holding_registers).with(100, 1).and_return([1])
141
141
  file_mock = mock('file')
142
142
  File.should_receive(:open).and_yield(file_mock)
143
- file_mock.should_receive(:puts).with({:host => '1.2.3.4', :slave => 1, :offset => '400101', :data => [1]}.to_yaml)
143
+ file_mock.should_receive(:puts).with({:host => '1.2.3.4', :port => 502, :slave => 1, :offset => '400101', :data => [1]}.to_yaml)
144
144
  cmd.run %w(read --output filename.yml 1.2.3.4 %MW100 1)
145
145
  stdout.should_not match(/./)
146
146
  end
147
147
 
148
148
  it 'can write the output from reading coils to a yaml file using the -o <filename> parameter' do
149
- client, slave = standard_connect_helper '1.2.3.4'
149
+ client, slave = standard_connect_helper '1.2.3.4', 502
150
150
  slave.should_receive(:read_coils).with(100, 1).and_return([1])
151
151
  file_mock = mock('file')
152
152
  File.should_receive(:open).and_yield(file_mock)
153
- file_mock.should_receive(:puts).with({:host => '1.2.3.4', :slave => 1, :offset => '101', :data => [1]}.to_yaml)
153
+ file_mock.should_receive(:puts).with({:host => '1.2.3.4', :port => 502, :slave => 1, :offset => '101', :data => [1]}.to_yaml)
154
154
  cmd.run %w(read --output filename.yml 1.2.3.4 %M100 1)
155
155
  stdout.should_not match(/./)
156
156
  end
data/spec/spec_helper.rb CHANGED
@@ -34,10 +34,10 @@ def stub_tcpip
34
34
  end
35
35
 
36
36
 
37
- def standard_connect_helper(address)
37
+ def standard_connect_helper(address, port)
38
38
  client = mock 'client'
39
39
  slave = mock 'slave'
40
- ModBus::TCPClient.should_receive(:connect).with(address).and_yield(client)
40
+ ModBus::TCPClient.should_receive(:connect).with(address, port).and_yield(client)
41
41
  client.should_receive(:with_slave).with(1).and_yield(slave)
42
42
  return client, slave
43
43
  end
@@ -10,26 +10,26 @@ describe Modbus::Cli::WriteCommand do
10
10
  end
11
11
 
12
12
  it 'can write to registers' do
13
- client, slave = standard_connect_helper 'HOST'
13
+ client, slave = standard_connect_helper 'HOST', 502
14
14
  slave.should_receive(:write_holding_registers).with(100, [1, 2, 3, 4])
15
15
  cmd.run %w(write HOST %MW100 1 2 3 4)
16
16
  end
17
17
 
18
18
 
19
19
  it 'can write floating point numbers' do
20
- client, slave = standard_connect_helper 'HOST'
20
+ client, slave = standard_connect_helper 'HOST', 502
21
21
  slave.should_receive(:write_holding_registers).with(100, [52429, 17095, 52429, 17095])
22
22
  cmd.run %w(write HOST %MF100 99.9 99.9)
23
23
  end
24
24
 
25
25
  it 'can write double word numbers' do
26
- client, slave = standard_connect_helper 'HOST'
26
+ client, slave = standard_connect_helper 'HOST', 502
27
27
  slave.should_receive(:write_holding_registers).with(100, [16959, 15, 16959, 15])
28
28
  cmd.run %w(write HOST %MD100 999999 999999)
29
29
  end
30
30
 
31
31
  it 'can write to coils' do
32
- client, slave = standard_connect_helper 'HOST'
32
+ client, slave = standard_connect_helper 'HOST', 502
33
33
  slave.should_receive(:write_multiple_coils).with(100, [1, 0, 1, 0, 1, 0, 0, 1, 1])
34
34
  cmd.run %w(write HOST %M100 1 0 1 0 1 0 0 1 1)
35
35
  end
@@ -45,58 +45,58 @@ describe Modbus::Cli::WriteCommand do
45
45
 
46
46
 
47
47
  it 'should split large writes in chunks for words' do
48
- client, slave = standard_connect_helper 'HOST'
48
+ client, slave = standard_connect_helper 'HOST', 502
49
49
  slave.should_receive(:write_holding_registers).with(100, (1..123).to_a)
50
50
  slave.should_receive(:write_holding_registers).with(223, (124..150).to_a)
51
51
  cmd.run %w(write HOST %MW100) + (1..150).to_a
52
52
  end
53
53
 
54
54
  it 'should split large writes in chunks for coils' do
55
- client, slave = standard_connect_helper 'HOST'
55
+ client, slave = standard_connect_helper 'HOST', 502
56
56
  slave.should_receive(:write_multiple_coils).with(100, [0, 1] * 984)
57
57
  slave.should_receive(:write_multiple_coils).with(2068, [0, 1] * 16)
58
58
  cmd.run %w(write HOST %M100) + [0, 1] * 1000
59
59
  end
60
60
 
61
61
  it 'can write to registers as ints' do
62
- client, slave = standard_connect_helper 'HOST'
62
+ client, slave = standard_connect_helper 'HOST', 502
63
63
  slave.should_receive(:write_holding_registers).with(100, [0xffff])
64
64
  cmd.run %w(write --int HOST %MW100 -1)
65
65
  end
66
66
 
67
67
  it 'can write to registers as floats' do
68
- client, slave = standard_connect_helper 'HOST'
68
+ client, slave = standard_connect_helper 'HOST', 502
69
69
  slave.should_receive(:write_holding_registers).with(100, [52429, 17095])
70
70
  cmd.run %w(write --float HOST %MW100 99.9)
71
71
  end
72
72
 
73
73
  it 'can write to registers as double words' do
74
- client, slave = standard_connect_helper 'HOST'
74
+ client, slave = standard_connect_helper 'HOST', 502
75
75
  slave.should_receive(:write_holding_registers).with(100, [16959, 15])
76
76
  cmd.run %w(write --dword HOST %MW100 999999)
77
77
  end
78
78
 
79
79
  it 'can write to registers as words' do
80
- client, slave = standard_connect_helper 'HOST'
80
+ client, slave = standard_connect_helper 'HOST', 502
81
81
  slave.should_receive(:write_holding_registers).with(100, [99])
82
82
  cmd.run %w(write --word HOST %MF100 99)
83
83
  end
84
84
 
85
85
  it 'can write to registers using Modicon addressing' do
86
- client, slave = standard_connect_helper 'HOST'
86
+ client, slave = standard_connect_helper 'HOST', 502
87
87
  slave.should_receive(:write_holding_registers).with(100, [1, 2, 3, 4])
88
88
  cmd.run %w(write HOST 400101 1 2 3 4)
89
89
  end
90
90
 
91
91
  it 'can write to coils using Modicon addressing' do
92
- client, slave = standard_connect_helper 'HOST'
92
+ client, slave = standard_connect_helper 'HOST', 502
93
93
  slave.should_receive(:write_multiple_coils).with(100, [1, 0, 1, 0, 1, 0, 0, 1, 1])
94
94
  cmd.run %w(write HOST 101 1 0 1 0 1 0 0 1 1)
95
95
  end
96
96
 
97
97
  it 'has a --slave parameter' do
98
98
  client = mock 'client'
99
- ModBus::TCPClient.should_receive(:connect).with('X').and_yield(client)
99
+ ModBus::TCPClient.should_receive(:connect).with('X', 502).and_yield(client)
100
100
  client.should_receive(:with_slave).with(99)
101
101
  cmd.run %w(write --slave 99 X 101 1)
102
102
  end
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
4
+ version: 0.0.5
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: 2011-12-02 00:00:00.000000000Z
12
+ date: 2011-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rmodbus
16
- requirement: &77908650 !ruby/object:Gem::Requirement
16
+ requirement: &75774940 !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: *77908650
24
+ version_requirements: *75774940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: clamp
27
- requirement: &77908400 !ruby/object:Gem::Requirement
27
+ requirement: &75774550 !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: *77908400
35
+ version_requirements: *75774550
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &77908170 !ruby/object:Gem::Requirement
38
+ requirement: &75774310 !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: *77908170
46
+ version_requirements: *75774310
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &77907940 !ruby/object:Gem::Requirement
49
+ requirement: &75774000 !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: *77907940
57
+ version_requirements: *75774000
58
58
  description: Command line interface to communicate over Modbus TCP
59
59
  email:
60
60
  - tallak@tveide.net
@@ -106,4 +106,3 @@ signing_key:
106
106
  specification_version: 3
107
107
  summary: Modbus command line
108
108
  test_files: []
109
- has_rdoc: