2010-01-06 23:49:33 +01:00
|
|
|
require 'rubygems'
|
|
|
|
require 'optparse'
|
|
|
|
require 'serialport'
|
|
|
|
|
|
|
|
|
|
|
|
options_parser = OptionParser.new do |opts|
|
|
|
|
opts.banner = "Usage: stream [options] gcode-file"
|
|
|
|
opts.on('-v', '--verbose', 'Output more information') do
|
|
|
|
$verbose = true
|
|
|
|
end
|
2010-01-07 23:14:29 +01:00
|
|
|
|
|
|
|
opts.on('-p', '--prebuffer', 'Prebuffer commands') do
|
|
|
|
$prebuffer = true
|
|
|
|
end
|
2010-01-06 23:49:33 +01:00
|
|
|
|
|
|
|
opts.on('-h', '--help', 'Display this screen') do
|
|
|
|
puts opts
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
options_parser.parse!
|
|
|
|
if ARGV.empty?
|
|
|
|
puts options_parser
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2010-06-28 23:29:58 +02:00
|
|
|
# SerialPort.open('/dev/tty.FireFly-A964-SPP-1', 115200) do |sp|
|
|
|
|
SerialPort.open('/dev/tty.usbserial-A9007QcR', 9600) do |sp|
|
|
|
|
|
2010-02-27 19:55:09 +01:00
|
|
|
sp.write("\r\n\r\n");
|
2010-03-14 23:45:31 +01:00
|
|
|
sleep 1
|
2010-01-06 23:49:33 +01:00
|
|
|
ARGV.each do |file|
|
|
|
|
puts "Processing file #{file}"
|
2010-03-14 23:45:31 +01:00
|
|
|
prebuffer = $prebuffer ? 20 : 0
|
2010-01-06 23:49:33 +01:00
|
|
|
File.readlines(file).each do |line|
|
2010-01-07 23:14:29 +01:00
|
|
|
next if line.strip == ''
|
2010-01-06 23:49:33 +01:00
|
|
|
puts line.strip
|
2010-01-07 23:14:29 +01:00
|
|
|
sp.write("#{line.strip}\r\n");
|
2010-01-06 23:49:33 +01:00
|
|
|
if prebuffer == 0
|
2010-01-07 23:14:29 +01:00
|
|
|
begin
|
|
|
|
result = sp.gets.strip
|
2010-02-27 19:55:09 +01:00
|
|
|
puts "Grbl >> #{result}" unless result == '' or result == 'ok'
|
2010-01-07 23:14:29 +01:00
|
|
|
end while result != 'ok'
|
2010-01-06 23:49:33 +01:00
|
|
|
else
|
|
|
|
prebuffer -= 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-06-28 23:29:58 +02:00
|
|
|
puts "Done."
|
|
|
|
sleep 500
|
2010-01-06 23:49:33 +01:00
|
|
|
end
|