Skip to content

Commit

Permalink
Add explicit timeout to serial port, fixing nil crash on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
cibomahto committed Feb 23, 2010
1 parent e870888 commit a171d5b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
13 changes: 10 additions & 3 deletions utilities/set_clock.rb
@@ -1,15 +1,22 @@
#!/usr/bin/ruby

# TODO: Check that argv[0] contains a serial port
# TODO: If above fails, print usage info.

require "rubygems"
# From http://ruby-serialport.rubyforge.org/
require "serialport"

puts "Connecting to Arduino on #{ARGV[0]}"
SerialPort.open(ARGV[0], 9600, 8, 1, SerialPort::NONE) do |sp|
# Set serial port timeout to infinite (defaults to -1 on Linux)
sp.read_timeout = 0

sleep 5
puts "Connected?"
buf = ""; while (! /.* POWER_ON\n/.match(buf)) do
printf("%c", t = sp.getc)
puts "Waiting for POWER_ON message from Arduino"
buf = ""; while (! /.* POWER_ON.*\n/.match(buf)) do
t = sp.getc
printf("%c", t)
buf << t
end
now = Time.now
Expand Down
21 changes: 18 additions & 3 deletions utilities/update_acl.rb
@@ -1,5 +1,16 @@
#!/usr/bin/ruby

# To use this, set:
# HACKPGH_GOOGLE_USER to your HackPGH google apps account
# HACKPGH_GOOGLE_KEY to your password for said account
# HACKPGH_GOOGLE_MEMBER_SHEET to the members worksheet key (it's part of the URL)

# TODO: Check for existance of environment variables
# TODO: Check that argv[0] contains a serial port
# TODO: If either fails, print usage info.

# TODO: Check that we can open the serial port, before bothering to go out to the net?

require "rubygems"
# From http://github.com/gimite/google-spreadsheet-ruby
require "google_spreadsheet"
Expand All @@ -22,10 +33,14 @@
puts "Connecting to Arduino on port #{ARGV[0]}"

SerialPort.open(ARGV[0], 9600, 8, 1, SerialPort::NONE) do |sp|
# Set serial port timeout to infinite (defaults to -1 on Linux)
sp.read_timeout = 0

sleep 5
puts "Connected?"
buf = ""; while (! /.* POWER_ON\n/.match(buf)) do
printf("%c", t = sp.getc)
puts "Waiting for POWER_ON message from Arduino"
buf = ""; while (! /.* POWER_ON.*\n/.match(buf)) do
t = sp.getc
printf("%c", t)
buf << t
end
sp.write 'U'
Expand Down

0 comments on commit a171d5b

Please sign in to comment.