OpenTAP 9.27
API Reference
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
OpenTap.ScpiInstrument Class Reference

Implements a connection to talk to any SCPI-enabled instrument. More...

Inheritance diagram for OpenTap.ScpiInstrument:
OpenTap.Instrument OpenTap.IScpiInstrument OpenTap.Resource OpenTap.IInstrument OpenTap.IInstrument OpenTap.ValidatingObject OpenTap.IResource OpenTap.INotifyActivity OpenTap.IResource OpenTap.ITapPlugin OpenTap.IResource OpenTap.ITapPlugin OpenTap.IValidatingObject

Classes

struct  ScpiError
 A SCPI error. More...
 

Public Member Functions

override string ToString ()
 Overrides ToString() to give more meaningful names. More...
 
 ScpiInstrument ()
 Initializes a new instance of the ScpiInstrument class.
 
 ScpiInstrument (IScpiIO2 io)
 Initialize a new instance of ScpiInstrument, specifying a IScpiIO interface to use. More...
 
override void Open ()
 Opens the connection to the Instrument. Assumes Visa Address property is specified.
 
override void Close ()
 Closes the connection to the instrument. Assumes connection is open.
 
virtual string ScpiQuery (string query, bool isSilent=false)
 Sends a SCPI query to the instrument and waits for a response. More...
 
ScpiQuery< T > (string query, bool isSilent=false)
 As ScpiQuery except it will try to parse the returned string to T. See Scpi.Parse for details on parsing. More...
 
byte[] ScpiQueryBlock (string query)
 Sends a IEEE Block SCPI query to the instrument and waits for a response. The response is assumed to be IEEE block data. More...
 
virtual T[] ScpiQueryBlock< T > (string query)
 Sends a IEEE Block SCPI query to the instrument and waits for a response. The response is assumed to be IEEE block data. More...
 
void ScpiCommand (string command, params object[] parameters)
 Sends a SCPI command to the instrument, but with special handling for parameters. See Scpi.Format for more information. More...
 
virtual void ScpiCommand (string command)
 Sends a SCPI command to the instrument. More...
 
virtual void ScpiIEEEBlockCommand (string command, byte[] data)
 Sends a IEEE Block SCPI command to the instrument.
 
virtual void ScpiIEEEBlockCommand (string command, Stream data, long maxSize=0)
 Sends a IEEE Block SCPI command to the instrument with a Streaming interface for large data size. Uses DirectIO.
 
bool PollStatusEvent ()
 Polls the instrument for an event. More...
 
List< ScpiErrorQueryErrors (bool suppressLogMessages=false, int maxErrors=1000)
 Returns all the errors on the instrument error stack. Clears the list in the same call. More...
 
void WaitForOperationComplete (int timeoutMs=2000)
 Waits for a all previously executed SCPI commands to complete. More...
 
void Reset ()
 Aborts the currently running measurement and makes the default measurement active.
 
delegate void ScpiSRQDelegate (ScpiInstrument sender)
 A delegate that is used by the SRQ event. More...
 
- Public Member Functions inherited from OpenTap.Instrument
 Instrument ()
 Sets the name of the instrument.
 
- Public Member Functions inherited from OpenTap.Resource
 Resource ()
 Instantiate a new instance of Resource class and creates logging source.
 
override string ToString ()
 Overrides ToString() to return the Name of the resource. Can be overridden by derived classes to provider a more descriptive name. Note the overrider should include the Name in the output.
 
void OnActivity ()
 Triggers the ActivityStateChanged event.
 
- Public Member Functions inherited from OpenTap.ValidatingObject
void OnPropertyChanged (string propertyName)
 Triggers the PropertyChanged event. More...
 

Protected Member Functions

virtual void SetTerminationCharacter (int inst)
 Called by InstrumentBase.Open() before the newly opened connection is used for anything. Allows specializations of InstrumentBase to customize connection parameters such as TerminationCharacter.
 
virtual void DoClear ()
 Clears the device SCPI buffers.
 
virtual short DoReadSTB ()
 Reads the status byte. More...
 
virtual string QueryIdn ()
 *IDN / Queries the instrument for a IDN string.
 
virtual string QueryOpc ()
 *OPC / Operation Complete Query
 
virtual void CommandRst ()
 *RST / Reset Command
 
virtual void CommandCls ()
 *CLS / Clear Status Command
 
virtual string QueryErr (bool isSilent=false)
 SYST:ERR? / Queries the instrument for errors. This will normally be in a format like '123,"Error message"'.
 
