EEVblog Electronics Community Forum

Products => Test Equipment => Topic started by: EVlab on August 06, 2014, 01:11:40 pm

Title: Tek TDS Hardcopy GPIB C
Post by: EVlab on August 06, 2014, 01:11:40 pm
Hi all!

I’m trying to transfer a hardcopy (bitmap-image) from my TDS644B to my PC running Debian Linux.
Scope and PC are connected via an Agilent 82357B. Programming is done using plain C (libgpib).

I’m able to communicate with the scope and take readings and transferring data. So far, so good :).
For the hardcopy action, the scope is switch to “talk-only” mode and there is a libgpib-function called “ibrdf” that should write the received data to a file directly.
And here my problem starts.

Ibrdf writes a file, but there is only partial data of the hardcopy in it.
I assume, that there is some kind of a synchronization problem.
Thus I started to monitor the GPIB bus status lines to wait for some kind of action if the TDS wants to send data and then call ibrdf.
But I had no success.

Can anyone help out (or give me a hint)?
There are some programming examples on the web, but they all use “fancy new languages” like Phyton, etc.
Furthermore they use high level stuff like VISA.
I would like to stick with plain C.

Best;
Title: Re: Tek TDS Hardcopy GPIB C
Post by: Andy Watson on August 06, 2014, 01:30:39 pm
How big is the resulting data file? Is it 64k, or a multiple thereof?

Title: Re: Tek TDS Hardcopy GPIB C
Post by: EVlab on August 07, 2014, 10:01:48 am
I have no idea.
I would expect with 8bit-color-depth: 640x480=370200byte + 14byte header + 40 byte info-block for am BMP file.
Title: Re: Tek TDS Hardcopy GPIB C
Post by: MarkL on August 07, 2014, 02:48:55 pm
Try increasing the timeout to a large value, like 30 seconds.

I had some problems using the perl library and I was getting half a printout from an HP spectrum analyzer.  This was several years ago but if I recall, there was some issue that the transaction had exceeded the timeout, but it was not reported as an error because *some* data was received.
Title: Re: Tek TDS Hardcopy GPIB C
Post by: Lukas on August 07, 2014, 08:19:06 pm

Furthermore they use high level stuff like VISA.
I would like to stick with plain C.
C and VISA aren't exclusive. Just find the visa.h (propably included in your adapter's driver package) and link your application to the visa dll.
Title: Re: Tek TDS Hardcopy GPIB C
Post by: EVlab on August 08, 2014, 08:07:27 am
I will try the hint from MarkL, as I can imagine that there is some strange behavior regarding a timeout.
To my understanding, there is no time-out condition, as long as there is data being send by the GPIB-talker.
Anyhow, the libgpib-function generates a timeout.

@Lukas: Do you have experience in using VISA? What are the benefits doing so? My intention was to keep the code as simple as possible and not to include additional libraries.
Title: Re: Tek TDS Hardcopy GPIB C
Post by: Lukas on August 08, 2014, 08:42:35 pm
@Lukas: Do you have experience in using VISA? What are the benefits doing so? My intention was to keep the code as simple as possible and not to include additional libraries.
Oh, I've noticed you're using linux, this makes things a bit more complicated, since VISA practically is windows-only.
Title: Re: Tek TDS Hardcopy GPIB C
Post by: davorin on August 08, 2014, 08:57:10 pm
Have you tried the communication with a simple terminal software like "ibterm" ?

It will just dump the content as hex values on the console...but you know it's working...

Haven't done anything in C, just Python...the screendumps from my two LeCroy DSOs work like a charme for HPGL, BMP and TIFF...


You might want to post your C code here...
Title: Re: Tek TDS Hardcopy GPIB C
Post by: EVlab on August 09, 2014, 12:38:01 pm
The solution was very simple: You have to make sure, that >timeout< in "/etc/gpib.conf" is set to a value or range in which the data transfer can surely be completed. I used >timeout=T30s< which works fine, as "MarkL" already suggested ;-)

>libgpib< will generate a timeout regardless if there is data being transferred successfully ...

Anyhow, I also took a look at the SVN repository that "davorin" mentioned. I would recommend any one who tries to get into GPIB programming using C to do so. The tool "ibterm" is very helpful for developing own software. Furthermore, there are some examples, where you can learn a lot by just looking at the code!

For the GPIB communication itself you have to distinguish if the scope runs in >talk/listen< or in >talk-only< mode. For my purpose, grep screen images as they are displayed, >talk-only< is what you need. A very simple code stores the data to a file:

