Author Topic: SCPI Programming Advice Requested  (Read 14370 times)

0 Members and 1 Guest are viewing this topic.

Offline BitstreamTopic starter

  • Contributor
  • Posts: 15
  • Country: us
SCPI Programming Advice Requested
« on: May 14, 2014, 08:30:27 pm »
I have an HP 6632B power supply (PS) and an Agilent 34970A data acquisition switch unit (DAQ).  I would like to control both remotely with SCPI.  I've got the basic commands working no problem and can send individual commands to the PS and DAQ.  But now I'd like to control the setup via a program running under Windows that contains things like  if/then statements, conditional loops, etc.  I'd prefer not having to install a ton of application software to get it all running.  Does anybody have any recommendations on an inexpensive and simple form of programmatic control using SCPI?  Some options I've found so far are:

* Matlab
* Excel macros
* Agilent's benchlink datalogger -but the pro version ($1000) has to be purchased to allow conditional operation
* Visual basic
* C

At the very least, it seems I need the Agilent visa driver installed to do the low-level communication with the devices.
 

Offline babysitter

  • Frequent Contributor
  • **
  • Posts: 900
  • Country: de
  • pushing silicon at work
Re: SCPI Programming Advice Requested
« Reply #1 on: May 15, 2014, 07:17:00 am »
Have a look at EZGPIB - which is basically a free Pascal that can use Serial ports, Prologix GPIB Adapters and VI out of the box. I used it with a Prologix Adapter at work together with 6632B and 34401A for a makeshift thermostat - worked quite well besides frequent crashes which improved after changing PC and Software upgrade.
I'm not a feature, I'm a bug! ARC DG3HDA
 

Offline BitstreamTopic starter

  • Contributor
  • Posts: 15
  • Country: us
Re: SCPI Programming Advice Requested
« Reply #2 on: May 15, 2014, 02:33:34 pm »
Thanks!   :-+ EXGPIB looks promising -nice and compact like I'm looking for.  I'll try it first with the USB-to-serial converter that I have and if that doesn't work, I may have to drop some $ to get the Prologix gpib adapter.

Now I just have to dust off my old pascal books. 
 

Offline Lukas

  • Frequent Contributor
  • **
  • Posts: 412
  • Country: de
    • carrotIndustries.net
Re: SCPI Programming Advice Requested
« Reply #3 on: May 15, 2014, 04:23:34 pm »
I can recommend python with pyvisa for that.
It's way nicer than MATLAB and more high level than C.
Example from the docs:
Code: [Select]
import visa
rm = visa.ResourceManager()
keithley = rm.get_instrument("GPIB::12")
print(keithley.ask("*IDN?"))
It won't get much easier.
Python also gives you easy string interpolation
Code: [Select]
i=10
print("i=%d"%i)
Don't have to deal with buffers (C) or ugly syntax (matlab).
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 2315
  • Country: dk
Re: SCPI Programming Advice Requested
« Reply #4 on: May 15, 2014, 04:28:15 pm »
I can recommend python with pyvisa for that.
It's way nicer than MATLAB and more high level than C.
Example from the docs:
Code: [Select]
import visa
rm = visa.ResourceManager()
keithley = rm.get_instrument("GPIB::12")
print(keithley.ask("*IDN?"))
It won't get much easier.
Python also gives you easy string interpolation
Code: [Select]
i=10
print("i=%d"%i)
Don't have to deal with buffers (C) or ugly syntax (matlab).

Dont forget to tell that you need a "Visa compatible GBIB adapter" , that leaves NI , or Agilent/Beiming interfaces on Windows.
And "None" easily installed on Linux , unless you use RHEL or CentOS , and only the older kernels.  :--


/Bingo
 

Offline Harvs

  • Super Contributor
  • ***
  • Posts: 1210
  • Country: au
Re: SCPI Programming Advice Requested
« Reply #5 on: May 15, 2014, 04:42:57 pm »
Python's very easy and powerful for this kind of thing. 

MatPlotLib combined with the other numerical packages mean there's not a lot you can't do with the results.

Whilst I don't particularly like programming in Python compared to some other languages, it's my go to for anything like this.  Creating a script that can acquire the measurements and produce a graphical representation is quick and easy.  My only real complaint is dealing with binary packed data can be a pain.
 

Offline Lukas

  • Frequent Contributor
  • **
  • Posts: 412
  • Country: de
    • carrotIndustries.net
Re: SCPI Programming Advice Requested
« Reply #6 on: May 15, 2014, 07:30:53 pm »
My only real complaint is dealing with binary packed data can be a pain.
Huh? There's the struct module https://docs.python.org/3.3/library/struct.html which makes extracting data from packed binary data very easy.
 

Offline Harvs

  • Super Contributor
  • ***
  • Posts: 1210
  • Country: au
Re: SCPI Programming Advice Requested
« Reply #7 on: May 16, 2014, 01:53:30 am »
Huh? There's the struct module https://docs.python.org/3.3/library/struct.html which makes extracting data from packed binary data very easy.

I'm just a hack a python, I've never put real time into learning it since it doesn't pay the bills. However, here's an example of what I (as a C programmer) find difficult in python.

I have a uint8 from a serial port 0x7C that has a 5bit twos complement value in bits 6 downto 2, I need it extract it as a standard int. e.g.
__int32 unpacked_int = (((__int32)data) << 25) >> 27;
ans: -1
How would I go about that in python?

As I understand it the struct module is good for unpacking standard C types.  Which is great for networking or file unpacking between PCs.

Anyway I have no interest in a language pissing match that these types of posts usually turn into, I just don't find it intuitive working at the bit level.
 

Offline BitstreamTopic starter

  • Contributor
  • Posts: 15
  • Country: us
Re: SCPI Programming Advice Requested
« Reply #8 on: May 16, 2014, 04:35:38 am »
I tried getting EZGPIB to work on the HP 6332B with the VISA commands with no success.  Note, I'm using EZGPIB with a USB-to-serial converter (FTDI chip).  From the EZGPIB documentation, it looks like it should work with the VISA communication path.  I opened the interface on the COM port (COM6) and tried to send a simple SCPI "OUTPUT ON" command.  I get no response from the power supply.  I did verify if I used a terminal emulator (e.g. Termite), I can successfully send the command so I know it's not the hardware linkage.  My next step is to hook up a logic analyzer and see what is going out the serial bus.  The EZGPIB code I'm running is:


Program HP6332B-VISA;

var Status:Integer;
    CountWritten:Integer;
    RM:Integer;
    VI:Integer;

begin;
  EZGPIB_ScreenClear;
 
  Status:=EZGPIB_viOpendefaultRM(RM);
  EZGPIB_TimeSleep(0.1);
  EZGPIB_screenwrite ('Status for VISA session start: ');
  EZGPIB_screenwriteln(Status);
 
  Status:=EZGPIB_viOpen(RM,'ASRL6::INSTR',0,0,VI);
  EZGPIB_TimeSleep(0.1);
  EZGPIB_screenwrite ('Status for VISA connect to instrument: ');
  EZGPIB_screenwriteln(Status);
 
  Status:=EZGPIB_viWrite(VI,'OUTPUT ON\n',CountWritten);
  EZGPIB_TimeSleep(0.1);
  EZGPIB_screenwrite ('Status for VISA write to instrument: ');
  EZGPIB_screenwrite(Status);
  EZGPIB_screenwrite(' Chars written: ');
  EZGPIB_screenwriteln(CountWritten);
 
  Status:=EZGPIB_viClose(VI);
  EZGPIB_TimeSleep(0.1);
  EZGPIB_screenwrite ('Status for VISA close connection: ');
  EZGPIB_screenwriteln(Status);

 

Offline babysitter

  • Frequent Contributor
  • **
  • Posts: 900
  • Country: de
  • pushing silicon at work
Re: SCPI Programming Advice Requested
« Reply #9 on: May 16, 2014, 06:49:45 am »
Until I got my prologix, I used the serial port with a USB converter and EZGPIB too... take care of the line end characters \r and \n !
I'm not a feature, I'm a bug! ARC DG3HDA
 

Offline BitstreamTopic starter

  • Contributor
  • Posts: 15
  • Country: us