- Protected Member Functions inherited from OpenTap.ValidatingObject
virtual string GetError (string propertyName=null)
 Return the error for a given property
 
void ThrowOnValidationError (bool ignoreDisabledProperties)
 Checks all validation rules on this object (Rules) and throws an AggregateException on errors. More...
 

Protected Attributes

readonly Dictionary< int, LogEventTypeScpiErrorsLogLevelOverrides = new Dictionary<int, LogEventType>()
 Specifies a dictionary that will map specific error codes to log levels other than Error (the level to which QueryErrors(bool, int) typically logs error messages).
 

Properties

string VisaAddress [getset]
 The VISA address of the instrument that this class represents a connection to.
 
int IoTimeout [getset]
 The timeout used by the underlying VISA driver when communicating with the instrument [ms].
 
bool FinegrainedLock [getset]
 If enabled ScpiInstrument acquires an exclusive lock when opening the instrument.
 
bool Lock [getset]
 If enabled ScpiInstrument acquires an exclusive lock when opening the instrument.
 
uint LockRetries [getset]
 Specifies how many times the SCPI instrument should retry an operation, if it was canceled by another host locking the device.
 
double LockHoldoff [getset]
 Specifies how long the SCPI instrument should wait before it retries an operation, if it was canceled by another host locking the device.
 
bool QueryErrorAfterCommand [getset]
 When enabled, causes the instrument driver to ask the instrument SYST:ERR? after every command. Useful when debugging.
 
bool SendClearOnConnect [getset]
 When true, Open will send VIClear() right after establishing a connection.
 
bool VerboseLoggingEnabled = true [getset]
 Gets or sets whether Verbose SCPI logging is enabled.
 
bool SendIDNOnConnect [getset]
 When true, will send *IDN? right after establishing a connection.
 
bool SendCLSOnConnect [getset]
 When true, will send *CLS right after establishing a connection.
 
string IdnString [get]
 Gets the instrument identity string. (As returned by the SCPI command *IDN?).
 
ScpiSRQDelegate SRQ
 This event is called whenever a SRQ is generated by the instrument. Adding a handler to this event will automatically enable SRQ transactions from the instrument when the instrument is opened/closed, or while the instrument is open. More...
 
- Properties inherited from OpenTap.Resource
TraceSource Log [get]
 Default log that the resource object can write to. Typically used by instances and extensions of the Resource object.
 
string Name [getset]
 A short name displayed in the user interface where space is limited.
 
bool IsConnected [getset]
 Indicates whether this resource is currently connected. This value should be set by Open() and Close().
 
- Properties inherited from OpenTap.ValidatingObject
ValidationRuleCollection Rules [get]
 All the validation rules. Add new rules to this in order to get runtime value validation.
 
string Error [get]
 Gets the error messages for each invalid rule and joins them with a newline.
 
- Properties inherited from OpenTap.IValidatingObject
ValidationRuleCollection Rules [get]
 A collection of all the currently defined validation rules. Add new rules here in order to get runtime value validation.
 
- Properties inherited from OpenTap.IResource
string Name [getset]
 A short name to display in the user interface in areas with limited space.
 
bool IsConnected [get]
 Indicates whether this DUT is currently connected. This value should be set by Open() and Close().
 
- Properties inherited from OpenTap.IScpiInstrument
IScpiIO IO [get]
 Get access to the low-level primitives of the connection.
 

Additional Inherited Members

- Events inherited from OpenTap.Resource
EventHandler< EventArgs > Activity
 Invoked on activity.
 
- Events inherited from OpenTap.ValidatingObject
PropertyChangedEventHandler PropertyChanged
 Standard PropertyChanged event object.
 
- Events inherited from OpenTap.INotifyActivity
EventHandler< EventArgs > Activity
 Invoked on activity.
 

Detailed Description

Implements a connection to talk to any SCPI-enabled instrument.

Constructor & Destructor Documentation

◆ ScpiInstrument()

OpenTap.ScpiInstrument.ScpiInstrument ( IScpiIO2  io)
inline

Initialize a new instance of ScpiInstrument, specifying a IScpiIO interface to use.

Parameters
ioAn IO Implementation for doing communication.

Member Function Documentation

◆ DoReadSTB()

virtual short OpenTap.ScpiInstrument.DoReadSTB ( )
inlineprotectedvirtual

Reads the status byte.

Returns

◆ PollStatusEvent()

bool OpenTap.ScpiInstrument.PollStatusEvent ( )
inline