status = ibrdf( board, file_path );
   if( status & ERR )
   {
      fprintf( stderr, "ibrdf() failed\n" );
      fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) );
      return -1;
   }

Thus I can also (like "davorin") state: "the screendumps from my TDS work like a charme for HPGL, BMP and TIFF..."

Have a nice weekend!
Title: Re: Tek TDS Hardcopy GPIB C
Post by: EVlab on August 09, 2014, 05:20:15 pm
I studied the SVN examples a bit further and found some interesting code in the examples regarding the timeout.

It's worth than mentioned above: You have to disable the GPIB-timeout completely by setting >timeout< to "TNONE".

I used this afternoon to modify the example code and to write a small program, that waits for hardcopy data and writes to files that will be numbered ascending.

Please find attached the code and the resulting screen dump!
Title: Re: Tek TDS Hardcopy GPIB C
Post by: davorin on August 09, 2014, 05:33:34 pm
Looks nice :-))

My 9354AL and 9414 don't feature nice colors...only different pen codes for channels in HPGL mode..that's all (o;

I see that you never write anything to the device....as I always write first to send the HCSU and then trigger it remotely via SCDP...

But good to have also some nice example written in C....as I'm working now on the OSX driver side for S82357/F82357 adapters...

Title: Re: Tek TDS Hardcopy GPIB C + Tek 11k
Post by: EVlab on March 25, 2015, 05:15:17 am
Dear all.

I have enhanced my little program with screen dump capability of my Tek 11801.
This variant does not wait for a "SCREEN COPY" button to be pressed on the scope.
Instead it will setup and grab the screen contents remotely via GPIB when you call the binary.

Best regards, Simon
Title: Re: Tek TDS Hardcopy GPIB C
Post by: bang007 on June 24, 2015, 10:57:36 am

Hi guys,

I  try to write a script in python to save the screenshoot in a png file but I get some errors. If any body can have a look on this. I am new in Python.
Many thanks for your help.

Code: [Select]
import visa

rm=visa.ResourceManager('@py')
scope = rm.open_resource('GPIB::6::0')

scope.write('HARDCOPY:FILENAME "test.png"')
scope.write('HARDCOPY:FORMAT PNG')
scope.write('HARDCOPY:LAYOUT LANDSCAPE')
scope.write('HARDCOPY:PORT GPIB')
scope.write('HARDCOPY START')

raw_data=scope.read()

fid=open('/home/pi/test.png','wb')
fid.write(raw_data)
fid.close()

And I got this error
Quote
File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 312, in read
    message = self.read_raw().decode(enco)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 1031: ordinal not in range(128)
Title: Re: Tek TDS Hardcopy GPIB C
Post by: davorin on June 24, 2015, 08:21:11 pm
No need to post in two separate threads (o;

Think I already posted my screen dump code somewhere here....but here it is again:

Code: [Select]
#!/usr/bin/python

import sys
from subprocess import Popen, PIPE
import errno
import shlex

hpgl = ""
hp2xx = "/usr/bin/hp2xx -m png -c 12445611 -d 150 -D 90 -q -f "
cat = "/bin/cat"

from Gpib import *

file_name = sys.argv[1]
hp2xx += file_name
hp2xx += ".png"

p = Popen(shlex.split(hp2xx), shell=False, stdin=PIPE)

bytes = 200

inst = Gpib(0,1)

inst.write("HCSU DEV,HP7550A")
inst.write("SCDP")

p.stdin.write(inst.read(bytes))
count = 0

while inst.ibcnt() == bytes:
print 'Bytes read: ',count
p.stdin.write(inst.read(bytes))
count += bytes

print '\nFinished dumping...        '

print hp2xx

p.stdin.close()
p.wait()

Most difficult was to find out how to launch the external hp2xx program in a shell and write the screen dump to stdout...but you won't need this as you dump a bitmap image...

Title: Re: Tek TDS Hardcopy GPIB C: CHECK OUT AMAZING MIKE K!
Post by: icezebra on June 19, 2022, 05:33:04 pm
Not all heros wear capes...
https://www.eevblog.com/forum/testgear/tds460-hardcopy/msg3571877/#msg3571877 (https://www.eevblog.com/forum/testgear/tds460-hardcopy/msg3571877/#msg3571877)
[attach=1]
http://mkelzenb.caltech.edu/software/TDSHC/index.html (http://mkelzenb.caltech.edu/software/TDSHC/index.html)
Thanks Mike, you rock.