Agilent Technologies N5980A manual Communicate with the instrument

Page 43

Programming Reference

/// </summary>

public void Disconnect()

{

if (m_Client != null)

m_Client.Close();

}

///<summary>

///Write to a SCPI command to a network socket and return

the

///response if it was a query.

///</summary>

///<param name="s">SCPI command to be written to the socket</param>

///<returns>Response of the instrument or an empty string

///if there is no response.</returns>

public string Send(string s)

{

string response = ""; int i;

//Write the string to the network socket byte[] bufferout = new byte[s.Length + 1]; for (i = 0; i < s.Length; i++)

bufferout[i] = (byte)s[i]; bufferout[s.Length] = (byte)'\n'; m_Stream.Write(bufferout, 0, bufferout.Length);

//If the string containes a '?', then it is a query and

//the response nneds to be read from the instrument

if (s.IndexOf('?') != -1)

{

// Read resonse from network stream

int numRead = m_Stream.Read(bufferin, 0, bufferin.Length);

// if the response contained any bytes, then convert

them

//to a valid string if (numRead > 0)

{

StringBuilder sb = new StringBuilder(); for (i = 0; i < numRead; i++)

sb.Append((char)bufferin[i]);

//make sure that all kind of terminators are

//reported as \r\n

sb.Append("\r\n");

response = sb.ToString().Trim(new char[] { '\r', '\n'

});

if (response.IndexOf("\r\n") != -1) response = response.Replace("\r\n", "\n");

if (response.IndexOf("\r") != -1) response = response.Replace("\r", "\r");

if (response.IndexOf("\n") != -1) response = response.Replace("\n", "\r\n");

}

}

return response;

}

}

}

Communicate with the instrument

Given the class above, the communication with the instrument can be done like this:

using System;

using System.Collections.Generic;

namespace TBertExample

{

static class Program

N5980A User Guide

43

Image 43
Contents Agilent 125 Gb/s Serial Bert Herrenberger Str Revision 1.0 MaySafety Summary Environmental Information Contents Programming Reference Introduction Inspect Shipment CD content isSerial Bert Front Panel Connect the InstrumentTo Connect N5980A Rear PanelSerial Bert setup diagram Install User Software for N5980ATo Install the User Software for N5980A Select the folder in which N5980A will be saved To Access N5980A Demo Offline Introduction Advanced ModeRunning the BER Test Setup Setting the Instrument ParametersAdvanced BER displays Gating BER and the Elapsed Gating Time Viewing the ResultsStore Setting Advanced ModeFile Menu Connection Menu Each PC can control only one N5980A ConnectHelp Menu Error IndicatorsInfo BER Bar ErrorSync Loss General Setup and Advanced TabGenerator SMA Data Pattern Error DetectorInput SFP Data PatternGating BER Bar BER and Advanced BER TabAdvanced BER Gating ErrorsActual Errors Error Detector PatternAgilent N5980A Command Summary Common Command SummaryCommon Commands Scpi Instrument Command List- ReferenceID Query Option Query Read error queueLoad factory default setting Operation completeDatarate Store current settingRecall setting All ChannelsEither sets or gets the pattern of the SMA output SMA Output Electrical GeneratorPattern SOUR1PATTOutput Level Error InsertionAdd Single Error Insertion RateSOUR2PATT SFP Output Optical GeneratorEither sets or gets the pattern of the SFP output SOUR2PATTEADD Once SOUR2PATTEADDRATESyntax SOUR2PATTEADD Once SENS1PATT? Trigger OutputDetected Pattern SOUR3PATTActual Bit Error Rate Synchronization modeActual Number of Errors Start Gating Gating Bit Error RateGating Number of Errors Gating TimeSENS1INP Description Selects the input for the error detectorGating Progress Input SelectionSample Code Communicate with the instrument Programming Reference