Shell Script to take screen caps from DS1000Z - Page 1
Forum section: electronics / testgear

author: wd5gnr
author_rank: Regular Contributor
timestamp: June 10, 2015, 01:22:21 pm
content: 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 (seehttp://www.imagemagick.org/script/formats.php)#!/bin/bashSCOPE=rigollan.localPORT=5555if [ -z "$TMP" ]thenTMP=/tmpfiFILE=$TMP/image$$.rawBFILE=$FILE.bmpBATCH=0DELAY=while getopts ":bBd:" OPTdocase $OPT inb) BATCH=1;;B) BATCH=1;;d) DELAY=$OPTARG;;*) >&2 echo Invalid argumentexit 1;;esacdoneshift $((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 WD5GNRexit 1fiecho -n 'Reading from 'echo "*IDN?" | nc $SCOPE $PORTif [ ! $? == 0 ]then>&2 echo Scope not found. Abortingexit 2fiwhile [ ! -z "$1" ]doRESULT="$1"echo Reading data for "$RESULT"echo ":DISP:DATA?" | nc $SCOPE $PORT >$FILESIZE=`ls -l $FILE | cut -d ' ' -f 5`SIZE=`expr $SIZE - 11`tail -c $SIZE $FILE >$BFILEif convert $BFILE "$RESULT"thenecho Wrote "$RESULT"else>&2 echo Error writing "$RESULT"firm $FILE $BFILEif [ "$BATCH" == 0 ]thenxdg-open "$RESULT" &fishiftif [ ! -z "$DELAY" ]thenecho Delaying $DELAY secondssleep $DELAYfidoneexit 0

author: wd5gnr
author_rank: Regular Contributor
timestamp: June 10, 2015, 10:55:50 pm
content: Now a newer version on github that can take multiple captures with delay, autonaming, etc.https://github.com/wd5gnr/scopesnap

author: smithnerd
author_rank: Regular Contributor
timestamp: June 11, 2015, 12:34:58 am
content: 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-linuxWhich 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?" | rigolor 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.

author: wd5gnr
author_rank: Regular Contributor
timestamp: June 11, 2015, 01:31:27 am
content: Quote from: smithnerd on June 11, 2015, 12:34:58 amI 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.

author: wd5gnr
author_rank: Regular Contributor
timestamp: June 11, 2015, 03:50:28 am
content: 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.

author: miguelvp
author_rank: Super Contributor
timestamp: June 11, 2015, 04:59:19 am
content: From the DS2000 programming manual (should be similar on the DS1000z programming manual):Code:Procedures of the screen waveform data reading:S1. :WAV:SOURce CHAN1 Set the channel source to be readS2. :WAV:MODE NORM Set the waveform mode to NORMS3. :WAV:DATA? Obtain data from bufferProcedures of the internal memory waveform data reading:S1. :STOP The internal memory waveform data can only be read in STOP stateS2. :WAV:SOURce CHAN1 Set the channel source to be readS3. :WAV:MODE RAW Set the waveform mode to RAWS4. :WAV:RESet Reset the waveform readingS5. :WAV:BEGin Start the waveform readingS6. :WAV:STATus? Get the state1) IDLE Waveform reading thread finishes:WAV:DATA? Get data in buffer:WAV: END Waveform reading finishes2) READ Waveform reading thread is running:WAV:DATA? Get data in bufferRepeat S6 Continue to read waveform dataThey 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.pdfDS1000Z programming manual:http://www.batronix.com/pdf/Rigol/ProgrammingGuide/MSO1000Z_DS1000Z_ProgrammingGuide_EN.pdf

author: miguelvp
author_rank: Super Contributor
timestamp: June 11, 2015, 05:26:23 am
content: My apologies, it seems the DS1000z doesn't have a :WAV:STATus? nor BEGin nor ENDOn the DS2000 series :WAV:STATus? returns a number of waveforms to be read after IDLE or after READ.

author: miguelvp
author_rank: Super Contributor
timestamp: June 11, 2015, 05:53:34 am
content: Quote from: wd5gnr on June 11, 2015, 03:50:28 amSince 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 12000000if 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:https://www.eevblog.com/forum/testgear/free-ds6000ds1000z-software/Seems that covers a lot of the DS1000z functionality but I didn't look at the detailsMaybe you can use what the author has done for reading waveforms from that code (Edit: save_data.cpp)

