vision_mate 0.1.2 → 0.1.3

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: 1e2e9ed2987b07be1525567b32a3d7042e891c5e
4
- data.tar.gz: 988fdb4f1a9763fb54c13bf89541780af9f84344
3
+ metadata.gz: 8862e4a3e6fc5d74ed601f4cd4a084b4d49bd684
4
+ data.tar.gz: be967aa4c5c8319bdfd85a1e91c9533579ee8fa8
5
5
  SHA512:
6
- metadata.gz: be57dbd5aa4c94ed4621c6d366bb7ee37ec902615ddf4e6537ee1e360076f17022dbc6f1fbea05b94fecd5ee98f146e9d2c688697c93a7f7d4f08094074d4b1b
7
- data.tar.gz: a1e1e669cde65ffe6c7ec19a2656cda0b4080fd64017c2454d02fb75195683f6798eed7bf2d6f87079f8584cc0187c9fb960fc1e119525e44b935648bde444cb
6
+ metadata.gz: 1044d370cdaf50827df903e04a806e4e0b4e6a6542534adf73780e06a56704cea10770cf54302a5b53a666364a6a5e8e0f1fd52663c5fe9466c04d4a1bf33492
7
+ data.tar.gz: e790bffc421236831a23a8508997e3461df7580056fa5200fbc0d191f944f8959adaaa6fe02cc6d4d50e96e96236033db3e98d02a51c5a85991ecb68688854cb
@@ -4,7 +4,8 @@ module VisionMate
4
4
  #
5
5
  module Configuration
6
6
  class << self
7
- attr_accessor :host, :port
7
+ attr_accessor :host, :port, :timeout
8
8
  end
9
+ self.timeout ||= 2
9
10
  end
10
11
  end
@@ -11,7 +11,10 @@ module VisionMate
11
11
  class Net::OpenTimeout; end
12
12
 
13
13
  def self.connect(host, port, telnet_class = Net::Telnet)
14
- new(telnet_class.new("Host" => host, "Port" => port))
14
+ @telnet_connection ||= telnet_class.new(
15
+ "Host" => host, "Port" => port, "Timeout" => Configuration.timeout
16
+ )
17
+ new(@telnet_connection)
15
18
  rescue Net::OpenTimeout, Timeout::Error
16
19
  raise CouldNotConnect, "Failed to connect to #{host}:#{port}"
17
20
  rescue SocketError
@@ -31,19 +34,28 @@ module VisionMate
31
34
  end
32
35
 
33
36
  def initiate_scan
34
- telnet_connection.cmd("String" => "S", "Match" => /OK/)
37
+ telnet_command("S")
35
38
  wait_for_data
36
39
  end
37
40
 
38
41
  private
39
42
 
43
+ def telnet_command(string)
44
+ telnet_connection.cmd("String" => string, "Match" => /OK/)
45
+ rescue Net::ReadTimeout, Timeout::Error
46
+ retries ||= 0
47
+ raise CouldNotConnect, "Telnet command timed out: #{string}" if retries == 5
48
+ retries += 1
49
+ retry
50
+ end
51
+
40
52
  def wait_for_data
41
53
  sleep 0.1 while scanner_status["finished_scan"]
42
54
  sleep 0.1 until scanner_status["data_ready"]
43
55
  end
44
56
 
45
57
  def scanner_status
46
- result = telnet_connection.cmd("String" => "L", "Match" => /OK/)
58
+ result = telnet_command "L"
47
59
  status = strip_prefix(result)
48
60
  status_names = %w{initializing scanning finished_scan data_ready
49
61
  data_sent rack96 empty error}
@@ -63,11 +75,11 @@ module VisionMate
63
75
  end
64
76
 
65
77
  def retrieve_data
66
- telnet_connection.cmd("String" => "D", "Match" => /OK/)
78
+ telnet_command "D"
67
79
  end
68
80
 
69
81
  def set_scanner_to_manual
70
- telnet_connection.cmd("String" => "M0", "Match" => /OK/)
82
+ telnet_command "M0"
71
83
  end
72
84
 
73
85
  def strip_prefix(string)
@@ -1,3 +1,3 @@
1
1
  module VisionMate
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -14,6 +14,7 @@ describe "Integrating With a Scanner" do
14
14
  .and_return one_tube_string
15
15
  telnet.stub(:cmd).with(hash_including("String" => "L")).and_return("OK37")
16
16
  Net::Telnet.stub new: telnet
17
+ VisionMate::Telnet.instance_variable_set(:@telnet_connection, nil)
17
18
  end
18
19
 
19
20
  it "scans a rack of tubes" do
@@ -1,4 +1,5 @@
1
1
  require_relative "../../lib/vision_mate/telnet"
2
+ require_relative "../../lib/vision_mate/configuration"
2
3
 
3
4
  class MockTelnet; end
4
5
 
@@ -6,6 +7,7 @@ describe VisionMate::Telnet do
6
7
  subject { VisionMate::Telnet.new(telnet_connection) }
7
8
  let(:uri) { double("uri", host: "192.168.3.132", port: "8000") }
8
9
  let(:telnet_connection) { double "telnet_connection" }
10
+ before { VisionMate::Telnet.instance_variable_set(:@telnet_connection, nil) }
9
11
 
10
12
  describe ".connect" do
11
13
  it "connects to telnet using a host and port" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vision_mate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Jackson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-21 00:00:00.000000000 Z
12
+ date: 2014-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler