Agilent Technologies N5980A manual Sample Code

Page 42

Programming Reference

Sample Code

The following example code shows how to control the N5980A from within a remote program. The example code is implemented in C#.

The code snippets show the required code that needs to be added to a user program.

It implements a class N5980A in the namespace N5980AExample that allows communication with the N5980A user software.

using System;

using System.Collections.Generic; using System.Text;

using System.Net;

using System.Net.Sockets; using System.Windows.Forms;

namespace TBertExample

{

class N5980A

{

///<summary>

///Holds the input buffer when reading from the socket.

///</summary>

byte[] bufferin = new byte[64 * 1024];

///<summary>

///Holds the TcpClient that is used to establish the

///remote connection.

///</summary>

TcpClient m_Client = null;

///<summary>

///Holds the NetworkStream that provides the communication

link.

///</summary>

NetworkStream m_Stream = null;

///<summary>

///Connect to the instrument with the given hostname and

///port number. Both values can be retrieved by the

///Connection -> Info... menu item in the N5980A software

///</summary>

///<param name="host">Hostname of the PC that executes

///the N5980A software.</param>

///<param name="port">Port number of the software instance

///to communicate with.</param>

public void Connect(string host, int port)

{

try

{

//resolve address of the given hostname IPHostEntry ipHostEntry = Dns.Resolve(host); IPAddress ipAddress = ipHostEntry.AddressList[0];

//create TcpClient and connect it to the instrument m_Client = new TcpClient(); m_Client.Connect(new IPEndPoint(ipAddress, port)); m_Stream = m_Client.GetStream();

}

catch (Exception e)

{

MessageBox.Show(e.Message, "Connect");

}

}

///<summary>

///Close the connection with the N5980A software.

42

N5980A User Guide

Image 42
Contents Agilent 125 Gb/s Serial Bert Revision 1.0 May Herrenberger StrSafety Summary Environmental Information Contents Programming Reference Introduction CD content is Inspect ShipmentSerial Bert Connect the Instrument Front PanelRear Panel To Connect N5980AInstall User Software for N5980A Serial Bert setup diagramTo Install the User Software for N5980A Select the folder in which N5980A will be saved To Access N5980A Demo Offline Advanced Mode IntroductionRunning the BER Test Setting the Instrument Parameters SetupAdvanced Viewing the Results BER displays Gating BER and the Elapsed Gating TimeAdvanced Mode Store SettingFile Menu Connection Menu Connect Each PC can control only one N5980AError Indicators Help MenuInfo Error BER BarSync Loss Setup and Advanced Tab GeneralGenerator SFP Data Pattern Error DetectorInput SMA Data PatternBER and Advanced BER Tab Gating BER BarError Detector Pattern Gating ErrorsActual Errors Advanced BERCommon Command Summary Agilent N5980A Command SummaryScpi Instrument Command List- Reference Common CommandsID Query Operation complete Read error queueLoad factory default setting Option QueryAll Channels Store current settingRecall setting DatarateSOUR1PATT SMA Output Electrical GeneratorPattern Either sets or gets the pattern of the SMA outputInsertion Rate Error InsertionAdd Single Error Output LevelSFP Output Optical Generator SOUR2PATTEither sets or gets the pattern of the SFP output SOUR2PATTEADDRATE SOUR2PATTEADD OnceSyntax SOUR2PATTEADD Once SOUR3PATT Trigger OutputDetected Pattern SENS1PATT?Synchronization mode Actual Bit Error RateActual Number of Errors Gating Time Gating Bit Error RateGating Number of Errors Start GatingInput Selection Description Selects the input for the error detectorGating Progress SENS1INPSample Code Communicate with the instrument Programming Reference