lib/arduino_firmata/arduino.rb in arduino_firmata-0.2.5 vs lib/arduino_firmata/arduino.rb in arduino_firmata-0.2.6

- old
+ new

@@ -1,13 +1,14 @@ module ArduinoFirmata class Arduino include EventEmitter - attr_reader :version, :status + attr_reader :version, :status, :nonblock_io def initialize(serial_name, params) + @nonblock_io = !!params[:nonblock_io] @status = Status::CLOSE @wait_for_data = 0 @execute_multi_byte_command = 0 @multi_byte_channel = 0 @stored_input_data = [] @@ -158,15 +159,23 @@ end private def write(cmd) return if status == Status::CLOSE - @serial.write cmd.chr + if nonblock_io + @serial.write_nonblock cmd.chr + else + @serial.write cmd.chr + end end def read return if status == Status::CLOSE - @serial.read 9600 rescue EOFError + if nonblock_io + @serial.read_nonblock 9600 rescue EOFError + else + @serial.read 9600 rescue EOFError + end end def process_input StringIO.new(String read).each_byte.each do |input_data| command = nil