Author Topic: Shell Script to take screen caps from DS1000Z  (Read 3996 times)

0 Members and 1 Guest are viewing this topic.

Offline wd5gnr

  • Regular Contributor
  • *
  • Posts: 179
Shell Script to take screen caps from DS1000Z
« on: June 10, 2015, 11:22:21 PM »
I was thinking this morning, I don't really need anything but shell script to read screen captures to jpg, png, pdf, etc. except Netcat and Imagemagic both of which are on most Linux systems. Here you go:

Save the file below into scopesnap and do a chmod +x on that file. Then run it like usual (put it on the path or use ./scopesnap). I'll also attach the file (but may have to rename it .txt, just rename it back).
By default it will open the file after capture (use -b to suppress) and you can capture more than one file with an optional delay (-d) after. Keep in mind the delay does not account for the natural delay of doing the data transfer.

The convert will handle .png, .jpg, .pdf, and lots more (see http://www.imagemagick.org/script/formats.php)


#!/bin/bash
SCOPE=rigollan.local
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

 

Offline wd5gnr

  • Regular Contributor
  • *
  • Posts: 179
Re: Shell Script to take screen caps from DS1000Z
« Reply #1 on: June 11, 2015, 08:55:50 AM »
Now a newer version on github that can take multiple captures with delay, autonaming, etc.

https://github.com/wd5gnr/scopesnap

 

Offline smithnerd

  • Regular Contributor
  • *
  • Posts: 79
  • Country: gb
Re: Shell Script to take screen caps from DS1000Z
« Reply #2 on: June 11, 2015, 10:34:58 AM »
Nice.

I've been wondering about doing the same with the USB interface, for the extra speed. I came across this old C project for the DS1052E, a few weeks ago:

https://github.com/ralfstx/rigol-linux

Which is an extremely simple and flexible tool (true to the UNIX philosophy of "do one thing well"). It operates in a similar way to netcat, so one can do things like:

$echo "$IDN?" | rigol

or use the readline(3) powered terminal input, for an interactive SCPI session. It's really quite nice, and ever so small - ~14K on my 64-bit box. It also talks directly to the kernel usbtmc driver, so it doesn't depend on anything else.

I have it working with my DS1054Z, in that it automatically finds the /dev/usbtmc# device and runs SCPI commands which don't return a lot of data. Judging by the README, it looks like the authors had to do some hacking around weirdness in the DS1052E SCPI bulk data output.

I doubt much needs to be done to make it work with the DS1054Z screen cap command, but it doesn't currently work.
 

Offline wd5gnr

  • Regular Contributor
  • *
  • Posts: 179
Re: Shell Script to take screen caps from DS1000Z
« Reply #3 on: June 11, 2015, 11:31:27 AM »
Nice.

I've been wondering about doing the same with the USB interface, for the extra speed. I came across this old C project for the DS1052E, a few weeks ago:

https://github.com/ralfstx/rigol-linux

Which is an extremely simple and flexible tool (true to the UNIX philosophy of "do one thing well"). It operates in a similar way to netcat, so one can do things like:

$echo "$IDN?" | rigol

or use the readline(3) powered terminal input, for an interactive SCPI session. It's really quite nice, and ever so small - ~14K on my 64-bit box. It also talks directly to the kernel usbtmc driver, so it doesn't depend on anything else.

I have it working with my DS1054Z, in that it automatically finds the /dev/usbtmc# device and runs SCPI commands which don't return a lot of data. Judging by the README, it looks like the authors had to do some hacking around weirdness in the DS1052E SCPI bulk data output.

I doubt much needs to be done to make it work with the DS1054Z screen cap command, but it doesn't currently work.

I had thought about that, but I can't get cat to read from the Rigol for some reason. I can write to /dev/usbtmcX but reads always timeout.
 

Offline wd5gnr

  • Regular Contributor
  • *
  • Posts: 179
Re: Shell Script to take screen caps from DS1000Z
« Reply #4 on: June 11, 2015, 01:50:28 PM »
The other thing I've noticed in case anyone wants to try it is that :WAV:DATA? can only write out 128K at a time before it barfs. So to get everything you have to cycle around using :WAV:STAR and :WAV:STOP. Seems flaky. The :WAV:PRE? Doesn't tell you how many points there are. It tells you how many you have set. Duh.
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5549
  • Country: us
Re: Shell Script to take screen caps from DS1000Z
« Reply #5 on: June 11, 2015, 02:59:19 PM »
From the DS2000 programming manual (should be similar on the DS1000z programming manual):

Code: [Select]
Procedures of the screen waveform data reading:
S1. :WAV:SOURce CHAN1    Set the channel source to be read
S2. :WAV:MODE NORM       Set the waveform mode to NORM
S3. :WAV:DATA?           Obtain data from buffer

Procedures of the internal memory waveform data reading:
S1. :STOP                The internal memory waveform data can only be read in STOP state
S2. :WAV:SOURce CHAN1    Set the channel source to be read
S3. :WAV:MODE RAW        Set the waveform mode to RAW
S4. :WAV:RESet           Reset the waveform reading
S5. :WAV:BEGin           Start the waveform reading
S6. :WAV:STATus?         Get the state
1) IDLE                  Waveform reading thread finishes
:WAV:DATA?               Get data in buffer
:WAV: END                Waveform reading finishes
2) READ                  Waveform reading thread is running
:WAV:DATA?               Get data in buffer
Repeat S6                Continue to read waveform data

