> Visual Basic
> This function can be called in a Visual Basic program. It demonstrates connection and setting parameters in the instrument while using Ethernet Socket protocol.
> Public Sub CommunicationWithTCPIPSocket()
> Const MAX_CNT = 200
> Dim stat As Variant
> Dim dfltRM As Variant
> Dim sesn As Variant
> Dim retCount As Long
> Dim Buffer As String * MAX_CNT
> Dim Response As String * VI_FIND_BUFLEN
> Dim sInputString As String
> Dim ipAddress As String
> Dim Port As String
> Rem Begin by initializing the system
> stat = viOpenDefaultRM(dfltRM)
> If (stat < VI_SUCCESS) Then
> Rem Error initializing VISA...exiting
> Exit Sub
> End If
> Rem Open communication with Ethernet Socket Protocol
> Rem before open an new Ethernet session make sure session was closed
> Rem NOTE: For simplicity, we will not show error checking
> 'address and port
> 'this sample address
> ipAddress = "172.26.202.117"
> 'For S331L port will be 9001
> Port = "9001"
> stat = viOpen(dfltRM, "TCPIP0::" & ipAddress & "::" & Port & "::SOCKET", VI_NULL, VI_NULL, sesn)
> Rem Set some visa attributes
> Rem recommandation timeout >= 90 sec
> stat = viSetAttribute(sesn, VI_ATTR_TMO_VALUE, 90000)
> stat = viSetAttribute(sesn, VI_ATTR_SEND_END_EN, VI_TRUE)
> Rem VI_ATTR_SUPPRESS_END_EN has to set to False during Ethernet Socket communication
> stat = viSetAttribute(sesn, VI_ATTR_SUPPRESS_END_EN, VI_FALSE)
> stat = viClear(sesn)
> Rem NOTE:
> Rem All commands (SCPI) must be send with linefeed
> Rem during Ethernet Socket communication
> Rem i.e. "vbLf" is in Visual Basic environment constant
> 'read back the strat frequency
> sInputString = "*IDN?" & vbLf
> stat = viWrite(sesn, sInputString, Len(sInputString), retCount)
> Buffer = ""
> stat = viRead(sesn, Buffer, MAX_CNT, retCount)
> 'System preset
> sInputString = ":SYSTEM:PRESET" & vbLf
> stat = viWrite(sesn, sInputString, Len(sInputString), retCount)
> 'Wait for previous operation to be completed
> sInputString = "*OPC?" & vbLf
> stat = viWrite(sesn, sInputString, Len(sInputString), retCount)
> Buffer = ""
> stat = viRead(sesn, Buffer, MAX_CNT, retCount)
> 'Set start frequency
> sInputString = ":SENSe:FREQuency:STARt 1 GHz" & vbLf
> stat = viWrite(sesn, sInputString, Len(sInputString), retCount)
> 'read back the strat frequency
> sInputString = ":SENSe:FREQuency:STARt?" & vbLf
> stat = viWrite(sesn, sInputString, Len(sInputString), retCount)
> Buffer = ""
> stat = viRead(sesn, Buffer, MAX_CNT, retCount)
> 'Set stop frequency
> sInputString = "SENSe:FREQuency:STOP 4 GHz" & vbLf
> stat = viWrite(sesn, sInputString, Len(sInputString), retCount)
> 'read back the stop frequency
> sInputString = ":SENSe:FREQuency:STOP?" & vbLf
> stat = viWrite(sesn, sInputString, Len(sInputString), retCount)
> Buffer = ""
> stat = viRead(sesn, Buffer, MAX_CNT, retCount)
> Rem Close down the system
> stat = viClose(sesn)
> stat = viClose(dfltRM)
> End Sub