send-gcode.pl 717 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. BEGIN {
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. use local::lib "$FindBin::Bin/../local-lib";
  8. }
  9. use Slic3r;
  10. die "Usage: send-gcode.pl SERIALPORT BAUDRATE GCODE_FILE\n"
  11. if @ARGV != 3;
  12. my $serial = Slic3r::GCode::Sender->new($ARGV[0], $ARGV[1]);
  13. 1 until $serial->is_connected;
  14. print "Connected to printer\n";
  15. {
  16. local $/ = "\n";
  17. Slic3r::open(\my $fh, '<', $ARGV[2])
  18. or die "Unable to open $ARGV[2]: $!\n";
  19. binmode $fh, ':utf8';
  20. while (<$fh>) {
  21. $serial->send($_);
  22. }
  23. close $fh;
  24. }
  25. while ((my $queue_size = $serial->queue_size) > 0) {
  26. printf "Queue size: %d\n", $queue_size;
  27. }
  28. $serial->disconnect;
  29. __END__