01-06-2016 11:55 AM
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
01-06-2016 12:41 PM
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?
01-06-2016 04:45 PM
Yes I'm getting an exception that is thrown as given under
"Timeout expired before operation completed. VISA error code -1073807339 (0xBFFF0015), ErrorTimeout"
01-06-2016 05:02 PM - edited 01-06-2016 05:21 PM
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
01-06-2016 05:53 PM
One thing you should note is that TerminationCharacter is for read *only*.
You will need to add your own when writing to the instrument.
01-07-2016 11:11 AM
Ok I checked for NI-VISA examples and only found C & VB6 code.
01-07-2016 11:21 AM
@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.
01-07-2016 11:45 AM
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.
01-07-2016 11:58 AM
@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.
01-07-2016 12:16 PM - edited 01-07-2016 12:16 PM
I am indeed sending the termination character. You check the code I posted above.
_gpibSession.TerminationCharacter = 10; _gpibSession.TerminationCharacterEnabled = true;