#!/bin/bash
SCOPE=192.168.2.49
PORT=5555
if [ -z "$TMP" ]
then
TMP=/tmp
fi
FILE=$TMP/image$$.raw
BFILE=$FILE.bmp
BATCH=0
DELAY=
while getopts ":bBd:" OPT
do
case $OPT in
b) BATCH=1
;;
B) BATCH=1
;;
d) DELAY=$OPTARG
;;
*) >&2 echo Invalid argument
exit 1
;;
esac
done
shift $((OPTIND-1))
RESULT="$1"
if [ -z "$RESULT" ]
then
>&2 echo Usage: scopesnap [-B] [-d delay] file [file ...]
>&2 echo Where file is a file name
>&2 echo ending with the format you want
>&2 echo "(e.g., jpg or png or pdf)"
>&2 echo If you include -B of -b
>&2 echo the image will not be opened after capture
>&2 echo "If you include -d there will be a delay (in seconds)"
>&2 echo after each capture
>&2 echo 73 de WD5GNR
exit 1
fi
echo -n 'Reading from '
echo "*IDN?" | nc $SCOPE $PORT
if [ ! $? == 0 ]
then
>&2 echo Scope not found. Aborting
exit 2
fi
while [ ! -z "$1" ]
do
RESULT="$1"
echo Reading data for "$RESULT"
echo ":DISP:DATA?" | nc $SCOPE $PORT >$FILE
SIZE=`ls -l $FILE | cut -d ' ' -f 5`
SIZE=`expr $SIZE - 11`
tail -c $SIZE $FILE >$BFILE
if convert $BFILE "$RESULT"
then
echo Wrote "$RESULT"
else
>&2 echo Error writing "$RESULT"
fi
rm $FILE $BFILE
if [ "$BATCH" == 0 ]
then
xdg-open "$RESULT" &
fi
shift
if [ ! -z "$DELAY" ]
then
echo Delaying $DELAY seconds
sleep $DELAY
fi
done
exit 0