Re: SCPI Programming Advice Requested
« Reply #10 on: May 16, 2014, 05:45:46 pm »
OK -I have a stupid question.  I went back to the straight EZGPIB_Com commands with no VISA.  I'm running the command " EZGPIB_ComWrite(6,'OUTPUT ON\n');  ".  The character stream shows up clearly on the logic analyzer (see the attached pic) but EZGPIB is interpreting the "\n" literally and not converting it into the ASCII code for a line feed.  Am I missing something silly here?  Once I get that figured out, I believe I'll be good to go with EZGPIB.

 

Offline BitstreamTopic starter

  • Contributor
  • Posts: 15
  • Country: us
Re: SCPI Programming Advice Requested
« Reply #11 on: May 16, 2014, 06:10:17 pm »
Aha -I figured it out -had to append '+#10' after the text string:  EZGPIB_ComWrite(6,'OUTPUT ON'+#10);
'+\n' doesn't work and adding \n directly after the text in the quotes doesn't work.

Anyway, now that I have it working, it's time to have some fun
 

Offline babysitter

  • Frequent Contributor
  • **
  • Posts: 900
  • Country: de
  • pushing silicon at work
Re: SCPI Programming Advice Requested
« Reply #12 on: May 16, 2014, 06:45:40 pm »
Fun is good, I am right now playing with the Prologix too trying to have fun, after having fun with the babies ! ^-^

(Readout of a talker-only Time interval counter, unrelated, not even SCPI enabled)

I'm not a feature, I'm a bug! ARC DG3HDA
 

Offline rfbroadband

  • Supporter
  • ****
  • Posts: 186
  • Country: us
Re: SCPI Programming Advice Requested
« Reply #13 on: May 18, 2014, 03:28:57 am »
I have been writing programs to control equipment for quite some time now in different languages and different OS. I have dealt with VISA drivers (and I don't like them for a variety of reasons) and I have now settled on

- MatLab using raw TCP/IP socket and SCPI commands, no VISA drivers required at all.
- it is platform (OS) independent, the same code runs on Windows, Linux and OS X since Matlab is available on all OS.
- Matlab is not necessarily cheap, you could use Octave as an alternative
- TCP/IP obviously only works with Ethernet enabled equipment, but GPIB and USB work just fine out of MatLab as well.

At the end you will get it to work in whatever programming language you feel comfortable with. be it Python, C, C++ Delphi etc....

It is really your call. One thing to keep in mind, figure out which programming environment saves you the most time. Do you plan to plot data in graphs, store measurement results in databases etc.....try to avoid to re-invent the wheel....that's why MatLab is useful for many of my situations, I have access to tons of libraries that I don't have to write myself...
 

Offline BitstreamTopic starter

  • Contributor
  • Posts: 15
  • Country: us
Re: SCPI Programming Advice Requested
« Reply #14 on: May 19, 2014, 01:14:32 am »
Thanks for the advice.  I mainly want to be able to write a control program where I can control outputs based on a combination of inputs.  I'm using an HP6332B power supply for power output and an Agilent 34970A DAQ with the 20-channel MUX card for inputs and the multifunction card for outputs.  I don't really need to do plotting, though that may come later.  I've been playing around with EZGPIB and that seems to work well for what I want to do right now.  It also seems to save me the most time right now.  If I get stuck later, I may have to break down and purchase Matlab.  I see the home version is $149.  That's not too bad but I don't want to spend money if I don't have to so I'll see how far I can go with EZGPIB for now.
 

Offline BitstreamTopic starter

  • Contributor
  • Posts: 15
  • Country: us
Re: SCPI Programming Advice Requested
« Reply #15 on: May 21, 2014, 12:37:20 am »
babysitter,
When you used EZGPIB with the serial port on your test equipment, did you have to insert delays when doing reads from the device?  For example, after issuing the *IDN? command, I have to insert the delay "EZGPIB_TimeSleep(0.1);".  Otherwise, I'll only get a partial string returned because the device is still returning characters when EZGPIB has moved on to the next line of code where another SCPI command gets issued.  Do you ever have to insert delays when using the GPIB port on the test equipment?  Also, when using GPIB, do have to add the end of line character to the text string (+#10) or is that handled automatically with GPIB?  Those two shortcomings with the serial port are enough to push me into buying the Prologic USB-to-GPIB adapter +GPIB cables as long as things are easier when programming over the GPIB interface.

Finally, I haven't used GPIB much.  When attaching multiple devices, is it better to do a star configuration where all the devices connect at the Prologix adapter or is it better to daisy chain all the devices together?  Do you find you have to have all the devices on for GPIB to work reliably?

Sorry about the many questions but I'm sure you've already been through all this already.

-Thanks
 

Offline alex.forencich

  • Frequent Contributor
  • **
  • Posts: 397
  • Country: us
    • Alex Forencich
Re: SCPI Programming Advice Requested
« Reply #16 on: May 22, 2014, 03:05:58 am »
If you're going to get a GPIB box of some sort, I highly recommend a GPIB to LAN box such as the old Agilent E2050.  THey can be had on ebay (from time to time) for about $100.  They will expose a VXI-11 interface on the LAN side that will work with pretty much anything capable of talking to LAN based instruments.  It's also very convenient just to connect the box to your home network so you can just connect to it over wifi. 

I also have a set of Python libraries (Python IVI) that I have developed over the past couple of years that can communicate with serial, VXI-11, GPIB, and USB instruments, it can leverage PyVISA as well if it is installed, and it's been verified to work in Windows, Linux, and Mac OS.  The serial port support is pretty good; it just wraps pySerial.  I have not had any issues with delays, but I have not used the serial interface extensively. 

GPIB interfaces are supposed to not affect the bus when the instrument is off, and I have not had any issues with this so far (with mostly HP/Agilent gear and a bit of Tektronix and Colby thrown in for good measure).  One potential issue I have heard of, though, is the drive strength of the GPIB controller.  The cheap ones don't always use the proper drive chips, and as a result they don't always drive long calbes/lots of endpoints very well. 
Python-based instrument control: Python IVI, Python VXI-11, Python USBTMC
 

Offline babysitter

  • Frequent Contributor
  • **
  • Posts: 900
  • Country: de
  • pushing silicon at work
Re: SCPI Programming Advice Requested
« Reply #17 on: May 22, 2014, 06:34:00 am »
babysitter,
When you used EZGPIB with the serial port on your test equipment, did you have to insert delays when doing reads from the device?  For example, after issuing the *IDN? command, I have to insert the delay "EZGPIB_TimeSleep(0.1);".  Otherwise, I'll only get a partial string returned because the device is still returning characters when EZGPIB has moved on to the next line of code where another SCPI command gets issued.  Do you ever have to insert delays when using the GPIB port on the test equipment?  Also, when using GPIB, do have to add the end of line character to the text string (+#10) or is that handled automatically with GPIB?  Those two shortcomings with the serial port are enough to push me into buying the Prologic USB-to-GPIB adapter +GPIB cables as long as things are easier when programming over the GPIB interface.

Finally, I haven't used GPIB much.  When attaching multiple devices, is it better to do a star configuration where all the devices connect at the Prologix adapter or is it better to daisy chain all the devices together?  Do you find you have to have all the devices on for GPIB to work reliably?

Sorry about the many questions but I'm sure you've already been through all this already.

-Thanks

Hi Bitstream,

of course I waited (you can only get out of the buffer what is already in) and of course I had to play with the CR/LF on line end.

But no one will interfere if you write your own handler functions - GPIB Read can be done with a BusWaitForData where you specify your patience too, so your read handler might just consist of a wait time, read command and possibly some postprocessing too(timestamping, conversion of your favourite numerical format, sanity checks...)

I'm not a feature, I'm a bug! ARC DG3HDA
 

Online MarkL

  • Supporter
  • ****
  • Posts: 2478
  • Country: us
Re: SCPI Programming Advice Requested
« Reply #18 on: May 22, 2014, 11:39:24 am »
Finally, I haven't used GPIB much.  When attaching multiple devices, is it better to do a star configuration where all the devices connect at the Prologix adapter or is it better to daisy chain all the devices together?  Do you find you have to have all the devices on for GPIB to work reliably?
Any combination of star or linear is fine.  The maximum total cable length is 2m * the number of devices, or 20m, whichever is less.

The spec says you need to have two-thirds of the devices powered on for unimpeded performance (as long as all the devices are compliant).  That being said, I've never had any problems with everything off except the one piece of equipment I'm working with.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->