#!/usr/bin/perl
#
# util to pass command to dacs board
# > ./get_dacs.pl /dev/ttyUSB0 h
#
# may need to do "sudo apt-get install libdevice-serialport-perl"
use Device::SerialPort;

# get comand to use
($device,$cmmd, $other) = @ARGV;
if($device eq "") {
  print "usage: get_dacs.pl device command ( /dev/tty??? for dacs )\n";
  exit(0);
}
if($cmmd eq "") {
  print "usage: get_dacs.pl device command ( command to send to dacs )\n";
  exit(0);
}

my $port = Device::SerialPort->new("$device");
$port->user_msg(ON);
$port->databits(8);
$port->baudrate(19200);
$port->parity("none");
$port->stopbits(1);
$port->write_settings;

# needed to clear buffer
$port->lookclear; 

# do send command - get ?
$port->write("$cmmd\n");

# get results and print it
do_print () ;

exit;

###### subs ########
sub do_print {
  while(1) {
    my $byte=$port->read(1);
    if ( $byte eq ">") {
       last;
    }
    if ( $byte eq "\r") {
       $byte="";
    }
    print "$byte";
  }
 
}

