#!/usr/local/bin/perl ## ## triangle_source - uses a DAC channel to sweep the current from 0-1mA. The ## target eac, channel, and number of steps in the sweep can be specified on ## the command line. ## ## Usage: triange_source > ## Example triangle_source eac1 0 200 ## sends out a triangle wave on channel 0 of eac1, outputs triangle wave in 200 steps ## per cycle. ## ## bhimebau 9/14/04 - script creation use Socket; if (@ARGV != 3) { print "\nUSAGE: triangle_source \n"; print "EXAMPLE: triangle_source eac1 2 20\n"; print "Repeatedly outputs triangle wave on DAC 2 of eac1 at 20 steps/cycle\n\n"; exit; } $eac=shift; $channel=shift; $steps_per_cycle=shift; if (($channel>15)||($channel<0)) { print "error - channel number must be between 0 and 15\n"; exit; } if (($steps_per_cycle>512)||($steps_per_cycle<0)) { print "error - data must be between 0 and 512\n"; exit; } $step_size = 1023/($steps_per_cycle*2); # Socket setup $iaddr = inet_aton("$eac") || die "no host: $eac"; $paddr = sockaddr_in("17000",$iaddr); $proto = getprotobyname("tcp"); socket(S,PF_INET,SOCK_STREAM,$proto) || die "socket: $!"; connect(S, $paddr) || die "connect: $!"; select(S); $|=1; select("stdout"); $cdir=0; while (1) { if ($dac_dat>=1023) { $cdir=1; $dac_dat=1023; } if ($dac_dat<=0) { $cdir=0; $dac_dat=0; close(S); sleep(2); socket(S,PF_INET,SOCK_STREAM,$proto) || die "socket: $!"; connect(S, $paddr) || die "connect: $!"; select(S); $|=1; select("stdout"); } $dac_string=sprintf("D%02x%03xZ",$channel,$dac_dat); print S "$dac_string\n"; $result = ; if ($cdir==0) { $dac_dat=$dac_dat+$step_size; } else { $dac_dat=$dac_dat-$step_size; } } close (S);