Remove '\r' from serial datastream
This commit is contained in:
@@ -13,7 +13,11 @@ ActiveRecord::Base.establish_connection(connection_details)
|
|||||||
|
|
||||||
# # Open connection to serial port
|
# # 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)
|
||||||
#
|
lines = ""
|
||||||
|
for i in 0..22
|
||||||
|
lines = lines+ser.readline("\n").gsub(/\r/, '')
|
||||||
|
end
|
||||||
|
|
||||||
# # read until newline
|
# # read until newline
|
||||||
# response = ser.readline("\r")
|
# response = ser.readline("\r")
|
||||||
# response.chomp!
|
# response.chomp!
|
||||||
@@ -21,8 +25,8 @@ ser = SerialPort.new("/dev/ttyUSB1", 9600, 7, 1, SerialPort::EVEN)
|
|||||||
|
|
||||||
sync = Synchronizer.new
|
sync = Synchronizer.new
|
||||||
#lines = File.read("example_blurp.txt")[rand(1500)..-1]
|
#lines = File.read("example_blurp.txt")[rand(1500)..-1]
|
||||||
lines = ser.readpartial(4096) # read max 4k of data
|
|
||||||
p "There are #{lines.length} characters"
|
p "There are #{lines.length} characters"
|
||||||
|
p lines
|
||||||
while (!lines.nil? && lines.length > 0)
|
while (!lines.nil? && lines.length > 0)
|
||||||
lines = sync.handle_byte_stream(lines)
|
lines = sync.handle_byte_stream(lines)
|
||||||
#p lines
|
#p lines
|
||||||
|
|||||||
Reference in New Issue
Block a user