send-gcode.pl 735 B

1234567891011121314151617181920212223242526272829303132333435363738
  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;
  13. $serial->connect($ARGV[0], $ARGV[1]);
  14. 1 until $serial->is_connected;
  15. print "Connected to printer\n";
  16. {
  17. local $/ = "\n";
  18. Slic3r::open(\my $fh, '<', $ARGV[2])
  19. or die "Unable to open $ARGV[2]: $!\n";
  20. binmode $fh, ':utf8';
  21. while (<$fh>) {
  22. $serial->send($_);
  23. }
  24. close $fh;
  25. }
  26. while ((my $queue_size = $serial->queue_size) > 0) {
  27. printf "Queue size: %d\n", $queue_size;
  28. }
  29. $serial->disconnect;
  30. __END__