Lab-Measurement-Legacy
view release on metacpan or search on metacpan
examples/Legacy/DAQ/DAQ_2024B view on Meta::CPAN
my (@want) = (qw(CH1 CH2 CH3 CH4 MATH REFA REFB REFC REFD));
if ( defined($chans) ) {
my (@l) = split( /\s*,\s*/, $chans ); # list requested chans
my (%hch); # hash of chans
foreach (@l) {
if (/^(ch)?([1-4])$/i) {
$hch{"CH$2"} = 1;
}
elsif (/^MATH$/i) {
$hch{"MATH"} = 1;
}
elsif (/^(REF)?([a-d])$/i) {
$hch{"REF$2"} = 1;
}
else {
carp("invalid channel '$_' requested");
}
}
@want = ( sort( keys(%hch) ) );
}
$s->connection->MuteTrace(1) unless $DEBUG;
foreach my $ch (@want) {
push( @acqch, $ch ) if $s->get_visible($ch);
print_errors( $s, "in DAQ setup" ) if $DEBUG;
}
# pre-DAQ setup to restore afterwards
my $header = $s->get_header();
my $sverb = $s->get_verbose();
my $data_width = $s->get_data_width();
my $data_encoding = $s->get_data_encoding();
my $acq_state = $s->get_acquire_state(); # for post-acq restore
my $acq_stopafter = $s->get_acquire_stopafter();
$s->connection->MuteTrace(0) unless $DEBUG;
$s->set_header(1);
$s->set_verbose(0);
$s->set_data_width(1);
$s->set_data_encoding('RPBINARY'); # max efficiency
$s->set_acquire_state('STOP');
$s->set_acquire_stopafter('SEQUENCE');
print_errors( $s, "after DAQ setup" ) if $DEBUG;
print "...ready to go!\n" if $VERBOSE;
StartRun();
my $event = 0;
while ( ( $nev <= 0 || $event != $nev ) && !$SHUTDOWN ) {
$s->set_acquire_state('RUN');
print "\tRead... " if $VERBOSE;
if ( defined($selfdelay) ) {
sleep($selfdelay);
$s->trigger();
}
MuteTrace(1) unless $DEBUG; # don't need all the BUSY? checks.
while ( !$SHUTDOWN ) {
last if !$s->test_busy();
sleep(0.05);
}
MuteTrace(0) unless $DEBUG;
my $tev = gettimeofday();
$event++;
NextEvent();
print "Event ", $event, " \@ t=$tev ", scalar( localtime($tev) ),
" .. reading"
if $VERBOSE;
foreach my $ch (@acqch) {
$s->get_waveform($ch);
}
print_errors( $s, "after event" ) if $DEBUG;
print "\n" if $VERBOSE;
}
print_errors( $s, "after last event" ) if $DEBUG;
#cleanup
$s->connection->MuteTrace(1) unless $DEBUG;
$s->set_data_width($data_width);
$s->set_data_encoding($data_encoding);
$s->set_acquire_stopafter($acq_stopafter);
$s->set_acquire_state($acq_state);
$s->set_locked(0);
$s->set_header($header);
$s->set_verbose($sverb);
print_errors( $s, "after cleanup" ) if $DEBUG;
$s->connection->MuteTrace(0) unless $DEBUG;
StopRun();
my $tend = gettimeofday();
print "STOP $event events @ t=$tend ", scalar( localtime($tend) ), "\n"
if $VERBOSE;
}
sub usage {
print "$0 [options] outputfile\n";
print " OPTIONS:\n";
print " -n --nevents=# number of events to take,0=infinity\n";
print " -I --ID='string' store ID with run header\n";
print " -c --channels='chans' channels to read (def: all visible)\n";
print " -s --self=T self-trigger, every T seconds\n";
print " -S --Setup=N load scope setup N (1..10)\n";
print " -f --force force overwrite of output file\n";
print " --tmc_address=N use /dev/usbtmcN device\n";
print " --visa_name=V use VISA style device spec:\n";
print " USB:0xAAAA::0xBBBB::SERIAL::INSTR\n";
print " 0xAAAA = vendor id, 0xBBBB = product id\n";
print " -u --usb_serial=SERIAL select by scope SERIAL \n";
print " if no 'scope selection' options given, first scope is used\n";
print " -d --debug turn on debug\n";
print " -q --quiet quiet mode, supress messages\n";
print " -h -? --help this text\n";
}
( run in 2.335 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )