require "rubygems" require "bundler/setup" require "active_record" require "serialport" require "state_pattern" project_root = File.dirname(File.absolute_path(__FILE__)) Dir.glob(project_root + "/app/models/*.rb").each{|f| require f} Dir.glob(project_root + "/app/helpers/*.rb").each{|f| require f} connection_details = YAML::load(File.open('config/database.yml')) ActiveRecord::Base.establish_connection(connection_details) if __FILE__ == $0 begin # Open connection to serial port ser = SerialPort.new("/dev/ttyUSB1", 9600, 7, 1, SerialPort::EVEN) lines = "" for i in 0..21 lines = lines+ser.readline("\n").gsub(/\r/, '') end rescue p "Serialport Error - reverting to 'example_blurp.txt'" lines = File.read("example_blurp.txt")[rand(1500)..-1] p "There are #{lines.length} characters" p lines end # # Process the received lines # sync = Synchronizer.new while (!lines.nil? && lines.length > 0) lines = sync.handle_byte_stream(lines) #p lines end end #p sync