modbus-cli 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f4ff66a5456651880910145cd8919117d404c80
4
+ data.tar.gz: 4d09091363edb51efc393e4ca97eec6953856e4a
5
+ SHA512:
6
+ metadata.gz: c5511ea5098afc1dd9ab931a11b3164eca5c3baa29a6a6970a5b12236131b71b9b5ccb1f9d312c8f21c3ca070e179786ee27d579fc66ebd828ed989d37f097ac
7
+ data.tar.gz: d946a25b721a6cf072f4ac9fa83f3d43bd82918ca5cf0bf02ab4c3557cce4c342d73c7112a18d888dbd741382baa6f7e970329206c428c35ea2bd5311f7ad245
data/.gitignore CHANGED
File without changes
@@ -1,4 +1,5 @@
1
1
  rvm:
2
+ - 2.1.0
2
3
  - 1.8.7
3
4
  - 1.9.3
4
5
  - jruby
data/Gemfile CHANGED
File without changes
@@ -21,7 +21,7 @@ The pure ruby gem should run on most rubies.
21
21
  Quick Start
22
22
  -----------
23
23
 
24
- Lets start by reading five words from our device startig from address %MW100.
24
+ Let's start by reading five words from our device starting from address %MW100.
25
25
 
26
26
  $ modbus read 192.168.0.1 %MW100 5
27
27
 
@@ -187,7 +187,7 @@ License
187
187
 
188
188
  (The MIT License)
189
189
 
190
- Copyright (C) 2011 Tallak Tveide
190
+ Copyright (C) 2011-2015 Tallak Tveide
191
191
 
192
192
  Permission is hereby granted, free of charge, to any person obtaining a copy
193
193
  of this software and associated documentation files (the "Software"), to
data/Rakefile CHANGED
File without changes
File without changes
File without changes
@@ -7,15 +7,13 @@ module Modbus
7
7
  extend CommandsCommon::ClassMethods
8
8
  include CommandsCommon
9
9
 
10
- parameter 'FILES ...', 'restore data in FILES to original devices (created by modbus read command)', :attribute_name => :files do |f|
11
- f.map do |filename|
12
- YAML.load_file(filename).dup.tap do |ff|
13
- #parameter takes presedence
14
- ff[:host] = host || ff[:host]
15
- ff[:port] = port || ff[:port]
16
- ff[:slave] = slave || ff[:slave]
17
- ff[:offset] = offset || ff[:offset]
18
- end
10
+ parameter 'FILES ...', 'restore data in FILES to original devices (created by modbus read command)' do |f|
11
+ YAML.load_file(f).dup.tap do |ff|
12
+ #parameter takes presedence
13
+ ff[:host] = host || ff[:host]
14
+ ff[:port] = port || ff[:port]
15
+ ff[:slave] = slave || ff[:slave]
16
+ ff[:offset] = offset || ff[:offset]
19
17
  end
20
18
  end
21
19
 
@@ -34,12 +32,12 @@ module Modbus
34
32
  debug_option
35
33
 
36
34
  def execute
37
- host_ids = files.map {|d| d[:host] }.sort.uniq
35
+ host_ids = files_list.map {|d| d[:host] }.sort.uniq
38
36
  host_ids.each {|host_id| execute_host host_id }
39
37
  end
40
38
 
41
39
  def execute_host(host_id)
42
- slave_ids = files.select {|d| d[:host] == host_id }.map {|d| d[:slave] }.sort.uniq
40
+ slave_ids = files_list.select {|d| d[:host] == host_id }.map {|d| d[:slave] }.sort.uniq
43
41
  ModBus::TCPClient.connect(host_id, port) do |client|
44
42
  slave_ids.each {|slave_id| execute_slave host_id, slave_id, client }
45
43
  end
@@ -48,7 +46,7 @@ module Modbus
48
46
  def execute_slave(host_id, slave_id, client)
49
47
  client.with_slave(slave_id) do |slave|
50
48
  slave.debug = true if debug?
51
- files.select {|d| d[:host] == host_id && d[:slave] == slave_id }.each do |file_data|
49
+ files_list.select {|d| d[:host] == host_id && d[:slave] == slave_id }.each do |file_data|
52
50
  execute_single_file slave, file_data
53
51
  end
54
52
  end
File without changes
@@ -1,5 +1,5 @@
1
1
  module Modbus
