element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Test & Tools
  • Technologies
  • More
Test & Tools
Blog Agilent / Keysight Spectrum Analyzer N9322C – Programming and Remote Control
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Test & Tools to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: shabaz
  • Date Created: 25 Aug 2014 10:27 PM Date Created
  • Views 3249 views
  • Likes 1 like
  • Comments 7 comments
  • RoadTest
  • keysight
  • n9322c
  • spectrum_analyser
  • visa
  • spectrum_analyzer
  • test_and_measurement
  • ti
  • agilent
Related
Recommended

Agilent / Keysight Spectrum Analyzer N9322C – Programming and Remote Control

shabaz
shabaz
25 Aug 2014

This blog post is part of a collection,/roadTestReviews/http://www.element14.com/community/roadTestReviews/1882#section2click here for links to the entire set, and a/roadTestReviews/http://www.element14.com/community/roadTestReviews/1882review of the products.

Introduction

Most test gear comes with remote connectivity options, and the Agilent N9322C Spectrum Analyzer (SA) is no different. It can be connected up via IEE-488 (available as an option) or via USB or Ethernet (available as standard).

For some screenshots of the SA, click here.

 

The SA is supplied with some nice client software described below but it is also possible to use third party software or make your own. It integrates into existing test beds using a supplied library discussed below.

This post briefly examines the connectivity options and how to programmatically control and manage the SA.

This post also provides a quick working example for program control for the N9322C but the concepts translate to other instruments too - plug in your instrument into the network (Ethernet port) or directly into your PC using a USB cable and you can control it using your own software in a dozen lines of code. It can be that simple.

image

 

Why would you want to do this?

There are many reasons. For engineers, documentation and recording of results is highly important. For test beds, automated control and measurement is needed.  Furthermore with a good implementation it becomes possible to have just as good an experience (if not better) using the instrument from your PC as it is from the instrument control panel.

Why would you want custom software control? It too is important for automated test of course, but also allows you to log data at periodic intervals, feed data directly into software, generate alarms or alerts, and also allows you to configure your instrument exactly the same way each time. It’s very cool.

 

Agilent Remote Control Software

Here is an example screenshot from the client software (known as Agilent BSA PC Software) that comes with the N9322C SA:

image

Once the software is installed, it is a quick process to get it working with the spectrum analyzer. It auto-detects the SA if it is plugged into a USB port on the PC, or if the SA is in the local area network. See the screenshots further below for further information.

 

The client software is fast and is not an identical repeat of the graphical user interface on the instrument. Instead, it makes the best use of the PC screen, scales up and allows you to use a mouse to drag to position markers quickly. Here is a very short (1 minute) video showing the basic spectrum analyzer view, a spectrogram view and manual marker positioning (there are auto peak detect options but I wanted to show the mouse drag behaviour):

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

The video above shows the screen scaled down, however on a large monitor the image scales gracefully as can be seen in this screenshot:

image

 

The BSA PC software is a very nice example of well executed remote control client software. I wouldn’t say it is perfect (and Linux and Mac client software is not available) however I can see it being the single most important application for most users to get installed if they plan on using this spectrum analyzer. It won’t be for everyone (some people may require third party software such as NI LabView for logging or post-processing purposes) but for design engineers the BSA PC software is great – it is quick and easy to use.

 

Although not explored here, the BSA PC software also allows the export of data into CSV files for processing using software such as Excel or MATLAB or GNU Octave, and for accessing files stored on the spectrum analyzer too.

 

For those installing the software, here are some screenshots of what to expect during the instrument discovery:

image

image

 

Programmable Behavior

As with most test gear, the Agilent / Keysight N9322C Spectrum Analyzer (SA) supports configuration and management/monitoring through a standard software abstraction known as Virtual Instrument Software Architecture (VISA).

 

In a nutshell it allows you to control your SA from your PC using Agilent, third party or your own custom software.

 

Sometimes it is hard finding concrete examples per test instrument, so I spent some time deciphering it now, so that I’m prepared if I ever need to do any automation or logging.

 

Even if you have a different instrument such as a multimeter or oscilloscope, you may be interested to know how to access it from your own software so it is good to spend time examining the programmer’s manual with your test instrument.

 

Here is a working example for Windows for the spectrum analyzer (the example in the user docs has a few unfortunate errors):

 

/******************************************************
* Test Program for Agilent / Keysight N9322C
* Revision 1 - shabaz Aug 2014
*
* To compile: C:\MinGW\bin>gcc.exe c:\MySourceCode\agilent\satest.c -o satest -I "C:\Program Files\IVI Foundation\VISA\Win64\agvisa\include" -L "C:\Program Files\IVI Foundation\VISA\Win64\agvisa\lib\msc" -lagvisa32
*
******************************************************/

#include "visa.h"
#include <stdio.h>
#include <stdlib.h>


#define VIERRORMSG(V,M) if ((V)!=VI_SUCCESS) { fprintf(stderr, "[ERROR] " M "\n"); exit(1); }


int
main(void)
{
  char buf[300];
  ViSession viN9322C;
  ViStatus viStatus;
  ViSession defaultRM;

  printf("N9322C Test Program\n");
  // Open session to USB device
  viStatus=viOpenDefaultRM(&defaultRM);
  VIERRORMSG(viStatus, "viOpenDefaultRM");
  viStatus=viOpen(defaultRM,"USB0::0x0957::0xFFEF::CN0743A192::0::INSTR",VI_NULL,VI_NULL,&viN9322C);
  VIERRORMSG(viStatus, "viOpen");
  // Initialize device
  viStatus=viPrintf(viN9322C, "*RST\n");
  VIERRORMSG(viStatus, "viPrintf RST");
  // Send an *IDN? string to the device
  viStatus=viPrintf(viN9322C, "*IDN?\n");
  VIERRORMSG(viStatus, "viPrintf IDN");
  // Read results
  viStatus=viScanf(viN9322C, "%t", buf);
  VIERRORMSG(viStatus, "viScanf");
  // Print results
  printf("Instrument ID string: %s\n", buf);
  // Close the sessions
  viClose(viN9322C);
  viClose(defaultRM);

  return(0);
}
    

 

Here is how to get it working:

 

1. Install MinGW

2. Install Agilent IO Libraries Suite (it is on the supplied CD)

3. From the Windows Start button, run Agilent Connection Expert to get the instrument name (see the earlier screenshot above)

4. Edit the test program so that it contains the instrument name

5. Open up a Windows command prompt

6. Go to the C:\MinGW\bin folder and type the following line to compile the program:

gcc.exe c:\MySourceCode\agilent\satest.c -o satest -I "C:\Program Files\IVI Foundation\VISA\Win64\agvisa\include" -L "C:\Program Files\IVI Foundation\VISA\Win64\agvisa\lib\msc" -lagvisa32
    

Note that the paths may be different. My PC already had a VISA library installed for Tektronix instruments, so the Agilent version automatically installed as a secondary set.

7. Run the program by typing:

satest.exe
    

 

When the program is run, output similar to this will be seen:

N9322C Test Program
Instrument ID string: Agilent Technologies,N9322C,CN1234A567,A,04,47
    

 

The red ‘Remote’ LED indicator on the SA will also light up. To release remote operation and take back control of the SA front panel, press the Enter key and the Remote indicator will extinguish.

 

This is just a basic example showing how to send a command and how to retrieve the result of a query. More complex programs can be built of course.

 

Summary

The remote control client software and programming options are great. The Ethernet interface comes as standard, which is good to see. This is an instrument that is just as easy (if not more easy) and fun to use via remote control as it is via the in-built user interface.

 

Since “thinking” about how to attack a problem can take a long time, it’s actually quite nice to walk away from the SA and still be able to fully deep-dive into the configuration and monitoring from a more comfortable place!

  • Sign in to reply

Top Comments

  • michaelkellett
    michaelkellett over 11 years ago in reply to shabaz +1
    Hello Shabaz, With other HP/Agilent/Keystone insturments I've tried you just send the SCPI commands to the correct port via a TCP socket. Rigol don't seem to reliably publish the ports they use so I sniffed…
  • Robert Peter Oakes
    Robert Peter Oakes over 11 years ago in reply to michaelkellett +1
    So no sign of pre-amble in the code there, just straight talking to the device with text so not sure what additional data is for, I agree one of the fields matches the string length, but I would need to…
Parents
  • michaelkellett
    michaelkellett over 11 years ago

    I notice that you've used the VI horror and bloatware (sorry I have an allergy to VISA image) to interface C with the N9322C. But once you've done this you're still sending SCPI commands as text strings. I've had a lot less trouble just talking directly through a TCP socket -  one is sending just the same text strings but you don't need to install any additional software or drivers.

    I recently bought  a Keithly Dual SMU (2614B) which I control the same way. Keithly call the direct interface the "raw" interface but interestingly this instrument doesn't really support SCPI but uses Lua internally and as its command language.  Once you get used to it it's very nice and you can develop a test sequence sending commands one at  a time but then, because the commands are just lines of Lua, you can build them into a  script which you download to the instrument and they can all run as  a block.

     

    The point of all this is to get round to asking you if the N9322C supports any higher level remote control protocol/command set than SCPI commands.

     

    Thanks for blog 1 !

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 11 years ago in reply to michaelkellett

    There does appear to be some sort of header before the command, and I'm not sure what it is :-(

    (The captures for the *RST and *IDN? commands are captured below).

    Most of it looks the same however - maybe the byte that changed is a length or sequence number. So, it's probably

    decipherable and if so, control from any platform should be possible.

     

    image

     

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelkellett
    michaelkellett over 11 years ago in reply to shabaz

    Hello Shabaz,

     

    With other HP/Agilent/Keystone insturments I've tried you just send the SCPI commands to the correct port via a TCP socket. Rigol don't seem to reliably publish the ports they use so I sniffed them to find likely candidates. I found this useful list of HAK (HP/Agilent/Keystone) ports:

     

    Below are the following protocol and port numbers used by Agilent instruments. Most instrument connections are VXI-11 or SOCKETS. 

     

    Name Protocol Port What is it for? Notes

    VXI-11/SICLLAN communications ports TCP dynamic, but usually starts at port 1024 and dynamically goes up from there (you will need to test this for your instrument)

    Discovery of the instrument, Communication with the instrument Used in conjunction with the ONC-RPC port mapper (Windows assigned)

     

    ONC-RPC port mapper TCP/UDP 111 Discovery of the instrument, Communication with the instrument Used in conjunction with the VXI-11 SICLLAN communication ports

     

    SCPI Sockets TCP 5025 Communication with the instrument Use this port to open a raw TCP/IP connection to send raw SCPI commands to the instrument

     

    HiSLIP TCP 4880 Communication with the instrument Used to communicate with newer Agilent instruments

     

    SCPI Telnet TCP 5024 Communication with the instrument Use this port to open a Telnet connection to the instrument to send SCPI commands

     

    mDNS Discovery UDP 5353 Discovery of the instrument mDNS is used to discover newer Agilent LXI instruments on the local subnet

     

    LXI Events TCP/UDP 5044 Port on which instrument listens for LXI Events Not all Agilent instruments implement this feature

     

    PTP Events UDP 319 Port on which instrument listens for Precision Time Protocol Event messages Not all Agilent instruments implem

    ent this feature

    PTP General UDP 320 Port on which instrument listens for Precision Time Protocol General messages Not all Agilent instruments implement this feature

     

    HTTP Server TCP 80 Serves the instruments webpage Implemented by all Agilent LXI instruments

     

    VNC TCP 5900 Remote display of instrument screen Used by some Agilent Windows-based instruments

     

    Remote Desktop TCP 3389 Remote login to instrument Available for Agilent Windows-based instruments

     

    at Keysight Technologies Support Forums : ports numbers used by Agilent PC ...

     

    The following is a snippet of Python which talks to an Agilent 34461A and a Rigol DM0132Z:

     

     

        import socket, signal, sys 

        import math

        import time

        from pylab import *

        

        #def signal_handler(signal, frame): 

        # s.close() 

        # sys.exit(0) 

        

        hpdmm=socket.socket(socket.AF_INET, socket.SOCK_STREAM) 

        hpdmm.connect(('192.168.1.101', 5025)) 

        #hpdmm.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) 

      

        siggen=socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        siggen.settimeout(2) 

        siggen.connect(('192.168.1.104', 5555))

         

        message = "*IDN?\n"

        hpdmm.sendall(bytes(message, 'UTF-8'))

        siggen.sendall(bytes(message, 'UTF-8'))  

        print (hpdmm.recv(1024)) 

        print (siggen.recv(1024))

      

        message = ":SYST:ERR?\n"

        siggen.sendall(bytes(message, 'UTF-8'))

        print (siggen.recv(1024))

     

      

        message = ":SOUR1:APPL:SIN 20,1,0,0\n"

        siggen.sendall(bytes(message, 'UTF-8'))

     

     

    As you can see you just send the SCPI straight to the port - probably 5025 for your spectrum analyser.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • michaelkellett
    michaelkellett over 11 years ago in reply to shabaz

    Hello Shabaz,

     

    With other HP/Agilent/Keystone insturments I've tried you just send the SCPI commands to the correct port via a TCP socket. Rigol don't seem to reliably publish the ports they use so I sniffed them to find likely candidates. I found this useful list of HAK (HP/Agilent/Keystone) ports:

     

    Below are the following protocol and port numbers used by Agilent instruments. Most instrument connections are VXI-11 or SOCKETS. 

     

    Name Protocol Port What is it for? Notes

    VXI-11/SICLLAN communications ports TCP dynamic, but usually starts at port 1024 and dynamically goes up from there (you will need to test this for your instrument)

    Discovery of the instrument, Communication with the instrument Used in conjunction with the ONC-RPC port mapper (Windows assigned)

     

    ONC-RPC port mapper TCP/UDP 111 Discovery of the instrument, Communication with the instrument Used in conjunction with the VXI-11 SICLLAN communication ports

     

    SCPI Sockets TCP 5025 Communication with the instrument Use this port to open a raw TCP/IP connection to send raw SCPI commands to the instrument

     

    HiSLIP TCP 4880 Communication with the instrument Used to communicate with newer Agilent instruments

     

    SCPI Telnet TCP 5024 Communication with the instrument Use this port to open a Telnet connection to the instrument to send SCPI commands

     

    mDNS Discovery UDP 5353 Discovery of the instrument mDNS is used to discover newer Agilent LXI instruments on the local subnet

     

    LXI Events TCP/UDP 5044 Port on which instrument listens for LXI Events Not all Agilent instruments implement this feature

     

    PTP Events UDP 319 Port on which instrument listens for Precision Time Protocol Event messages Not all Agilent instruments implem

    ent this feature

    PTP General UDP 320 Port on which instrument listens for Precision Time Protocol General messages Not all Agilent instruments implement this feature

     

    HTTP Server TCP 80 Serves the instruments webpage Implemented by all Agilent LXI instruments

     

    VNC TCP 5900 Remote display of instrument screen Used by some Agilent Windows-based instruments

     

    Remote Desktop TCP 3389 Remote login to instrument Available for Agilent Windows-based instruments

     

    at Keysight Technologies Support Forums : ports numbers used by Agilent PC ...

     

    The following is a snippet of Python which talks to an Agilent 34461A and a Rigol DM0132Z:

     

     

        import socket, signal, sys 

        import math

        import time

        from pylab import *

        

        #def signal_handler(signal, frame): 

        # s.close() 

        # sys.exit(0) 

        

        hpdmm=socket.socket(socket.AF_INET, socket.SOCK_STREAM) 

        hpdmm.connect(('192.168.1.101', 5025)) 

        #hpdmm.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) 

      

        siggen=socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        siggen.settimeout(2) 

        siggen.connect(('192.168.1.104', 5555))

         

        message = "*IDN?\n"

        hpdmm.sendall(bytes(message, 'UTF-8'))

        siggen.sendall(bytes(message, 'UTF-8'))  

        print (hpdmm.recv(1024)) 

        print (siggen.recv(1024))

      

        message = ":SYST:ERR?\n"

        siggen.sendall(bytes(message, 'UTF-8'))

        print (siggen.recv(1024))

     

      

        message = ":SOUR1:APPL:SIN 20,1,0,0\n"

        siggen.sendall(bytes(message, 'UTF-8'))

     

     

    As you can see you just send the SCPI straight to the port - probably 5025 for your spectrum analyser.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • Robert Peter Oakes
    Robert Peter Oakes over 11 years ago in reply to michaelkellett

    So no sign of pre-amble in the code there, just straight talking to the device with text so not sure what additional data is for, I agree one of the fields matches the string length, but I would need to see various different length commends to be captured before we could confirm

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 11 years ago in reply to Robert Peter Oakes

    I will capture some more, and see if we spot a pattern. We'll get to the bottom if it! image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Robert Peter Oakes
    Robert Peter Oakes over 11 years ago in reply to shabaz

    I look forward to it, I do enjoy a game of find the pin in a haystack image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube