S331P Site Master™ Programming Manual : General Information : Sending SCPI Commands
 
Sending SCPI Commands
SCPI commands can be sent to the instrument through any Virtual Instrument Software Architecture (VISA) controller. VISA is a commonly used API in the Test and Measurement industry for communicating with instruments from a PC. The physical connection between the PC and the instrument is USB or Ethernet. NI-VISA is the National Instruments implementation of the VISA I/O standard. Information and downloads are available at: http://www.ni.com/visa/
The following example describes the verification that a VISA controller can interact with the instrument. The images shown and the instructions for your instrument and software may differ from the examples.
Ethernet Connectivity
1. On the PC, run NI Measurement & Automation Explorer or VISA Interactive Control and create a new LAN Resource under Network Devices. Add the TCP/IP resource using a Manual Entry of Raw Socket, as shown in the example below.
NI VISA Interactive Control LAN Resource Addition Using Raw Socket
2. Enter the IP address that the instrument has acquired (On the S331P, go to System, Status, Connectivity Info, then enter the IP address as shown in Figure: NI VISA Interactive Control LAN Resource Settings of IP Address and Port Number.
3. Enter port 9001 and validate the connection (note that the latest versions of Windows 10 and above may require port 59001). If the connection is not validated, enter the other port number and try validating the connection again.
NI VISA Interactive Control LAN Resource Settings of IP Address and Port Number
NI VISA Interactive Control LAN Resource Validated
4. Select the Configuration I/O settings tab and verify that the Termination Methods are set as shown in the example below.
NI VISA Interactive Control LAN Resource I/O Termination Method Settings
5. Select the Input/Output Basic I/O tab and execute the default *IDN? Query. If the PC is connected to the instrument the command returns the following information from the Buffer: manufacturer name (“Anritsu”), model number/options, serial number, and firmware package number, as shown in the example below.
NI VISA Interactive Control USB Basic I/O Tab
 
Note 
When sending SCPI commands over Ethernet, it is required to send a newline termination character at the end of each command. In the example above, a newline character ("\n" in this case, but could be different depending on your programming environment) was used to terminate the *IDN? command.
Note 
When sending query commands over raw socket, the entire buffer must be read before the next query command is sent. Each query result is terminated by a newline to help identify the end of the query response. Query read operations could be broken into multiple reads, if necessary.
Note 
When using raw socket connections, you must close a session before opening a new one or before switching to a new protocol (such as USB). If you try to open a new session or switch protocols without first closing the previously opened session, you may lose communications with the instrument and not be able to reconnect until you reboot the instrument.