#!/usr/bin/perl
#
# get_dac.pl -- 140601 by Bill Kibler
#
# Usage:
# perl ./get_dac.pl /dev/ttyUSB0 tf
# tf   80.1

# util to pass command to dac board
use Device::SerialPort;

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

# get start time of run
$date = `date`;

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 analog 0
$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;
    }
    print "$byte";
  }

}
