Author Topic: Raspberry Pi for GPIB and data analysis: very easy and fully equipped  (Read 15364 times)

0 Members and 1 Guest are viewing this topic.

Offline e61_philTopic starter

  • Frequent Contributor
  • **
  • Posts: 962
  • Country: de
Hi,

based on MiDis description I set up a simple script which fully installs GPIB on a Raspberry Pi based on Rasperry Pi OS (with or without GUI).

The goal was to provide an as simple as possible solution to setup a Pi with everything you need to use GPIB with an Agilent or NI USB-GPIB adaptor.

After installing the Raspberry Pi OS on your Pi (by using Raspberry Pi Imager for example) you just need to copy&paste these two lines into the console:

Code: [Select]
sudo apt update && sudo apt -y upgrade && sudo apt-get -y install --reinstall raspberrypi-bootloader raspberrypi-kernel && sudo apt-get -y install raspberrypi-kernel-headers git
reboot the Pi (This is unfortunately neccessary, because there a sometimes problems to have the right kernel headers for the running kernel)

Code: [Select]
sudo reboot
and then this line (without the [ url ] tags. Better go to the GitHub page and copy from there):

Code: [Select]
mkdir ~/repos && cd ~/repos && git clone [url]https://github.com/PhilippCo/meas_rpi.git[/url] && meas_rpi/install.sh
The script, examples and so on are hosted on GitHub https://github.com/PhilippCo/meas_rpi Please check that URL for the latest instructions!




The script will not only compile and install linux-GPIB to work with Agilent and NI adaptors, it will also install the following:

