Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WaitOnEvent Timing out

Hi All

 

Trying to set SRQ for power meter (HP437B) via USB GPIB  VISA and waiting for event to return.

When the same thing is done in VB6 it works.

Under given is the code snippet in C# 2010

 

_gpibSession = null;
_gpibSession = (MessageBasedSession)ResourceManager.GetLocalManager().Open(_resourceName, AccessModes.NoLock, timeOutValue);

_gpibSession.SynchronizeCallbacks = true;
_gpibSession.Timeout = 60000;
_gpibSession.DefaultBufferSize = 65536000;

_gpibSession.TerminationCharacter = 10;
_gpibSession.TerminationCharacterEnabled = true;

_gpibSession.Write("*SRE 64");
_gpibSession.EnableEvent(_mbSrq, EventMechanism.Queue);
_gpibSession.Write("PR");		//preset
_gpibSession.WaitOnEvent(_mbSrq, 6000);          //timing out at this point

StatusByteFlags sbfStatus = _gpibSession.ReadStatusByte(); if ((sbfStatus & StatusByteFlags.RequestingService) != 0) { MessageBox("Request Service in the status register is set."); } else if ((sbfStatus & StatusByteFlags.MessageAvailable) != 0) { MessageBox("MAV in the status register is set."); } else if ((sbfStatus & StatusByteFlags.EventStatusRegister) != 0) { MessageBox("ESB in the status register is set."); string esrValue = _gpibSession.Query("*ESR?"); //get content of event status register }

Any help in resolving this issue is appreciated.

 

Thank you

 

0 Kudos
Message 1 of 15
(5,402 Views)

According to the documentation, WaitOnEvent method will throw an exception after the timeout you in put in.

 

Are you getting an exception that is thrown?

0 Kudos
Message 2 of 15
(5,397 Views)

Yes I'm getting an exception that is thrown as given under

"Timeout expired before operation completed.  VISA error code -1073807339 (0xBFFF0015), ErrorTimeout"  

 

0 Kudos
Message 3 of 15
(5,386 Views)

Where did you get this code snippet?

 

NI has very good examples on Servest Request written in .NET 4.0 and .NET 4.5

You basically register the handler for the event.

 

Look in C:\Users\Public\Public Documents\National Instruments\NI-VISA\Examples

0 Kudos
Message 4 of 15
(5,382 Views)

One thing you should note is that TerminationCharacter is for read *only*.

You will need to add your own when writing to the instrument.

0 Kudos
Message 5 of 15
(5,374 Views)

Ok I checked for NI-VISA examples and only found C & VB6 code.

 

0 Kudos
Message 6 of 15
(5,353 Views)

@master9991 wrote:

Ok I checked for NI-VISA examples and only found C & VB6 code.

 


Then you need to re-install NI-VISA.

 

 

 

I highly suggest appending NewLine to your VISA write.

0 Kudos
Message 7 of 15
(5,348 Views)

Already did the re-install and have the new line when ever a write is done.

 

Can you send me online link to the NI-VISA .NET examples.

 

0 Kudos
Message 8 of 15
(5,343 Views)

@master9991 wrote:

Already did the re-install and have the new line when ever a write is done.

 

Can you send me online link to the NI-VISA .NET examples.

 


There aren't online examples that I know of.

 

When installing you may want to do a custom install. It is suppose to detect that you have VB.NET installed, but you never know...

 

Let me repeat yet again. You may be timing out because your VISA write is not complete and your instrument is waiting for your termination character.

0 Kudos
Message 9 of 15
(5,340 Views)

I am indeed sending the termination character. You check the code I posted above.

 

 

_gpibSession.TerminationCharacter = 10;
_gpibSession.TerminationCharacterEnabled = true;
0 Kudos
Message 10 of 15
(5,336 Views)