2
2
  module Cli
3
- VERSION = "0.0.9"
3
+ VERSION = "0.0.10"
4
4
  end
5
5
  end
@@ -16,19 +16,19 @@ module Modbus
16
16
  debug_option
17
17
  timeout_option
18
18
 
19
- parameter 'VALUES ...', 'values to write, nonzero counts as true for discrete values', :attribute_name => :values do |vv|
19
+ parameter 'VALUES ...', 'values to write, nonzero counts as true for discrete values' do |v|
20
20
  case addr_type
21
21
 
22
22
  when :bit
23
- int_parameter vv, 0, 1
23
+ int_parameter v, 0, 1
24
24
  when :word
25
- int_parameter vv, 0, 0xffff
25
+ int_parameter v, 0, 0xffff
26
26
  when :int
27
- int_parameter vv, -32768, 32767
27
+ int_parameter v, -32768, 32767
28
28
  when :dword
29
- int_parameter vv, 0, 0xffffffff
29
+ int_parameter v, 0, 0xffffffff
30
30
  when :float
31
- vv.map {|v| Float(v) }
31
+ Float(v)
32
32
  end
33
33
  end
34
34
 
@@ -55,11 +55,11 @@ module Modbus
55
55
  end
56
56
 
57
57
  def write_coils(sl)
58
- sliced_write_coils sl, addr_offset, values
58
+ sliced_write_coils sl, addr_offset, values_list
59
59
  end
60
60
 
61
61
  def write_words(sl)
62
- sliced_write_registers sl, addr_offset, values.pack('S*').unpack('S*')
62
+ sliced_write_registers sl, addr_offset, values_list.pack('S*').unpack('S*')
63
63
  end
64
64
 
65
65
  def write_floats(sl)
@@ -72,14 +72,12 @@ module Modbus
72
72
 
73
73
  def pack_and_write(sl, format)
74
74
  # the word ordering is wrong. calling reverse two times effectively swaps every pair
75
- sliced_write_registers(sl, addr_offset, values.reverse.pack("#{format}*").unpack('n*').reverse)
75
+ sliced_write_registers(sl, addr_offset, values_list.reverse.pack("#{format}*").unpack('n*').reverse)
76
76
  end
77
77
 
78
78
  def int_parameter(vv, min, max)
79
- vv.map {|v| Integer(v) }.tap do |values|
80
- values.each do |v|
81
- raise ArgumentError, "Value should be in the range #{min}..#{max}" unless (min..max).member? v
82
- end
79
+ Integer(vv).tap do |v|
80
+ raise ArgumentError, "Value should be in the range #{min}..#{max}" unless (min..max).member? v
83
81
  end
84
82
  end
85
83
  end
@@ -20,8 +20,8 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # specify any dependencies here; for example:
22
22
  # s.add_development_dependency "rspec"
23
- s.add_runtime_dependency "rmodbus", '~> 1.1'
24
- s.add_runtime_dependency "clamp", '~> 0.3'
25
- s.add_development_dependency "rspec", '~> 2.7'
23
+ s.add_runtime_dependency "rmodbus", '~> 1.2'
24
+ s.add_runtime_dependency "clamp", '~> 0.6.5'
25
+ s.add_development_dependency "rspec", '~> 3.2'
26
26
  s.add_development_dependency "rake", '~> 0.9'
27
27
  end
@@ -8,20 +8,20 @@ describe Modbus::Cli::DumpCommand do
8
8
  end
9
9
 
10
10
  it 'reads the file and write the contents to the original device' do
11
- client = mock 'client'
12
- slave = mock 'slave'
11
+ client = double 'client'
12
+ slave = double 'slave'
13
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
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
- cmd.run %w(dump dump.yml)
17
+ cmd.run %w(dump dump.yml)
18
18
  end
19
19
 
20
20
  it 'can read two files from separate hosts' do
21
- client1 = mock 'client1'
22
- client2 = mock 'client2'
23
- slave1 = mock 'slave1'
24
- slave2 = mock 'slave2'
21
+ client1 = double 'client1'
22
+ client2 = double 'client2'
23
+ slave1 = double 'slave1'
24
+ slave2 = double 'slave2'
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' })
@@ -35,9 +35,9 @@ describe Modbus::Cli::DumpCommand do
35
35
  end
36
36
 
