class Calypso::SerialMonitor
Calypso's serial controller
Constants
- CALYPSO_EXIT
Calypso
application exit token.
Attributes
baud[R]
@return [Fixnum] Serial baud rate.
data[R]
@return [Array<String>] Array of data read from the serial port.
databits[R]
@return [Fixnum] Number of data bits per byte.
parity[R]
@return [Symbol] Connection parity.
portname[R]
@return [String] Path to the serial device.
stopbits[R]
@return [Fixnum] Number of stop bits.
Public Class Methods
new(port, baud = 9600, databits = 8, stopbits = 1, parity = SerialPort::NONE)
click to toggle source
Create a new serial port controller.
@param port [String] Path to the serial device. @param baud [Fixnum] Serial baud rate. @param databits [Fixnum] Number of data bits per byte. @param stopbits [Fixnum] Number of stop bits. @param parity [Symbol] Connection parity.
# File lib/calypso/serialmonitor.rb, line 49 def initialize(port, baud = 9600, databits = 8, stopbits = 1, parity = SerialPort::NONE) @port = SerialPort.new(port, baud, databits, stopbits, parity) @portname = port @baud = baud @databits = databits @stopbits = stopbits @parity = parity @data = nil @mutex = Mutex.new end
Public Instance Methods
monitor()
click to toggle source
Monitor the serial port.
@return [Boolean] Whether or not the application was manually stopped.
# File lib/calypso/serialmonitor.rb, line 63 def monitor running = true ary = [] manual_stop = false thread = Thread.new do while running do begin input = gets puts input if input.nil? @mutex.synchronize {running = false} manual_stop = true Thread.stop break end input.chomp! @port.write input @port.flush rescue Exception => e puts e.message exit end end end while (data = @port.gets.chomp) do if data.eql? CALYPSO_EXIT then Thread.kill thread ary.push data break end puts data ary.push data break unless running end thread.join unless manual_stop @port.close @data = ary manual_stop end