Control Using SICL-LAN Server

Other topics about Sample Application Program

Overview

This section explains how to control the E5071C by using SICL in the Windows environment.

Sample Program in Excel VBA

Opening ctrl_lansicl.xls in Microsoft Excel displays a screen as shown in the figure below:

ctrl_lansicl.xls

For how to use each element in ctrl_lansicl.xls, refer to the following description.

  1. In part 1, in the cell to the right of the SICL-LAN Address, enter the address of the E5071C for control with the SICL-LAN server. This address is XX, which has been set with the command System > Misc Setup > Network Setup > SICL-LAN Address [XX]. Enter the IP address of the E5071C in the cell to the right of the IP Address. This VBA macro will not work properly without the correct values in these two cells.

  2. Click Preset in part 2  to execute the presetting operation.

  3. In part 3, the sweep range (start and stop points) and the number of measurement points for channel 1 are set. Click Set to execute the setting as shown in the setting table.

  4. Part 4 sets the measurement parameters and data format for trace 1 in channel 1. Click Set to execute the setting as shown in the setting table.

  5. Click Read Trace in part 5 retrieves the formatted data array of trace 1 in channel 1. The data is displayed in tabular and graphical format.

Description of Operation in VBA macro

This section describes the operation of the VBA macro, focusing on the part related to control with SICL.

The basic control flow with SICL is shown in Flow of control using SICL.

Flow of control using SICL

 

The procedures of each step in Flow of control using SICL are described below.

Connection

The procedure corresponding to connection is OpenSession (OpenSession). OpenSession establishes a connection to the E5071C with the iopen function of SICL, using the SICL-LAN Address and IP Address entered in part 1 in ctrl_lansicl.xls. The iopen function takes the address information of the E5071C you specify as its parameters.

Syntax

addr = iopen(dev)

 

Variable

addr

Description

Session information (output)

Data type

Integer type

 

dev

Description

Address information of the instrument you specify (input)

Data type

Character string type

Grammar

sicl-name [ip-address]:interface, sicl-lan-address

For example, if the parameter (dev) is "lan[192.168.0.1]:hpib9,17," connection is made to the address of 17 of the interface of hpib9 with the E5071C whose IP address is 192.168.0.1 by using the external controller whose SICL interface name is lan.

OpenSession

Function OpenSession() As Integer

Dim ServAddr As String

Dim IpAddr As String

On Error GoTo ErrHandler

'''Get Sicl-Lan Address

Sheets("Sheet1").Select

Range("C2").Select

ServAddr = ActiveCell.FormulaR1C1

'''Get Ip Address

Sheets("Sheet1").Select

Range("C3").Select

IpAddr = ActiveCell.FormulaR1C1

 

OpenSession = iopen("lan[" & IpAddr & "]:hpib9," & ServAddr)

Call itimeout(OpenSession, 10000)

Exit Function

ErrHandler:

MsgBox "*** Error : " & Error$

Call siclcleanup

End

End Function

 

Sending

The procedure corresponding to sending in communication is OutputSiclLan. OutputSiclLan uses the ivprintf function of SICL to send messages (SCPI commands). The ivprintf function takes the session information output from the iopen function and a program message as its parameters.

Syntax

Status = ivprintf(addr,mes)

 

Variable

Status

Description

Return value of the function (output)

Data type

Integer type

 

addr

Description

Session information (input)

Data type

Integer type

 

mes

Description

Program message (input)

Data type

Character string type

OutputSiclLan

Sub OutputSiclLan(addr As Integer, message As String)

 

Dim Status As Integer

Dim actualcnt As Long

Dim length As Long

 

On Error GoTo ErrHandler

length = Len(message)

Status = ivprintf(addr, message & Chr$(10))

Exit Sub

 

ErrHandler:

MsgBox "*** Error : " & Error$

Call siclcleanup

End

End Sub

 

Receiving

The procedure corresponding to receiving ASCII format messages in communication is EnterSiclLan. EnterSiclLan uses the ivscanf function of SICL to receive a message in ASCII format and store it into the output variable. The ivscanf function takes the session information output from the iopen function, the format for output, and the data to be output as its parameters.

Syntax

Status = ivscanf(addr,fmt,ap)

 

Variable

fmt

Description

Format for output (input)

Data type

Character string type

 

ap

Description

Data to be output (output)

Data type

Character string type

 

For information on the variable (Status) and the variable (addr), refer to Variable.

In Visual Basic, variables must be declared as a fixed-length string when receiving string data using the ivscanf function.

EnterSiclLan

Sub EnterSiclLan(addr As Integer, Query As String)

 

Dim Status As Integer

Dim actualcnt As Long

Dim res As String * 256

 

On Error GoTo ErrHandler

Status = ivscanf(addr, "%t", res)

Query = Trim(res)

Exit Sub

 

ErrHandler:

MsgBox "*** Error : " & Error$

Call siclcleanup

End

 

End Sub

 

The procedure corresponding to receiving array data in communication is EnterSiclLanArrayReal64, which uses the iread function of SICL to receive array data in the IEEE 64-bit floating point binary transfer format and store it into the output variable. The iread function takes the session information output from the iopen function, the data to be output, the number of data bytes, the condition to finish reading data, and the number of data bytes actually read out as its parameters.

Syntax

Status = iread(addr,buf,bufsize,reason,actual)

 

Variable

buf

Description

Data to be output (output)

Data type

Character string type

 

bufsize

Description

The number of data bytes (input)

Data type

Long integer type

 

reason

Description

The condition to finish reading out data (input)

Data type

Integer type

 

actual

Description

The number of data bytes actually read out (output)

Data type

Long integer type

 

For information on the variable (Status) and the variable (addr), refer to Variable.

 

Each functional part of EnterSiclLanArrayReal64 is described below.

(1) Retrieves the data header.

(2) Stores the number of data bytes into the size variable in the header part.

(3) Retrieves the formatted data array for trace 1 in channel 1 and stores it into the databuf variable.

(4) Retrieves the message terminator at the end of the data.
 

EnterSiclLanArrayReal64

Function EnterSiclLanArrayReal64(addr As Integer, databuf() As Double) As Long

 

Dim Status As Integer

Dim actualcnt As Long

Dim buf As String * 8

Dim size As Long

On Error GoTo ErrHandler

'''Read header info of "#6NNNNNN"

Status = iread(addr, buf, 8, I_TERM_MAXCNT, actualcnt) '.................(1)

size = Val(Mid$(buf, 3, 6)) '.................(2)

'''Read data

Status = iread(addr, databuf, size, I_TERM_MAXCNT, actualcnt) '.................(3)

'''Read ending LF

Status = iread(addr, buf, 1, I_TERM_MAXCNT, actualcnt) '.................(4)

EnterSiclLanArrayReal64 = size / 8

Exit Function

 

ErrHandler:

MsgBox "*** Error : " & Error$

Call siclcleanup

End

End Function

 

Disconnection

The iclose function of SICL is used to disconnect communication. The iclose function takes the session information output from the iopen function as its parameter.

Syntax

Status = iclose(addr)

For information on the variable (Status) and the variable (addr), refer to Variable

Sample control

The E5071C can be controlled by executing the above procedures in order, following the control flow in Flow of control using SICL. This is demonstrated by the Preset procedure (a procedure that is executed when the Preset button is clicked) as described in Preset.

Preset

Sub Preset()

 

''' Open Session

E507x = OpenSession

 

'''Presetting the analyzer

Call OutputSiclLan(E507x, ":SYST:PRES")

'''Close Session

Call iclose(E507x)

 

End Sub