Skip to content
This repository has been archived by the owner on Aug 12, 2019. It is now read-only.

Commit

Permalink
always read/write properly (removes non_blocking option)
Browse files Browse the repository at this point in the history
  • Loading branch information
phemmer committed Jun 27, 2014
1 parent 69bde2f commit 3ec9b13
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions lib/arduino_firmata/arduino.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ module ArduinoFirmata
class Arduino
include EventEmitter

attr_reader :version, :status, :nonblock_io, :eventmachine
attr_reader :version, :status, :eventmachine

def initialize(serialport_name, params)
@serialport_name = serialport_name
@nonblock_io = !!params[:nonblock_io]
@eventmachine = !!params[:eventmachine]
@read_byte_size = eventmachine ? 256 : 9600
@process_input_interval = eventmachine ? 0.0001 : 0.01
Expand Down Expand Up @@ -164,27 +163,14 @@ def servo_write(pin, angle)
private
def write(cmd)
return if status == Status::CLOSE
if nonblock_io
begin
@serial.write_nonblock cmd.chr
rescue Errno::EAGAIN
sleep 0.1
retry
end
else
@serial.write cmd.chr
end
@serial.write cmd.chr
end

def read
return if status == Status::CLOSE
data = nil
begin
if nonblock_io
data = @serial.read_nonblock @read_byte_size
else
data = @serial.read @read_byte_size
end
data = @serial.readpartial @read_byte_size
rescue IOError, EOFError => e
end
data
Expand Down

0 comments on commit 3ec9b13

Please sign in to comment.