They have a description of the data header and blocks in there as well as programming samples in C# on the :WAV:DATA? section, some more examples at the end of the document.

DS2000 programming manual:

http://www.tequipment.net/assets/1/26/Documents/Rigol/DS2072/ds2072_doc_5.pdf

DS1000Z programming manual:

http://www.batronix.com/pdf/Rigol/ProgrammingGuide/MSO1000Z_DS1000Z_ProgrammingGuide_EN.pdf

 
« Last Edit: June 11, 2015, 03:01:06 PM by miguelvp »
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5549
  • Country: us
Re: Shell Script to take screen caps from DS1000Z
« Reply #6 on: June 11, 2015, 03:26:23 PM »
My apologies, it seems the DS1000z doesn't have a :WAV:STATus? nor BEGin nor END

On the DS2000 series :WAV:STATus? returns a number of waveforms to be read after IDLE or after READ.
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5549
  • Country: us
Re: Shell Script to take screen caps from DS1000Z
« Reply #7 on: June 11, 2015, 03:53:34 PM »
The other thing I've noticed in case anyone wants to try it is that :WAV:DATA? can only write out 128K at a time before it barfs. So to get everything you have to cycle around using :WAV:STAR and :WAV:STOP. Seems flaky. The :WAV:PRE? Doesn't tell you how many points there are. It tells you how many you have set. Duh.

Since I don't have a DS1000z I only can guess and it's similar to my DS2000 one.

You want to set the mode to raw to get the data in memory.
you can only read the internal memory when the scope is in the stop state (:STOP, not to be confused with :WAV:STOP)
Use the :WAV:PRE? to find out that you are indeed in RAW mode and other parameters associated to the waveforms in memory including the number of points set for the memory depth. If you are in stop state there should all be available (maybe not all filled with data but all available).
Use :WAV:START n and :WAV:STOP n to get chunks of the memory for n going from 1 to 12000000

if you are in Normal mode instead of Raw then there are only 1200 points and start defaults to 1 and stop defaults to 1200

:WAV:DATA? also returns a header #900000dddd where dddd is the number of bytes of the waveform data to be read.

There are too many variations on how to use it all so I guess it depends what format type and mode you want to read and if you want to be in running or stop state.

But there is a free project with source (C++ I think) in the first post of this thread:
http://www.eevblog.com/forum/testgear/free-ds6000ds1000z-software/

Seems that covers a lot of the DS1000z functionality but I didn't look at the details

Maybe you can use what the author has done for reading waveforms from that code (Edit: save_data.cpp)
« Last Edit: June 11, 2015, 03:58:13 PM by miguelvp »
 

Offline wd5gnr

  • Regular Contributor
  • *
  • Posts: 179
Re: Shell Script to take screen caps from DS1000Z
« Reply #8 on: June 12, 2015, 01:26:00 PM »
Yes I've written a lot of code for the DS1xx2E and I have the 1000z manual. But it does seem that if you request more than 128K of data at once you get a beep on the scope, some error message flash on the screen and you wind up with only 128K of data anyway. I agree, you can slide along the start and end (that's what I've done) but it is somewhat unhandy.

I don't think I have the gall to make as many functions for this one as qrigol does for the E series, but it would be nice to have a screen with all measurements and to be able to do the exports (especially to sigrok/OLS since the decode capability is so crippled).