37
37
  it 'can dump two files from separate slaves on same host' do
38
- client1 = mock 'client1'
39
- slave1 = mock 'slave1'
40
- slave2 = mock 'slave2'
38
+ client1 = double 'client1'
39
+ slave1 = double 'slave1'
40
+ slave2 = double 'slave2'
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 })
@@ -50,8 +50,8 @@ describe Modbus::Cli::DumpCommand do
50
50
  end
51
51
 
52
52
  it 'can dump two files from one slave' do
53
- client1 = mock 'client1'
54
- slave1 = mock 'slave1'
53
+ client1 = double 'client1'
54
+ slave1 = double 'slave1'
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)
@@ -69,7 +69,7 @@ describe Modbus::Cli::DumpCommand do
69
69
  end
70
70
 
71
71
  it 'accepts the --slave <id> parameter' do
72
- client = mock 'client'
72
+ client = double 'client'
73
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
74
  ModBus::TCPClient.should_receive(:connect).with('1.2.3.4', 502).and_yield(client)
75
75
  client.should_receive(:with_slave).with(99)
@@ -77,8 +77,8 @@ describe Modbus::Cli::DumpCommand do
77
77
  end
78
78
 
79
79
  it 'accepts the --offset <n> parameter with modicon addressing' do
80
- client = mock 'client'
81
- slave = mock 'slave'
80
+ client = double 'client'
81
+ slave = double 'slave'
82
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
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)
@@ -87,8 +87,8 @@ describe Modbus::Cli::DumpCommand do
87
87
  end
88
88
 
89
89
  it 'accepts the --offset <n> parameter with schneider addressing' do
90
- client = mock 'client'
91
- slave = mock 'slave'
90
+ client = double 'client'
91
+ slave = double 'slave'
92
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
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)
@@ -97,8 +97,8 @@ describe Modbus::Cli::DumpCommand do
97
97
  end
98
98
 
99
99
  it 'has a --debug flag' do
100
- client = mock 'client'
101
- slave = mock 'slave'
100
+ client = double 'client'
101
+ slave = double 'slave'
102
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
103
  ModBus::TCPClient.should_receive(:connect).with('1.2.3.4', 502).and_yield(client)
104
104
  client.should_receive(:with_slave).with(5).and_yield(slave)
File without changes
@@ -130,7 +130,7 @@ describe Modbus::Cli::ReadCommand do
130
130
  end
131
131
 
132
132
  it 'has a --slave parameter' do
133
- client = mock 'client'
133
+ client = double 'client'
134
134
  ModBus::TCPClient.should_receive(:connect).with('X', 502).and_yield(client)
135
135
  client.should_receive(:with_slave).with(99)
136
136
  cmd.run %w(read --slave 99 X 101 1)
@@ -139,9 +139,9 @@ describe Modbus::Cli::ReadCommand do
139
139
  it 'can write the output from reading registers to a yaml file using the -o <filename> parameter' do
140
140
  client, slave = standard_connect_helper '1.2.3.4', 502
141
141
  slave.should_receive(:read_holding_registers).with(100, 1).and_return([1])
142
- file_mock = mock('file')
143
- File.should_receive(:open).and_yield(file_mock)
144
- file_mock.should_receive(:puts).with({:host => '1.2.3.4', :port => 502, :slave => 1, :offset => '400101', :data => [1]}.to_yaml)
142
+ file_double = double('file')
143
+ File.should_receive(:open).and_yield(file_double)
144
+ file_double.should_receive(:puts).with({:host => '1.2.3.4', :port => 502, :slave => 1, :offset => '400101', :data => [1]}.to_yaml)
145
145
  cmd.run %w(read --output filename.yml 1.2.3.4 %MW100 1)
146
146
  stdout.should_not match(/./)
147
147
  end
@@ -149,9 +149,9 @@ describe Modbus::Cli::ReadCommand do
149
149
  it 'can write the output from reading coils to a yaml file using the -o <filename> parameter' do
150
150
  client, slave = standard_connect_helper '1.2.3.4', 502
151
151
  slave.should_receive(:read_coils).with(100, 1).and_return([1])
