Better handling of boundary conditions
Trying with serialport.readpartial
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user