Better handling of boundary conditions

Trying with serialport.readpartial
This commit is contained in:
Aart van Halteren
2013-06-26 16:03:28 -04:00
parent 58eee12fb5
commit 099d90c9d8
5 changed files with 34 additions and 14 deletions

View File

@@ -12,7 +12,7 @@ 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)
ser = SerialPort.new("/dev/ttyUSB1", 9600, 7, 1, SerialPort::EVEN)
#
# # read until newline
# response = ser.readline("\r")
@@ -20,9 +20,12 @@ ActiveRecord::Base.establish_connection(connection_details)
# print "#{response}\n"
sync = Synchronizer.new
lines = File.read("example_blurp.txt")[rand(500)..-1]
while (lines.length > 0)
#lines = File.read("example_blurp.txt")[rand(1500)..-1]
lines = ser.readpartial(4096) # read max 4k of data
p "There are #{lines.length} characters"
while (!lines.nil? && lines.length > 0)
lines = sync.handle_byte_stream(lines)
#p lines
end
p sync
#p sync