If you check out my github page (http://github.com/wd5gnr  I have qrigol, of course, but also a simple shell script that dumps the screen with optional repeats and time stamping. That's what drives the almost famous scope cam.
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: dk
Re: Shell Script to take screen caps from DS1000Z
« Reply #9 on: June 13, 2015, 07:27:31 PM »
How long time does it take for you guyzz to get a screendump via usb and via tcp/ip

I'm only using tcp/ip & py : http://www.eevblog.com/forum/testgear/new-rigol-ds1054z-oscilloscope/msg675845/#msg675845   

Where a dump takes around 15..18 sec.

I Know  miguelvp got a tremendous boost on his 2000 by changing the MTU size , and wondered if anyone had tried on a 1054z.

I haven't gotten around to installing the VXI11 from Alex yet (i had to return my scope to Batronix , and my new one came 2 days ago.)

/Bingo
« Last Edit: June 13, 2015, 09:28:26 PM by bingo600 »
 

Offline Karel

  • Frequent Contributor
  • **
  • Posts: 938
  • Country: 00
Re: Shell Script to take screen caps from DS1000Z
« Reply #10 on: June 13, 2015, 08:06:06 PM »
How long time dies it take for you guyzz to get a screendump via usb and via tcp/ip

Are you talking about the screenshot in bmp format? About 0.5 sec. via usb. Haven't tried via lan.
Model is a DS1054Z using this software: http://www.teuniz.net/DSRemote/
The difference between theory and practice is less in theory than
the difference between theory and practice in practice.
Expensive tools cannot compensate for lack of experience.
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: dk
Re: Shell Script to take screen caps from DS1000Z
« Reply #11 on: June 13, 2015, 09:32:14 PM »
How long time dies it take for you guyzz to get a screendump via usb and via tcp/ip

Are you talking about the screenshot in bmp format? About 0.5 sec. via usb. Haven't tried via lan.
Model is a DS1054Z using this software: http://www.teuniz.net/DSRemote/

Actually the shoot's are xferred (via tcp/ip) in bmp (i think it's the only format the scope can create) , and then converted to png on my linux pc.

But it's the xfer that takes time not the conversion.

I'm not interested in using USB where i have to have it connected to a specific pc.
I'm often doing the measurements (logging) from another pc

/Bingo
/Bingo
 

Offline Karel

  • Frequent Contributor
  • **
  • Posts: 938
  • Country: 00
Re: Shell Script to take screen caps from DS1000Z
« Reply #12 on: June 28, 2015, 01:08:35 AM »
How long time dies it take for you guyzz to get a screendump via usb and via tcp/ip

Are you talking about the screenshot in bmp format? About 0.5 sec. via usb. Haven't tried via lan.
Model is a DS1054Z using this software: http://www.teuniz.net/DSRemote/

Actually the shoot's are xferred (via tcp/ip) in bmp (i think it's the only format the scope can create) , and then converted to png on my linux pc.

But it's the xfer that takes time not the conversion.

I'm not interested in using USB where i have to have it connected to a specific pc.
I'm often doing the measurements (logging) from another pc

/Bingo
/Bingo

It also supports LAN. Downloading a screenshot takes 0.5 seconds.
The difference between theory and practice is less in theory than
the difference between theory and practice in practice.
Expensive tools cannot compensate for lack of experience.
 

Offline rosbuitre

  • Regular Contributor
  • *
  • Posts: 90
  • Country: ar
Re: Shell Script to take screen caps from DS1000Z
« Reply #13 on: July 05, 2015, 02:59:29 AM »
Hi
Error in DSRemote
I get these errors when connecting via LAN, switching relay is heard and DS1074Z screen changes until show the error
Any suggestions?

Regards

My instruments: DMM Keysight 34461A / Tektronix DMM916 / Fluke 12, Rigol DS1074Z, Deer DE-5000, Siglent SDG805 / SDP3303D, Dayton Dats2
 

Offline Karel

  • Frequent Contributor
  • **
  • Posts: 938
  • Country: 00
Re: Shell Script to take screen caps from DS1000Z
« Reply #14 on: July 05, 2015, 04:31:59 AM »
You hit a bug (a typo in the source) that causes this problem when the oscilloscope is in high-res mode before connecting.
Pull again from git and recompile.
(or set the scope to normal aquisition before connecting)

