Author Topic: Visashot, a python script for capturing screenshots from vintage instruments  (Read 30490 times)

0 Members and 2 Guests are viewing this topic.

Offline damienTopic starter

  • Contributor
  • Posts: 29
  • Country: jp
    • Website
Hi fenugrec,

Whoopsie, thanks! Fixed in 1.24 :-)
 

Offline KE5FX

  • Super Contributor
  • ***
  • Posts: 2677
  • Country: us
    • KE5FX.COM
HP-894xx Signal analyzers (89441A, 89440A, 89410A, 89441V, 89450A, 89451A) [untested]

Minor data point: it looks like the 89410A/8944xA should work, but the MMEM storage area appears to only have about 64KB available, at least on mine.  TIFF files tend to be (much) bigger than that, and in my case I get a disk-full error.

I added a couple of lines to force it to use the RAM disk:
Code: [Select]
      instrument.write("MMEM:INIT 'RAM:',DOS, 500000")
      instrument.write("MMEM:MSIS 'RAM:'")

That lets it create the SCRNSHOT.TIF file, but instrument_query_binary_values() doesn't appear to read the preamble properly.  I can retrieve the file with this short program, courtesy o4-mini-high:

Code: [Select]
import pyvisa
rm   = pyvisa.ResourceManager()
inst = rm.open_resource('GPIB0::17::INSTR')

inst.read_termination  = None
inst.write_termination = '\r\n'

inst.write(":MMEM:DATA? 'SCRNSHOT.TIF'")

hdr    = inst.read_bytes(2)                       # b'#' + b'<digit>'
if hdr[0] != ord('#') or not chr(hdr[1]).isdigit():
    raise RuntimeError(f"Bad preamble: {hdr!r}")

n      = int(chr(hdr[1]))                         # how many ASCII digits follow
len_s  = inst.read_bytes(n).decode('ascii')       # payload length
length = int(len_s)
img = inst.read_bytes(length)

inst.read_bytes(1)                                # trailing \n

with open('screen.tif','wb') as f:
    f.write(img)

The file is there, but the incantation that wrote it apparently wasn't quite right:



That's all the time I had to tinker around with it.  Looks pretty close, but I'm not familiar enough with PyVISA to diagnose it easily.
 
The following users thanked this post: damien

Offline damienTopic starter

  • Contributor
  • Posts: 29
  • Country: jp
    • Website
Hi KE5FX,

Ooh, this is awesome! I did some quick blind coding for those instruments, I'm surprised is "nearly" works!  ^-^

I added your two lines and changed

Code: [Select]
instrument.write(":MMEM:DATA? 'INT:scrnshot.tif'")

into

Code: [Select]
instrument.write(":MMEM:DATA? 'RAM:scrnshot.tif'")

Since you set "MMEM:MSIS 'RAM:'" we could maybe omit the "RAM:" before "scrnshot.tif" but it could also be the source of the error you saw. BTW that red warning on the screen is missing the "?" after "MMEM:DATA". Maybe it was from a previous (unsuccessful) attempt at reading the buffer, because AFAICT that GPIB call is for reading not writing.

Can you try the attached version? If anything is wrong please try the -g option and share the debug output.
 

Offline KE5FX

  • Super Contributor
  • ***
  • Posts: 2677
  • Country: us
    • KE5FX.COM
Can you try the attached version? If anything is wrong please try the -g option and share the debug output.

Thanks much, that worked after a couple of tweaks.  :-+ 
  • Some operations needed *WAI commands for synchronization
  • The 894xx doesn't support the READ? command so I added a separate _read_HCOPY_bitmap() function
  • Deleting a file that doesn't exist causes an error message, so you won't want to do that twice (or at all, necessarily, since the RAM disk gets initialized each time)
There should probably be a warning somewhere that we nuke the RAM disk.  Hate to do something like that, but I don't see any alternatives at first glance.
 
The following users thanked this post: damien

Offline damienTopic starter

  • Contributor
  • Posts: 29
  • Country: jp
    • Website
Hi KE5FX,

Thanks for helping out! I've tweaked a few minor things and came up with this new version. Let me know if there's any issue, otherwise I'll make a new release. Banzai!

Damien
 
The following users thanked this post: wkb

Offline KE5FX

  • Super Contributor
  • ***
  • Posts: 2677
  • Country: us
    • KE5FX.COM
Looks good, ship it!
 
The following users thanked this post: damien