- PyVISA for Python3 (no it isn't big, it is just a couple of 100kB)
- a Vxi11 Server which acts as a poor mans Agilent E5810. With that you can use the Pi as a GPIB to Ethernet bridge
- my testgear lib to control instruments (no need to use it, but it makes many things easier)
- Jupyter Lab as a Service. This provides a web based development enviroment to control your instruments and run data analysis completely on the Pi without the need to install something else than a browser on your PC (http://<Pi IP>:8888 password:1281)
- Everything you need to do some data analysis in Python: Numpy, SciPy, Pandas, Matplotlib and so on

If you don't like pyvisa (for whatever reason) you can also use vxi11:
Code: [Select]
>>> import vxi11
>>> instr = vxi11.Instrument('TCPIP::192.168.2.48::gpib0,4::INSTR')
>>> instr.ask("*IDN?")
'HEWLETT-PACKARD,34401A,0,10-5-2'

If you run your meaurement script in Jupyter Lab, it will go on even if you close the browser.

I tested it on Raspberry Pi 4, Raspberry Pi 3B and Raspberry Pi 400

Best regards
Philipp

Offline ScoobyDoo

  • Regular Contributor
  • *
  • Posts: 83
  • Country: fr
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #1 on: August 11, 2021, 06:18:32 am »
Hello e61_phil - this is a major achievement (milestone) for Voltnuts community - unfortunately a lot of people have not yet understood the impact of your work !

GREAT JOB - well done !

Un saludo / Best regards
ScoobyDoo
« Last Edit: August 11, 2021, 06:24:24 am by ScoobyDoo »
 

Offline notfaded1

  • Frequent Contributor
  • **
  • Posts: 559
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #2 on: August 12, 2021, 08:05:03 pm »
Yeah thanks Phil... I'll try your setup too.  Love to see more of this kind of thing here!  :-+

Bill
.ılılı..ılılı.
notfaded1
 

Offline e61_philTopic starter

  • Frequent Contributor
  • **
  • Posts: 962
  • Country: de
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #3 on: August 13, 2021, 10:12:25 pm »
Thanks for your feedback!

I added a very simple Jupyter Notebook to update all the repos on the Pi. This way it is easy to add more examples and so on without setting up the Pi again.

Just open the Jupyter Lab (<RPI IP>:8888 in your browser) and click "Restart Kernel and run all".

There is also an even simpler Notebook to shutdown the Pi. There is no need to use the linux console if you just want to control some testgear.



I also added a analysis subdirectory with a simple example of an INL calculation. That notebook takes the Transmile data from TiNs Server (branadic showed it another thread) and calculates the INL. Everything happens on the Pi. You can interactely zoom in and out into the graph, resize ist and everything you know from MATLAB or similar tools. Just to show that it is really simple to start with Jupyter.


 
The following users thanked this post: MiDi, bastl_r

Offline baltersice

  • Regular Contributor
  • *
  • Posts: 65
  • Country: de
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #4 on: August 14, 2021, 10:38:45 am »
Thank you for posting this, great work!!
Installation went fine on a Raspberry Pi Zero W V1.1 as far as I can tell, only JupyterLab is slow on that kind of hardware.

Unfortunately my Cheap (139.33 EUR) Fake NI GPIB-USB-HS bought on eBay in Feb 2020 refuses to cooperate. Curiously it works fine with a fresh, up to date LabView under Windows. But after multiple attempts at getting it to work with linux-GPIB on all the Raspberry Pi models (3, 4, zero) with all available Kernels and OS versions (even the new 64 bit Raspberry Pi OS for the 4) I have to conclude that it's not meant to be. Gotta stick with my TAMS L488 and its noisy PoE for now.

Here's how it looks. I would stay clear of cheap eBay listings in 'New' condition. Perhaps the cheap fake Agilent adapter works better?  :-//
« Last Edit: August 14, 2021, 10:57:41 am by baltersice »
 

Offline martinr33

  • Frequent Contributor
  • **
  • Posts: 363
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #5 on: August 16, 2021, 04:44:55 pm »
So I am stuck trying to get my Agilent E5810A to show up.

Is there a configuration file somewhwere that I am missing? I don't see how to set it up.

Any ideas appreciated!
 

Offline Johnny10

  • Frequent Contributor
  • **
  • Posts: 899
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #6 on: August 16, 2021, 04:48:48 pm »
 :popcorn:
Tektronix TDS7104, DMM4050, HP 3561A, HP 35665, Tek 2465A, HP8903B, DSA602A, Tek 7854, 7834, HP3457A, Tek 575, 576, 577 Curve Tracers, Datron 4000, Datron 4000A, DOS4EVER uTracer, HP5335A, EIP534B 20GHz Frequency Counter, TrueTime Rubidium, Sencore LC102, Tek TG506, TG501, SG503, HP 8568B
 

Online gamalot

  • Super Contributor
  • ***
  • Posts: 1300
  • Country: au
  • Correct my English
    • Youtube
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #7 on: August 16, 2021, 05:17:12 pm »
Thank you for posting this, great work!!
Installation went fine on a Raspberry Pi Zero W V1.1 as far as I can tell, only JupyterLab is slow on that kind of hardware.

Unfortunately my Cheap (139.33 EUR) Fake NI GPIB-USB-HS bought on eBay in Feb 2020 refuses to cooperate. Curiously it works fine with a fresh, up to date LabView under Windows. But after multiple attempts at getting it to work with linux-GPIB on all the Raspberry Pi models (3, 4, zero) with all available Kernels and OS versions (even the new 64 bit Raspberry Pi OS for the 4) I have to conclude that it's not meant to be. Gotta stick with my TAMS L488 and its noisy PoE for now.

Here's how it looks. I would stay clear of cheap eBay listings in 'New' condition. Perhaps the cheap fake Agilent adapter works better?  :-//

The NI GPIB-USB-HS that I bought a few months ago looks very different. Mine is even cheaper. If you buy it directly on Taobao in China, it only costs 450 RMB (about 59 Euro, 70 US dollars, or 95 Australian dollars). I haven't actually used it yet, maybe I will do some testing later.

Offline e61_philTopic starter

  • Frequent Contributor
  • **
  • Posts: 962
  • Country: de
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #8 on: August 16, 2021, 05:41:31 pm »
So I am stuck trying to get my Agilent E5810A to show up.

Is there a configuration file somewhwere that I am missing? I don't see how to set it up.

Any ideas appreciated!

What do you mean by show up?

Which instrument do you want to control? Do you want to use py-visa directly, my testgear lib or linux-gpib lib?

Best regards
Philipp
 

Offline e61_philTopic starter

  • Frequent Contributor
  • **
  • Posts: 962
  • Country: de
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #9 on: August 16, 2021, 05:43:47 pm »
Perhaps the cheap fake Agilent adapter works better?  :-//

Thanks for your feedback!

I'm currently on vacation, but I have a clone Agilent one at home. I will test it end of next week. I tested just original Agilent and NI so far (and E5810).

Best regards
Philipp
 

Offline Irv1n

  • Newbie
  • Posts: 8
  • Country: by
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #10 on: August 16, 2021, 06:58:54 pm »
My original Agilent and NI adapter works good! Great solution out of the box!
 

Offline KE5FX

  • Super Contributor
  • ***
  • Posts: 1878
  • Country: us
    • KE5FX.COM
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #11 on: August 16, 2021, 07:59:54 pm »
Thank you for posting this, great work!!
Installation went fine on a Raspberry Pi Zero W V1.1 as far as I can tell, only JupyterLab is slow on that kind of hardware.

Unfortunately my Cheap (139.33 EUR) Fake NI GPIB-USB-HS bought on eBay in Feb 2020 refuses to cooperate. Curiously it works fine with a fresh, up to date LabView under Windows. But after multiple attempts at getting it to work with linux-GPIB on all the Raspberry Pi models (3, 4, zero) with all available Kernels and OS versions (even the new 64 bit Raspberry Pi OS for the 4) I have to conclude that it's not meant to be. Gotta stick with my TAMS L488 and its noisy PoE for now.

Here's how it looks. I would stay clear of cheap eBay listings in 'New' condition. Perhaps the cheap fake Agilent adapter works better?  :-//

Interesting, that's the first actual fake GPIB-USB-HS adapter I've seen.  The units I've purchased out of China all look like gamalot's photo, and are either genuine or extremely good copies.  Do you remember the name of the seller you bought yours from?
 

Offline AaronD

  • Frequent Contributor
  • **
  • Posts: 260
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #12 on: August 16, 2021, 08:57:36 pm »
Nice!  It appears, though, that it works differently from what I would expect for something like this.  Not that that's necessarily a bad thing; just curious.

Since GPIB is essentially ASCII on an 8-bit parallel interface, I would expect an 8-bit-at-a-time standardized API like a virtual UART, that I can use like any other UART (echo "*IDN?" > /dev/gpib0 && cat /dev/gpib0), except that the "black box" between the standard API and the real world has an 8-bit shift register in it.  (or doesn't if you imagine that a serial port does)  Is there a reason for not doing it like that?
« Last Edit: August 16, 2021, 09:09:12 pm by AaronD »
 

Offline martinr33

  • Frequent Contributor
  • **
  • Posts: 363
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #13 on: August 16, 2021, 09:12:02 pm »
I am trying to use the Jupyter notebok configuration from your Github distribution. Everything seems to be complete, the installation finished.

I am using the simple example script that just pulls a read from the instrument.

What  I don't understand is, how do I configure the IP address of the E5810A? e.g. 192.168.0.157?



 

Offline e61_philTopic starter

  • Frequent Contributor
  • **
  • Posts: 962
  • Country: de
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #14 on: August 16, 2021, 09:12:51 pm »
Nice!  It appears, though, that it works differently from what I would expect for something like this.  Not that that's necessarily a bad thing; just curious.

Since GPIB is essentially ASCII on an 8-bit parallel interface, I would expect an 8-bit-at-a-time standardized API like a virtual UART, that I can use like any other UART (echo "*IDN?" > /dev/gpib0 && cat /dev/gpib0), except that the "black box" between the standard API and the real world has an 8-bit shift register in it.  (or doesn't if you imagine that a serial port does)  Is there a reason for not doing it like that?

I don't know what you want to do and if it really makes sense to do it not in python, but you could do something like that:

Code: [Select]
import sys
import testgear

dmm = testgear.HPAK.HP34401A(gpib=3, gwip="192.168.2.88")

for line in sys.stdin:
    sys.stdout.write(dmm.query(line.strip()))

That will take stdin and sends it to the instrument (a 34401A in this example). The output is then writte to stdout. If you save the file as piper.py you can use it like this:

Code: [Select]
echo "*IDN?" | python3 piper.py
 

Offline e61_philTopic starter

  • Frequent Contributor
  • **
  • Posts: 962
  • Country: de
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #15 on: August 16, 2021, 09:14:46 pm »
I am trying to use the Jupyter notebok configuration from your Github distribution. Everything seems to be complete, the installation finished.

I am using the simple example script that just pulls a read from the instrument.

What  I don't understand is, how do I configure the IP address of the E5810A? e.g. 192.168.0.157?

If you're using a gateway like the E5810 (or the Pi itself, if you run the Python on another machine). Just specify the Gateway IP:
Code: [Select]
dmm = testgear.HPAK.HP34401A(gpib=3, gwip="192.168.2.88")
 

Offline AaronD

  • Frequent Contributor
  • **
  • Posts: 260
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #16 on: August 16, 2021, 09:29:40 pm »
I don't know what you want to do and if it really makes sense to do it not in python...

I'm thinking that I'm already familiar with bash and not so much in python, and I have an off-brand power supply with GPIB on the back.  (I really doubt it's in anyone's library of drivers)  I want to discover what it can do from that port and how the responses are formatted, and then use it for some quick-and-dirty automated testing with minimal development effort for each test.  I'm also looking at a USB oscilloscope and logic analyzer for that Pi as well...

...but you could do something like that:
Code: [Select]
import sys
import testgear

dmm = testgear.HPAK.HP34401A(gpib=3, gwip="192.168.2.88")

for line in sys.stdin:
    sys.stdout.write(dmm.query(line.strip()))

That will take stdin and sends it to the instrument (a 34401A in this example). The output is then writte to stdout. If you save the file as piper.py you can use it like this:

Code: [Select]
echo "*IDN?" | python3 piper.py

Okay, I can copy/paste as well as anyone else, but what's the IP address for?  Doesn't everything run on the same Pi with no network required at all?
 

Offline e61_philTopic starter

  • Frequent Contributor
  • **
  • Posts: 962
  • Country: de
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #17 on: August 16, 2021, 09:36:55 pm »
Okay, I can copy/paste as well as anyone else, but what's the IP address for?  Doesn't everything run on the same Pi with no network required at all?

Sorry, I tested it with my notebook here on vacation. My 34401A is sitting at home behind my E5810 with this IP address. Just delete that parameter and it will work completely local.
 

Offline e61_philTopic starter

  • Frequent Contributor
  • **
  • Posts: 962
  • Country: de
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #18 on: August 16, 2021, 10:04:14 pm »
To be clear: Most of the software is from other people and I just combined them. But one of the things which is from me, is the testgear lib. The idea behind this lib is to create an easy to access and common interface for the testgear we use quite often.
One of the goals was that one can write a script and after that change the instruments used without changing anything on the script.

At the moment there are two important classes of instruments: meters and sources (and some instruments can be a meter and a source).

The first step with testgear is alwas to import the lib:

Code: [Select]
import testgear
After that you can create your instruments:
Code: [Select]
dmm = testgear.HPAK.HP3458A(gpib=3)

Possible parameters for this are:
visastr: You can directly specify the VISA String to talk to the instrument
gpib: GPIB address
gwip: GPIB Gateway (Pi or E5810)
ip: IP address of the instrument in case your using the ethernet interface of an instrument


In case of a meter you will configure it in the next step. In case of a DCV measurement like this:
Code: [Select]
dmm.conf_function_DCV(mrange=10, nplc=100, HiZ=True)

The idea of putting the function of the instrument in the method name and not in a parameter was, that the autocompletion (also available in Jupyter Lab) is much more helpful this way. Just start to write dmm.conf in the Jupyter Lab and hit <tab> and you can select between the functions.

I also tried to make everything as readable as possible. Some parameter names may appear long, but it should help to directly understand the code.

To get a reading of your DMM just use
Code: [Select]
dmm.get_reading()
That will trigger a reading, fetch the data and return a float value


If you're controlling a source. The most important method is
Code: [Select]
set_output(voltage=None, current=None, enabled=True, frequency=0, resistance=None, fourWire=False, channel=1)

Lets assume you want to generate 1Vrms with 100Hz. Just use
Code: [Select]
source.set_output(voltage=1, frequency=100)
That will create an 1Vrms output with 100Hz, not matter if your source is a AC calibrator (Valhalla 2703 for example, a MFC (Fluke 5730A) or a signal generator. You always get 1Vrms.

Same is true for DCV. Just set frequency to zero (which is default) and it doesn't matter if the source is a power supply, MFC, DCV calibrator, the DC source of your electrometer or a signal generator.
And it is again the same for resistance.

That means you can write a test script to compare resistances against your 3458A, 8588A, 34401A, 8508A.... sourcing from a 5730A or 5450A or whatever and you don't need to change your script. Just change the instruments.


There is still a lot of work to do and hopefully one can add more and more instruments
 
The following users thanked this post: martinr33, Svgeesus, syau, AaronD

Offline AaronD

  • Frequent Contributor
  • **
  • Posts: 260
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #19 on: August 17, 2021, 12:39:12 am »
Sorry, I tested it with my notebook here on vacation. My 34401A is sitting at home behind my E5810 with this IP address. Just delete that parameter and it will work completely local.

Ah!  That makes sense now.  Thanks!

...But one of the things which is from me, is the testgear lib. The idea behind this lib is to create an easy to access and common interface for the testgear we use quite often.
One of the goals was that one can write a script and after that change the instruments used without changing anything on the script.

...

That means you can write a test script to compare resistances against your 3458A, 8588A, 34401A, 8508A.... sourcing from a 5730A or 5450A or whatever and you don't need to change your script. Just change the instruments.

There is still a lot of work to do and hopefully one can add more and more instruments

And I see what you're doing now too.  That's a good idea!
 

Offline martinr33

  • Frequent Contributor
  • **
  • Posts: 363
  • Country: us
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #20 on: August 17, 2021, 02:00:21 am »
OK, first results in hand.

1) If the E5810A gets a command it doesn't like, it seems that I have to restart it.
2) The Jupyter environment works great.

Here's my first working script, the E5810A is at 192.168.0.246:

import testgear
dmm = testgear.HPAK.HP3458A(gpib=12, gwip="192.168.0.246")
dmm.conf_function_DCV(mrange=10, nplc=100, HiZ=True)
dmm.get_reading()
9.999929798     <-----this is the output from the above line

Thanks again for making this work (and thanks also to TiN who helped me get me rolling).

 
The following users thanked this post: e61_phil

Offline e61_philTopic starter

  • Frequent Contributor
  • **
  • Posts: 962
  • Country: de
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #21 on: August 17, 2021, 07:37:20 am »
Very good to hear it works for you :)
Do you use it in Jupyter Lab/Notebook or in a python script on the console?

I added a very simple logging example, which logs into an Excel file. I like logging into Excel files, because one can easily open such files and have a look without writing any code. Another advantage of xlsx is, that it is zipped xml data. If you create very long logs it is automatically compressed.

If you don't like the excel format, there are thousands of alternatives.

In a second Jupyter Notebook I made an example how to read the data into a Pandas dataframe and plot the data.
 

Offline Anders Petersson

  • Regular Contributor
  • *
  • Posts: 122
  • Country: se
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #22 on: August 17, 2021, 10:04:53 am »
But one of the things which is from me, is the testgear lib. The idea behind this lib is to create an easy to access and common interface for the testgear we use quite often.
One of the goals was that one can write a script and after that change the instruments used without changing anything on the script.
[...]
There is still a lot of work to do and hopefully one can add more and more instruments

This is an interesting topic. When getting familiar with automation of test equipment, I've seen several Python libraries for this. That's not surprising, given how well such an abstraction conforms with best practices of software development and how easy it is to wrap a SCPI command in a function.

However, none of the Python libraries I've seen are very complete. I haven't found my set of instruments implemented anywhere. Also, the APIs don't usually offer many functions. This shows that it's easier to start your own library than to extend an existing library (which would benefit all users). With hundreds of instrument models available and a fragmented scene of libraries, none will be very complete.

python-ivi is one attempt, but even this one project is fragmented: https://www.eevblog.com/forum/metrology/software-for-automated-testing-(scpi)/msg3397668/#msg3397668

For a library to gain wide use the APIs of its base classes must suit many use cases. Also, it would help if developers can reap the benefit of extra functionality. For example, PyMeasure provides some basic graphical user interface, plotting and experiment sequencing.

These are things I ponder as I too write my own instrument drivers...
 

Offline mendip_discovery

  • Frequent Contributor
  • **
  • Posts: 824
  • Country: gb
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #23 on: August 17, 2021, 11:08:55 am »
Out of curiosity why can't a Pi (+Hat) or Arduino not be trained to translate the GPIB stuff directly and avoid the whole expensive hardware to interface with?
Motorcyclist, Nerd, and I work in a Calibration Lab :-)
--
So everyone is clear, Calibration = Taking Measurement against a known source, Verification = Checking Calibration against Specification, Adjustment = Adjusting the unit to be within specifications.
 

Offline e61_philTopic starter

  • Frequent Contributor
  • **
  • Posts: 962
  • Country: de
Re: Raspberry Pi for GPIB and data analysis: very easy and fully equipped
« Reply #24 on: August 17, 2021, 11:27:41 am »
But one of the things which is from me, is the testgear lib. The idea behind this lib is to create an easy to access and common interface for the testgear we use quite often.
One of the goals was that one can write a script and after that change the instruments used without changing anything on the script.
[...]
There is still a lot of work to do and hopefully one can add more and more instruments

This is an interesting topic. When getting familiar with automation of test equipment, I've seen several Python libraries for this. That's not surprising, given how well such an abstraction conforms with best practices of software development and how easy it is to wrap a SCPI command in a function.

However, none of the Python libraries I've seen are very complete. I haven't found my set of instruments implemented anywhere. Also, the APIs don't usually offer many functions. This shows that it's easier to start your own library than to extend an existing library (which would benefit all users). With hundreds of instrument models available and a fragmented scene of libraries, none will be very complete.

python-ivi is one attempt, but even this one project is fragmented: https://www.eevblog.com/forum/metrology/software-for-automated-testing-(scpi)/msg3397668/#msg3397668

For a library to gain wide use the APIs of its base classes must suit many use cases. Also, it would help if developers can reap the benefit of extra functionality. For example, PyMeasure provides some basic graphical user interface, plotting and experiment sequencing.

These are things I ponder as I too write my own instrument drivers...


Yes, wrapping around SCPI is very simple for most cases. Trigger the instrument and get a reading is just READ? for most of the newer instruments. But we all here in the metrology section deal with many older instruments and they have sometimes very crude commands.

Most older instruments just want to have a range specified, they can't handle conf_function_DCV(mrange=3.87) directly. Or getting the output status of a Fluke 5730A calibrator needs to look up for a specified bit in the status register. And again other instruments (like my Knick JS3010 calibrator) aren't able to switch the output off an on again. Therefore, you need to keep some state of the instrument in the class.

And you're also right: Such a lib is never complete. My goal was to have something I can use without any manual. Just start writing code and use auto-completion. Having a common API for every instrument also implies that it can only represent a subset of functions which are shared with most of the instruments.

An example are the different AC modes of an HP 3458A. conf_function_ACV just looks simply like that internally:

Code: [Select]
    def conf_function_ACV(self, mrange=None, nplc=100, AutoZero=True, HiZ=True, channel=1):
        """configures the meter to measure ACV. if range=None the meter is set to Autorange"""
        self.write("PRESET NORM")
        self.write("ACV")
        self.write("SETACV SYNC")
        self.__set_range(mrange, nplc)
        self.__autoZero(AutoZero)
        self.__hiZ(HiZ)

SYNC is the most accurate mode in most cases, but it might not always be what you want. In such cases one can directly talk to the instrument:

Code: [Select]
dmm.write("SETACV RNDM")

To prevent that from breaking appart as soon as your using not a HP 3458A you can use a small helper function which compares the type of class:

Code: [Select]
dmm.conf_function_ACV(mrange=10)
if dmm.is_type_of("HP3458A"):
   #we have an 3458A and don't want to have SYNC mode
   dmm.write("SETACV RNDM")

But that already breaks with the idea of a common interface
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf