Permalink
Browse files

Add explicit timeout to serial port, fixing nil crash on linux

  • Loading branch information...
1 parent e870888 commit a171d5b4970451db49892355f0ef37c165e65ec2 @cibomahto cibomahto committed Feb 23, 2010
Showing with 28 additions and 6 deletions.
  1. +10 −3 utilities/set_clock.rb
  2. +18 −3 utilities/update_acl.rb
View
@@ -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
View
@@ -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"
@@ -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'

0 comments on commit a171d5b

Please sign in to comment.