author: wd5gnr
author_rank: Regular Contributor
timestamp: June 12, 2015, 03:26:00 am
content: 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/wd5gnrI 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.

author: bingo600
author_rank: Super Contributor
timestamp: June 13, 2015, 09:27:31 am
content: How long time does it take for you guyzz to get a screendump via usb and via tcp/ipI'm only using tcp/ip & py :https://www.eevblog.com/forum/testgear/new-rigol-ds1054z-oscilloscope/msg675845/#msg675845Where 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

author: Karel
author_rank: Super Contributor
timestamp: June 13, 2015, 10:06:06 am
content: Quote from: bingo600 on June 13, 2015, 09:27:31 amAre 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/

author: bingo600
author_rank: Super Contributor
timestamp: June 13, 2015, 11:32:14 am
content: Quote from: Karel on June 13, 2015, 10:06:06 amActually 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

author: Karel
author_rank: Super Contributor
timestamp: June 27, 2015, 03:08:35 pm
content: Quote from: bingo600 on June 13, 2015, 11:32:14 amIt also supports LAN. Downloading a screenshot takes 0.5 seconds.

author: rosbuitre
author_rank: Regular Contributor
timestamp: July 04, 2015, 04:59:29 pm
content: HiError in DSRemoteI get these errors when connecting via LAN, switching relay is heard and DS1074Z screen changes until show the errorAny suggestions?Regards

author: Karel
author_rank: Super Contributor
timestamp: July 04, 2015, 06:31:59 pm
content: 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)

author: rosbuitre
author_rank: Regular Contributor
timestamp: July 05, 2015, 03:57:43 pm
content: Quote from: Karel on July 04, 2015, 06:31:59 pmHi KarelThank you, it was that, now works OKRegards

author: smithnerd
author_rank: Regular Contributor
timestamp: July 25, 2015, 11:31:18 pm
content: 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:#!/bin/bashif [ -z "$1" ]thenecho "Usage: $0 "exit 1fi# open device for R/Wexec 3<>/dev/usbtmc0printf ":DISP:DATA?\n" >&3# headerread -N 11 <&3# just BMP data#dd <&3 bs=1024 iflag=count_bytes count=1152054 -of=$1# ..or convert image format while readingdd <&3 bs=1024 iflag=count_bytes count=1152054 | convert - $1# trailing dataread -N 2 <&3# close deviceexec 3>&-It's quick too:Code:$ time ./snap.sh test.png1125+1 records in1125+1 records out1152054 bytes (1.2 MB) copied, 0.425762 s, 2.7 MB/sreal0m0.580suser0m0.066ssys0m0.068sAll I've done on this Linuxmint box, is add a udev permission rule for non root users, in /etc/udev/rules.d.

author: smithnerd
author_rank: Regular Contributor
timestamp: August 11, 2015, 04:51:21 pm
content: 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:#!/bin/bashif [ -z "$2" ]thenecho "Usage: $0 [colour,invert,format] "echoecho "Examples:"echo "$0 ON,OFF,PNG file.png"echo "(colour, non-inverted PNG)"echoecho "$0 OFF,ON,TIFF file.tiff"echo "(non-colour, inverted TIFF)"echoecho "formats are: BMP8,BMP24,PNG,TIFF,JPEG"echoexit 1fi# open device for R/Wexec 3<>/dev/usbtmc0printf ":DISP:DATA? $1\n" >&3# headerread -N 11 <&3 headersize=${header:2}echo "Size: $size";# image datadd <&3 bs=8192 iflag=count_bytes count=$size of=$2# trailing newlineread -N 2 <&3# close deviceexec 3>&-It's not super quick though:Code:$ time ./snapfmt.sh ON,OFF,PNG test.pngSize: 0000392254+1 records in4+1 records out39225 bytes (39 kB) copied, 0.0118891 s, 3.3 MB/sreal0m0.939suser0m0.007ssys0m0.004sJPEG encoding is comparatively slow (and arguably pointless):Code:$ time ./snapfmt.sh ON,OFF,JPEG test.jpgSize: 0000747319+1 records in9+1 records out74731 bytes (75 kB) copied, 0.036549 s, 2.0 MB/sreal0m3.977suser0m0.000ssys0m0.006sPNG 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.