Class: Smalrubot::TxRx::Serial

Inherits:
Base
  • Object
show all
Defined in:
lib/smalrubot/tx_rx/serial.rb

Constant Summary collapse

BAUD =
19_200

Constants inherited from Base

Base::RETURN_CODE

Instance Method Summary collapse

Methods inherited from Base

#flush_read, #gets, #read, #write

Constructor Details

#initialize(options = {}) ⇒ Serial

Returns a new instance of Serial.



8
9
10
11
12
# File 'lib/smalrubot/tx_rx/serial.rb', line 8

def initialize(options={})
  @device = options[:device]
  @baud = options[:baud] || BAUD
  @first_write = true
end

Instance Method Details

#handshakeObject

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/smalrubot/tx_rx/serial.rb', line 18

def handshake
  while tty_devices.length > 0
    begin
      if on_windows?
        io; sleep 3
      end

      return super
    rescue BoardNotFound
      @tty_devices.shift
      if @io
        @io.close
      end
      @io = nil
    end
  end
  raise BoardNotFound
end

#ioObject



14
15
16
# File 'lib/smalrubot/tx_rx/serial.rb', line 14

def io
  @io ||= connect
end