1 #!/usr/bin/perl 2 # 3 # get_dac.pl -- 140601 by Bill Kibler 4 # 5 # Usage: 6 # perl ./get_dac.pl /dev/ttyUSB0 tf 7 # tf 80.1 8 9 # util to pass command to dac board 10 use Device::SerialPort; 11 12 # get command to use 13 ($device, $cmmd, $other) = @ARGV; 14 if($device eq "") { 15 print "usage: get_dac.pl device command ( /dev/tty??? for dac )\n"; 16 exit(0); 17 } 18 if($cmmd eq "") { 19 print "usage: get_dac.pl device command ( command to send to dac )\n"; 20 exit(0); 21 } 22 23 # get start time of run 24 $date = `date`; 25 26 my $port = Device::SerialPort->new("$device"); 27 $port->user_msg(ON); 28 $port->databits(8); 29 $port->baudrate(19200); 30 $port->parity("none"); 31 $port->stopbits(1); 32 $port->write_settings; 33 34 # needed to clear buffer 35 $port->lookclear; 36 37 # do send command - get analog 0 38 $port->write("$cmmd\n"); 39 # get results and print it 40 do_print () ; 41 42 exit; 43 44 ###### subs ######## 45 sub do_print { 46 while(1) { 47 my $byte=$port->read(1); 48 if ( $byte eq ">") { 49 last; 50 } 51 print "$byte"; 52 } 53 54 }