152
- file_mock = mock('file')
153
- File.should_receive(:open).and_yield(file_mock)
154
- file_mock.should_receive(:puts).with({:host => '1.2.3.4', :port => 502, :slave => 1, :offset => '101', :data => [1]}.to_yaml)
152
+ file_double = double('file')
153
+ File.should_receive(:open).and_yield(file_double)
154
+ file_double.should_receive(:puts).with({:host => '1.2.3.4', :port => 502, :slave => 1, :offset => '101', :data => [1]}.to_yaml)
155
155
  cmd.run %w(read --output filename.yml 1.2.3.4 %M100 1)
156
156
  stdout.should_not match(/./)
157
157
  end
@@ -3,6 +3,17 @@ require 'clamp'
3
3
  require 'stringio'
4
4
  require 'modbus-cli'
5
5
 
6
+ # keep old fashioned should syntax for now, would be better to convert to new
7
+ # syntax
8
+ RSpec.configure do |config|
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.syntax = [:should, :expect]
11
+ end
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = [:should, :expect]
14
+ end
15
+ end
16
+
6
17
  # Borrowed from Clamp tests
7
18
  module OutputCapture
8
19
 
@@ -30,13 +41,14 @@ module OutputCapture
30
41
  end
31
42
 
32
43
  def stub_tcpip
33
- TCPSocket.stub!(:new) # prevent comms with actual PLC or device
44
+ # prevent any real TCP communications
45
+ allow(TCPSocket).to receive(:new).and_return("TCPSocket")
34
46
  end
35
47
 
36
48
 
37
49
  def standard_connect_helper(address, port)
38
- client = mock 'client'
39
- slave = mock 'slave'
50
+ client = double 'client'
51
+ slave = double 'slave'
40
52
  ModBus::TCPClient.should_receive(:connect).with(address, port).and_yield(client)
41
53
  client.should_receive(:with_slave).with(1).and_yield(slave)
42
54
  return client, slave
@@ -96,7 +96,7 @@ describe Modbus::Cli::WriteCommand do
96
96
  end
97
97
 
98
98
  it 'has a --slave parameter' do
99
- client = mock 'client'
99
+ client = double 'client'
100
100
  ModBus::TCPClient.should_receive(:connect).with('X', 502).and_yield(client)
101
101
  client.should_receive(:with_slave).with(99)
102
102
  cmd.run %w(write --slave 99 X 101 1)
data/tust.yml CHANGED
File without changes
metadata CHANGED
@@ -1,78 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modbus-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
5
- prerelease:
4
+ version: 0.0.10
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tallak Tveide
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-12 00:00:00.000000000 Z
11
+ date: 2015-06-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rmodbus
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '1.1'
19
+ version: '1.2'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '1.1'
26
+ version: '1.2'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: clamp
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '0.3'
33
+ version: 0.6.5
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '0.3'
40
+ version: 0.6.5
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '2.7'
47
+ version: '3.2'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
- version: '2.7'
54
+ version: '3.2'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0.9'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0.9'
78
69
  description: Command line interface to communicate over Modbus TCP
@@ -83,8 +74,8 @@ executables:
83
74
  extensions: []
84
75
  extra_rdoc_files: []
85
76
  files:
86
- - .gitignore
87
- - .travis.yml
77
+ - ".gitignore"
78
+ - ".travis.yml"
88
79
  - Gemfile
89
80
  - README.markdown
90
81
  - Rakefile
@@ -104,27 +95,25 @@ files:
104
95
  - tust.yml
105
96
  homepage: http://www.github.com/tallakt/modbus-cli
106
97
  licenses: []
98
+ metadata: {}
107
99
  post_install_message:
108
100
  rdoc_options: []
109
101
  require_paths:
110
102
  - lib
111
103
  required_ruby_version: !ruby/object:Gem::Requirement
112
- none: false
113
104
  requirements:
114
- - - ! '>='
105
+ - - ">="
115
106
  - !ruby/object:Gem::Version
116
107
  version: '0'
117
108
  required_rubygems_version: !ruby/object:Gem::Requirement
118
- none: false
119
109
  requirements:
120
- - - ! '>='
110
+ - - ">="
121
111
  - !ruby/object:Gem::Version
122
112
  version: '0'
123
113
  requirements: []
124
114
  rubyforge_project: modbus-cli
125
- rubygems_version: 1.8.24
115
+ rubygems_version: 2.2.2
126
116
  signing_key:
127
- specification_version: 3
117
+ specification_version: 4
128
118
  summary: Modbus command line
129
119
  test_files: []
130
- has_rdoc: