Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Using ServiceRequests with .Net

Hello,

 

I am trying to run timed sweeps with an DAQ970A connected via Ethernet using C#. I've included the following libraries:

C:\Program Files (x86)\IVI Foundation\VISA\Microsoft.NET\Framework32\v2.0.50727\VISA.NET Shared Components 5.11.0\Ivi.Visa.dll

C:\Program Files (x86)\IVI Foundation\VISA\Microsoft.NET\Framework32\v4.0.30319\NI VISA.NET 19.0\NationalInstruments.Visa.dll

 

According to my understanding, the best approach would be using Events from an activated ServiceRequest. However, I cannot get it to work. This is my code (for testing I've connected it to an USB port as I cannot disable the firewall on my dev laptop):

using Ivi.Visa;
using NationalInstruments.Visa;

MessageBasedSession _session;

private void SessionOnServiceRequest(object sender, VisaEventArgs e)
{
	StatusByteFlags sb = _session.ReadStatusByte();
	Console.WriteLine(sb);
}
void main()
{
	_session = new UsbSession("USB0::0x2A8D::0x5001::MY58002830::INSTR", AccessModes.None, 1000);
	_session.FormattedIO.WriteLine("*RST");
	_session.FormattedIO.WriteLine("*CLS");
	_session.FormattedIO.WriteLine("SYSTem:REMote");	
	_session.FormattedIO.WriteLine("CONF:RES 1E6,DEF, (@101:140)");
	_session.FormattedIO.WriteLine("FORM:READ:CHAN ON");
	_session.FormattedIO.WriteLine("FORM:READ:TIME OFF");
	_session.FormattedIO.WriteLine("FORM:READ:UNIT OFF");
	_session.FormattedIO.WriteLine("TRIG:SOUR TIMER");
	_session.FormattedIO.WriteLine("TRIG:COUN INF");
	_session.FormattedIO.WriteLine("TRIG:TIM 30");
	_session.FormattedIO.WriteLine("ROUT:SCAN (@101:140)");
	_session.ServiceRequest += SessionOnServiceRequest;
	_session.FormattedIO.WriteLine("*SRE 16");
	_session.FormattedIO.WriteLine("*SRE?");
	var resp = _session.FormattedIO.ReadLine().Trim();
	//In Debugger, resp contains "+16"
	_session.FormattedIO.WriteLine("INIT");
	//endless loop here waiting for user to abort
}

 

The event is fired two times, the first time sb is set to RequestingService, the second time it is set to 0. That both occurs before the INIT command. However, after that the event is never fired again even after multiple sweeps.

 

Am I missing something here?

 

Best regards

Manuel

0 Kudos
Message 1 of 2
(1,928 Views)

After some testing with the Status-Subsystem it does not seem to be a VISA Problem but rather a Keysight issue. I've managed to get the event to fire by subscribing to changes in the Standard Operation Register (STAT:OPER:ENAB 48, *SRE 128) and then checking the Condition and Event registers:

StatusByteFlags sb = _session.ReadStatusByte();
if (sb.HasFlag(StatusByteFlags.User7))
{
	_session.FormattedIO.WriteLine("STAT:OPER:COND?");
    var cond = _session.FormattedIO.ReadInt64();
    _session.FormattedIO.WriteLine("STAT:OPER:EVEN?");
    var evnt = _session.FormattedIO.ReadInt64();
	if (cond == 48 && (evnt & 32) > 0)
    {
        //Data available here
	}
}

 

However, I cannot use any data retrieval functions (Read?, Fetc?) when the data is generated by a timed trigger (this is independent from the event and does not work with other tools either) as this will block the command queue and stops all communication until manually reset on the front panel. This might also explain why the MessageAvailable Request never fires.

I can read the data directly from the result buffer with the DATA-Functions, which is not nice but works:

_session.FormattedIO.WriteLine("DATA:POIN?");
var p = _session.FormattedIO.ReadInt64();
_session.FormattedIO.WriteLine($"DATA:REM? {p}");
var data = _session.FormattedIO.ReadLineListOfDouble();
0 Kudos
Message 2 of 2
(1,901 Views)