handling of frame extended. Persisting Reading to database.
This commit is contained in:
@@ -11,25 +11,28 @@ 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)
|
||||
|
||||
# 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/, '')
|
||||
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
|
||||
|
||||
# # read until newline
|
||||
# response = ser.readline("\r")
|
||||
# response.chomp!
|
||||
# print "#{response}\n"
|
||||
|
||||
sync = Synchronizer.new
|
||||
#lines = File.read("example_blurp.txt")[rand(1500)..-1]
|
||||
p "There are #{lines.length} characters"
|
||||
p lines
|
||||
while (!lines.nil? && lines.length > 0)
|
||||
lines = sync.handle_byte_stream(lines)
|
||||
#p lines
|
||||
end
|
||||
|
||||
#p sync
|
||||
|
||||
Reference in New Issue
Block a user