Class: VisionMate::Telnet

Inherits:
Object
  • Object
show all
Defined in:
lib/vision_mate/telnet.rb

Defined Under Namespace

Classes: BadHostNameOrPort, CouldNotConnect, TubeReadError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(telnet_connection) ⇒ Telnet

Returns a new instance of Telnet.



21
22
23
24
# File 'lib/vision_mate/telnet.rb', line 21

def initialize(telnet_connection)
  self.telnet_connection = telnet_connection
  set_scanner_to_manual
end

Instance Attribute Details

#telnet_connectionObject

Returns the value of attribute telnet_connection.



5
6
7
# File 'lib/vision_mate/telnet.rb', line 5

def telnet_connection
  @telnet_connection
end

Class Method Details

.connect(host, port, telnet_class = Net::Telnet) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/vision_mate/telnet.rb', line 13

def self.connect(host, port, telnet_class = Net::Telnet)
  new(telnet_class.new("Host" => host, "Port" => port))
rescue Net::OpenTimeout, Timeout::Error
  raise CouldNotConnect, "Failed to connect to #{host}:#{port}"
rescue SocketError
  raise BadHostNameOrPort, "Malformed host name or port"
end

Instance Method Details

#initiate_scanObject



33
34
35
36
# File 'lib/vision_mate/telnet.rb', line 33

def initiate_scan
  telnet_connection.cmd("String" => "S", "Match" => /OK/)
  wait_for_data
end

#scanObject

Raises:



26
27
28
29
30
31
# File 'lib/vision_mate/telnet.rb', line 26

def scan
  initiate_scan
  result = retrieve_data
  raise TubeReadError, "One or more tubes not read" if result[/No Read/]
  strip_prefix(result)
end