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.
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.
02-20-2018 01:53 PM
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
02-21-2018 12:41 PM
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?
02-21-2018 02:34 PM
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.
02-22-2018 01:44 PM
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
02-22-2018 11:26 PM
It was my starting point....
02-23-2018 06:22 AM - edited 02-23-2018 06:24 AM
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. ???
02-26-2018 09:41 AM
If you architect the code like this and initialize service request, does this work?
02-27-2018 12:34 AM
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.