From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-VISA .NET ReadStatusByte freezes program

Hi All,

We decided to rewrite our huge calibration program to NI-VISA .NET platform. Before start I created simple Project which has only one Counter (Keysight 53230A). We want to use ServiceRequest event of MessageBasedSession object.

We use below code for creating counter object.

 

counter = (MessageBasedSession)ResourceManager.GetLocalManager().Open("GPIB0::17::INSTR");
counter.Timeout = GpibInterface.InfiniteTimeout;
counter.ServiceRequest += Counter_ServiceRequest;
counter.EnableEvent(MessageBasedSessionEventType.ServiceRequest, EventMechanism.Handler);
//this starts new measurement and trigger SRQ when finish counter.Write("*CLS; *ESE 1; *SRE 32; INIT:IMM; *OPC");

 

 

When I run the program it reaches Service Request sub program and freezes at ReadStatusByte() line. If I omit this line, program reads data from counter and starts new measurements but ServiceRequest sub program does not call again.

 

private void Counter_ServiceRequest(object sender, MessageBasedSessionEventArgs e)
        {
            MessageBasedSession mb = sender as MessageBasedSession;
            if (mb != null)
            {
                //Program freezes this point
                //If omit this line, service request function does not run again 
                StatusByteFlags sb = mb.ReadStatusByte();   
                listBox1.Items.Add(mb.Query("FETCH?"));
                mb.Write("*CLS; INIT:IMM; *OPC"); //Restart measurement...

            }
        }

I tried AutoSerialPoll On or Off and results are same. I updated NI-VISA to 17.5 which is latest version.

 

 

Any idea?

 

Best regards,

 

Adem

0 Kudos
Message 1 of 8
(4,062 Views)

Ademg,

 

NI VISA is built off of the official VISA foundation's requirements. Do you know of any other method from another language that could be translated into NI VISA and applied?

 

Since Keysight manufactures this device, are we sure we are calling the right command?

Chase
NI Technical Support Engineer
0 Kudos
Message 2 of 8
(4,015 Views)

Hi,

Thank you for your reply.

The Project was written using some GPIB Activex components from old version of Measurement Studio. Now we have many different type of devices and many different interface like USB, Ethernet. Our aim is to create common way to control for all kind of interface. So NI VISA looks great for this.

The problem is not related to manufacturer. I tried some other device even other manufacturer and still same problem.

 

I compiled and run NI-VISA Examples\ServiceRequest Project and it freezes same line.

 

Best regards.

0 Kudos
Message 3 of 8
(4,011 Views)

Have you gotten to check this example?

 

<National Instruments>\NI-VISA\Examples\.NET Nonstandard\4.5.1\ServiceRequest\cs

 

I think this method may be easier to accomplish this

Chase
NI Technical Support Engineer
0 Kudos
Message 4 of 8
(3,986 Views)

It was my starting point....

0 Kudos
Message 5 of 8
(3,979 Views)

Update...

 

There is another example below directory which is same as my first example except written in C.

C:\Users\Public\Documents\National Instruments\NI-VISA\Examples\C\Gpib\AsyncSRQ

I compiled and run this code and viReadSTB() function works without any problem. In same file there is a very important note :

* With GPIB SRQ events, viReadSTB() must be called otherwise
* later SRQ events will not be detected.  

Since ReadStatusByte() function (equivalent to viReadSTB()) cannot call correctly, my first code does not capture next SRQ events.

 

Looks like there is a bug in VISA-NET. ???

0 Kudos
Message 6 of 8
(3,969 Views)

If you architect the code like this and initialize service request, does this work?

A022B66A.PNG

 

Chase
NI Technical Support Engineer
0 Kudos
Message 7 of 8
(3,934 Views)

Update...

Since it has very easy to use functions (like Query, FindResources etc...) I am trying to develop my application usign NI-VisaNS library. To do this I added NationalInstruments.Common and NationalInstruments.VisaNS dll to my project as a Reference. I guess that ReadStatusByte() function also makes some internal adjustment for accepting next events. I found another function DiscardEvent() and still I am not sure it is good way to do this but below code works as I expected.

private void Counter_ServiceRequest(object sender, MessageBasedSessionEventArgs e)
        {
            MessageBasedSession mb = sender as MessageBasedSession;
            if (mb != null)
            {
                 //StatusByteFlags sb = mb.ReadStatusByte();   
		mb.DiscardEvent(MessageBasedSessionEventType.ServiceRequest);
//After calling DiscardEvent(), ServiceRequest function can be retriggered on next event.??? listBox1.Items.Add(mb.Query("FETCH?")); mb.Write("*CLS; INIT:IMM; *OPC"); //Restart measurement... } }

 After reading some documents, I see that VisaNS may not support in future. There is a new standard from Interchangeable Virtual Instruments Foundation (Ivi) for that area and NI has developed NationalInstruments.Visa library which must be use together with Ivi.Visa library. I also write same program with using that references and works without any problem. So I have started to upgrade our project using this method.

 

0 Kudos
Message 8 of 8
(3,927 Views)