Offline bostonman

  • Super Contributor
  • ***
  • Posts: 2845
  • Country: us
I think being able to print is great. I have a spectrum analyzer (8592L) and think being able to print will be nice.

Unfortunately I don't believe I have any spare cables and not knowledgeable with using Python scripts.

Do you have plans to post a brief tutorial on making a cable and/or better steps to implement the script?
 

Offline wkb

  • Super Contributor
  • ***
  • Posts: 1159
  • Country: nl
  • PA1WBU
HPiB cables should be quite simple to acquire as used surplus.
Given the rather apecial connectors forget about DIY.
 
The following users thanked this post: damien

Offline DeepLink

  • Regular Contributor
  • *
  • Posts: 132
  • Country: dk
Besides the GPIB cable, you also need a GPIB Interface

Look at the AR488 - USB to GPIB DIY - based on a Arduino Nano
 
The following users thanked this post: damien

Offline damienTopic starter

  • Contributor
  • Posts: 29
  • Country: jp
    • Website
Hi Bostonman,

I have some information/tips on my website here: https://damien.douxchamps.net/elec/visashot/ Admittedly not a full tutorial though. ::)
The most important is to get GPIB (or serial) and pyVISA working with your machine.
If you have a desktop you can find cheap PCI cards (ok, an older desktop then!) or as @DeepLink suggested a USB adapter. The DIY one is the cheapest way, you can also find some by Keysight/Agilent or NI on auction sites (but they can go for more than $100).

If you use linux then python will be easy: just save the script somewhere and execute it (use the -h option for help). For example:
Code: [Select]
./visashot.py -d 8 -o output.png
for device 8 on the GPIB bus. On windows you will have to install python and call it a little differently:
Code: [Select]
python3 visashot.py -d 8 -o output.png
 

Offline damienTopic starter

  • Contributor
  • Posts: 29
  • Country: jp
    • Website
Looks good, ship it!

Awesome, released! Thanks for the feedback and help  ;D
 

Offline bostonman

  • Super Contributor
  • ***
  • Posts: 2845
  • Country: us
Sadly, I thought my 8592L had GPIB. Unfortunately, after doing more research into implementing your script, I grabbed my analyzer only to discover it has serial and parallel only.
 

Offline damienTopic starter

  • Contributor
  • Posts: 29
  • Country: jp
    • Website
Sadly, I thought my 8592L had GPIB. Unfortunately, after doing more research into implementing your script, I grabbed my analyzer only to discover it has serial and parallel only.

Someone with an 8591EM had success using the serial port. It would look something like:

./visashot.py -g -s "ASRL4::INSTR" -r 19200 -o output.png

ASRL is for the serial port, and you will need to set the baudrate on your instrument too.
 

Offline bostonman

  • Super Contributor
  • ***
  • Posts: 2845
  • Country: us
So a basic serial cable to a USB convertor, and then use Visashot?

Do I need any image convertor or is it simply run that command and get a PNG image?

Some research showed I'd need the parallel port for capturing screen shots and the serial port for capturing the settings (i.e. frequency, span, etc...) with a RTC (real time clock) for keeping track of date/time stamps, and an SD card. This all assumes I use an Arduino to do the work.
 

Offline damienTopic starter

  • Contributor
  • Posts: 29
  • Country: jp
    • Website
So a basic serial cable to a USB convertor, and then use Visashot?

Yes it should be that simple. I'm not sure about the code when using a USB-serial converter though. Hopefully it's as simple as ASRL1 (serial port 1).

Quote
Do I need any image convertor or is it simply run that command and get a PNG image?

No convertor needed, it's integrated in visashot via ImageMagick. So something close to the command line above should give you a PNG image as output.

You can run

./visashot.py -h

for help about options. I've only had one person with a serial instrument so far, so I can't rule out it will fail. But I'm happy to work with you to make it chooch!
 

Offline bostonman

  • Super Contributor
  • ***
  • Posts: 2845
  • Country: us
Thankfully I have a USB to serial convertor (also had to install a driver).

Due to too many anomalies between analyzer printer settings, not understanding Python, and your script, I apologize in advance, but need some help with the basics.

The analyzer printer settings is something I'll need to tinker with, but I'd like to know one piece of the puzzle that is correct so I know where to focus my attention.

I have an older laptop with Win7 with Python 3.8.0; I just downloaded it and ran the installer. When I click your script, I get a Command window that quickly closes.