Polls the instrument for an event.

Returns

Usually used for error handling.

◆ QueryErrors()

List< ScpiError > OpenTap.ScpiInstrument.QueryErrors ( bool  suppressLogMessages = false,
int  maxErrors = 1000 
)
inline

Returns all the errors on the instrument error stack. Clears the list in the same call.

Parameters
suppressLogMessagesif true the errors will not be logged.
maxErrorsThe max number of errors to retrieve. Useful if instrument generates errors faster than they can be read.
Returns

◆ ScpiCommand() [1/2]

virtual void OpenTap.ScpiInstrument.ScpiCommand ( string  command)
inlinevirtual

Sends a SCPI command to the instrument.

Parameters
commandThe command to send.

Non-blocking.

Implements OpenTap.IScpiInstrument.

◆ ScpiCommand() [2/2]

void OpenTap.ScpiInstrument.ScpiCommand ( string  command,
params object[]  parameters 
)
inline

Sends a SCPI command to the instrument, but with special handling for parameters. See Scpi.Format for more information.

Parameters
commandThe command to send, including Scpi.Format placement arguments.
parametersScpi.Format arguments.

Non-blocking.

◆ ScpiQuery()

virtual string OpenTap.ScpiInstrument.ScpiQuery ( string  query,
bool  isSilent = false 
)
inlinevirtual

Sends a SCPI query to the instrument and waits for a response.

Parameters
queryThe SCPI query to send.
isSilentTrue to suppress log messages.
Returns
The response from the instrument.

Implements OpenTap.IScpiInstrument.

◆ ScpiQuery&lt; T &gt;()

T OpenTap.ScpiInstrument.ScpiQuery< T > ( string  query,
bool  isSilent = false 
)
inline

As ScpiQuery except it will try to parse the returned string to T. See Scpi.Parse for details on parsing.

Template Parameters
T
Parameters
query
isSilentTrue to suppress log messages.
Returns

◆ ScpiQueryBlock()

byte[] OpenTap.ScpiInstrument.ScpiQueryBlock ( string  query)
inline

Sends a IEEE Block SCPI query to the instrument and waits for a response. The response is assumed to be IEEE block data.

Parameters
queryThe SCPI query to send.
Returns
The response from the instrument.

Implements OpenTap.IScpiInstrument.

◆ ScpiQueryBlock&lt; T &gt;()

virtual T[] OpenTap.ScpiInstrument.ScpiQueryBlock< T > ( string  query)
inlinevirtual

Sends a IEEE Block SCPI query to the instrument and waits for a response. The response is assumed to be IEEE block data.

Parameters
queryThe SCPI query to send.
Returns
The response from the instrument.

The format for data returned by the query must be configured to a type matching the type of T . Example 1:

ScpiCommand("FORMat:TRACe:DATA REAL,32", true);
var data = ScpiQueryBlock<float>(":TRACe:DATA? TRACE1");
void ScpiCommand(string command, params object[] parameters)
Sends a SCPI command to the instrument, but with special handling for parameters. See Scpi....
Definition: ScpiInstrument.cs:942

Example 2:

ScpiCommand("FORMat:TRACe:DATA REAL,64", true);
var data = ScpiQueryBlock<double>(":TRACe:DATA? TRACE1");
Type Constraints
T :struct 

◆ ScpiSRQDelegate()

delegate void OpenTap.ScpiInstrument.ScpiSRQDelegate ( ScpiInstrument  sender)

A delegate that is used by the SRQ event.

Parameters
senderA reference to the ScpiInstrument that the SRQ originated from.

◆ ToString()

override string OpenTap.ScpiInstrument.ToString ( )
inline

Overrides ToString() to give more meaningful names.

Returns

◆ WaitForOperationComplete()

void OpenTap.ScpiInstrument.WaitForOperationComplete ( int  timeoutMs = 2000)
inline

Waits for a all previously executed SCPI commands to complete.

Parameters
timeoutMsMaximum time to wait, default is 2 seconds. If value is less than IoTimeout, IoTimeout will be used.

Property Documentation

◆ SRQ

ScpiSRQDelegate OpenTap.ScpiInstrument.SRQ
addremove

This event is called whenever a SRQ is generated by the instrument. Adding a handler to this event will automatically enable SRQ transactions from the instrument when the instrument is opened/closed, or while the instrument is open.

To disable SRQ transactions all handlers added must be removed.

OpenTAP 9.27 API built Wed Nov 27 2024 13:14:46