The difference between theory and practice is less in theory than
the difference between theory and practice in practice.
Expensive tools cannot compensate for lack of experience.
 

Offline rosbuitre

  • Regular Contributor
  • *
  • Posts: 90
  • Country: ar
Re: Shell Script to take screen caps from DS1000Z
« Reply #15 on: July 06, 2015, 01:57:43 AM »
You hit a bug (a typo in the source) that causes this problem when the oscilloscope is in high-res mode before connecting.
Pull again from git and recompile.
(or set the scope to normal aquisition before connecting)

Hi Karel
Thank you, it was that, now works OK  :-+

Regards
My instruments: DMM Keysight 34461A / Tektronix DMM916 / Fluke 12, Rigol DS1074Z, Deer DE-5000, Siglent SDG805 / SDP3303D, Dayton Dats2
 

Offline smithnerd

  • Regular Contributor
  • *
  • Posts: 79
  • Country: gb
Re: Shell Script to take screen caps from DS1000Z
« Reply #16 on: July 26, 2015, 09:31:18 AM »
It turns out that interfacing with the Linux usbtmc driver is a doddle. Here's a quick and dirty example, using just shell I/O redirection and dd (plus ImageMagick):

Code: [Select]
#!/bin/bash

if [ -z "$1" ]
then
echo "Usage: $0 [filename]"
exit 1
fi

# open device for R/W
exec 3<>/dev/usbtmc0

printf ":DISP:DATA?\n" >&3

# header
read -N 11 <&3

# just BMP data
#dd <&3 bs=1024 iflag=count_bytes count=1152054 -of=$1

# ..or convert image format while reading
dd <&3 bs=1024 iflag=count_bytes count=1152054 | convert - $1

# trailing data
read -N 2 <&3

# close device
exec 3>&-



It's quick too:

Code: [Select]
$ time ./snap.sh test.png
1125+1 records in
1125+1 records out
1152054 bytes (1.2 MB) copied, 0.425762 s, 2.7 MB/s

real 0m0.580s
user 0m0.066s
sys 0m0.068s


All I've done on this Linuxmint box, is add a udev permission rule for non root users, in /etc/udev/rules.d.
 

Offline smithnerd

  • Regular Contributor
  • *
  • Posts: 79
  • Country: gb
Re: Shell Script to take screen caps from DS1000Z
« Reply #17 on: August 12, 2015, 02:51:21 AM »
I think the :DISP:DATA? command got extra image format options added in 00.04.03.SP1:

:DISPlay:DATA? [<color>,<invert>,<format>]

Script for USB connected scope:
Code: [Select]
#!/bin/bash

if [ -z "$2" ]
then
echo "Usage: $0 [colour,invert,format] [filename]"
echo
echo "Examples:"
echo " $0 ON,OFF,PNG file.png"
echo " (colour, non-inverted PNG)"
echo
echo " $0 OFF,ON,TIFF file.tiff"
echo " (non-colour, inverted TIFF)"
echo
echo "formats are: BMP8,BMP24,PNG,TIFF,JPEG"
echo
exit 1
fi

# open device for R/W
exec 3<>/dev/usbtmc0

printf ":DISP:DATA? $1\n" >&3

# header
read -N 11 <&3 header
size=${header:2}
echo "Size: $size";

# image data
dd <&3 bs=8192 iflag=count_bytes count=$size of=$2

# trailing newline
read -N 2 <&3

# close device
exec 3>&-

It's not super quick though:
Code: [Select]
$ time ./snapfmt.sh ON,OFF,PNG test.png
Size: 000039225
4+1 records in
4+1 records out
39225 bytes (39 kB) copied, 0.0118891 s, 3.3 MB/s

real 0m0.939s
user 0m0.007s
sys 0m0.004s

JPEG encoding is comparatively slow (and arguably pointless):
Code: [Select]
$ time ./snapfmt.sh ON,OFF,JPEG test.jpg
Size: 000074731
9+1 records in
9+1 records out
74731 bytes (75 kB) copied, 0.036549 s, 2.0 MB/s

real 0m3.977s
user 0m0.000s
sys 0m0.006s

PNG and TIFF files have bad checksums in their metadata, as do files saved via USB, but it doesn't seem to be a problem. BMP8 files have the wrong length in their header - again, nothing ImageMagick can't work around. But hey, it wouldn't be a rigol without a few new bugs :).
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

http://opalkelly.com/