The little I know about Python is: I think it needs to be set in an environment in order to just run a .py file. I added the path in the environment. Now when I type Python --version in the CMD window, it shows the version.

Having said this, I'm uncertain how to setup Python to run your script; and this eliminates me from using the 'help' file you suggested.

As for the analyzer, I'm tinkering with the print/plotter settings, but, each time I try a setting by pressing 'copy', it freezes. Due to not understanding how to run the script, I have two equations with three unknowns (the third being whether this USB to serial works).

Going forward, assuming this current setup works, ideally I'd like something that will last the test of time. Most likely a USB to serial convertor will not work on future Windows due to driver incompatibility, but maybe an alternate method would be great like a Pi or Arduino.
« Last Edit: June 06, 2025, 08:55:54 pm by bostonman »
 

Offline damienTopic starter

  • Contributor
  • Posts: 29
  • Country: jp
    • Website
To run the script you type (in the folder that contains visashot)

Code: [Select]
Python visashot.py
Note that you need to install the python package PyVisa. Otherwise the visashot will not be happy. I have no windows experience, but on Linux you would do:

Code: [Select]
pip install pyvisa
For ImageMagick have a look here: https://imagemagick.org/script/download.php

Maybe a good samaritan with Windows experience can help? :-)
 

Offline bostonman

  • Super Contributor
  • ***
  • Posts: 2845
  • Country: us
Hmmmm seems then this would all be easier on Linux.

Looking at pyvisa, it seems a NI driver also needs to be installed.

 

Offline bostonman

  • Super Contributor
  • ***
  • Posts: 2845
  • Country: us
Think maybe I'll need to cancel trying to get this to work.

The NI Visa that's required needs Labview and/or Studio installed. I can try Linux, but assume I need a driver for the serial to USB cable.

 

Online abeyer

  • Frequent Contributor
  • **
  • Posts: 961
  • Country: us
Looking at pyvisa, it seems a NI driver also needs to be installed.

If it meets your needs, the pyvisa-py backend is usually much easier to get working in my experience, rather than messing with the vendor drivers.
 
The following users thanked this post: damien

Online abeyer

  • Frequent Contributor
  • **
  • Posts: 961
  • Country: us
I can try Linux, but assume I need a driver for the serial to USB cable.

most linux distros will have all the common usb serial devices prebuilt and will show up as either /dev/ttyUSB[n] or /dev/ttyACM[n] out of the box
 
The following users thanked this post: damien

Offline bostonman

  • Super Contributor
  • ***
  • Posts: 2845
  • Country: us
From what I understand, and maybe my interpretation is incorrect, pyvisa won't install without the NI stuff, but then NI won't install without Labview or Studio.

So it seems this whole setup isn't Windows friendly.

 

Online abeyer

  • Frequent Contributor
  • **
  • Posts: 961
  • Country: us
From what I understand, and maybe my interpretation is incorrect, pyvisa won't install without the NI stuff, but then NI won't install without Labview or Studio.

So it seems this whole setup isn't Windows friendly.

No, that's what pyvisa-py is for, to avoid that:

https://pyvisa.readthedocs.io/en/latest/introduction/getting.html#:~:text=Alternatively%2C%20you%20can%20install%20PyVISA%2DPy%20which%20is%20a%20pure%20Python%20implementation%20of%20the%20VISA%20standard.%20You%20can%20install%20it%20using%20pip%3A

https://pyvisa.readthedocs.io/projects/pyvisa-py/en/latest/
 
The following users thanked this post: damien

Offline bostonman

  • Super Contributor
  • ***
  • Posts: 2845
  • Country: us
I think this all revolves around Linux because Windows doesn't install pyvisa. Online documentation keeps referring me to NI which states pyvisa needs NI installed.

Maybe someone who installed this on a Windows machine knows more than the documentation I'm finding.
 

Online abeyer

  • Frequent Contributor
  • **
  • Posts: 961
  • Country: us
No, it's nothing to do with linux, works on windows too. pyvisa needs a backend. NI is one backend, pyvisa-py is another. Read the pyvisa-py docs and follow them.

This is from scratch on a windows laptop that that's never had pyvisa nor NI installed (and also doesn't have any devices to connect to) but it still gets all the way through to device discovery along with some warnings about optional extra packages you can use for enhanced network discovery:

2589504-0
« Last Edit: June 10, 2025, 07:18:34 pm by abeyer »
 
The following users thanked this post: damien


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->