Module: WallE::SerialSnoop

Extended by:
Logger, SerialSnoop
Included in:
SerialSnoop
Defined in:
lib/wall_e/serial_snoop.rb

Instance Method Summary collapse

Methods included from Logger

error, info, log

Instance Method Details

#locate_portsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/wall_e/serial_snoop.rb', line 9

def locate_ports
  ports = Dir['/dev/*'].grep(/usb|acm/)
  board = nil
  if ports.any?
    what = 'serial port'
    what << 's' unless ports.one?

    info "Found possible #{what} #{ports}"
    ports.each do |port|
      begin
        info "Connecting to #{port}..."
        board = Firmata::Board.new(port)
        info "Connected to #{port}."
        break # we've found a board
      rescue => e
        error e.message
        board = nil
      end
    end
  else
    error 'Error: No USB devices detected'
  end

  error 'Error: Unable to connect to USB device' unless board

  board
end