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: 

How do I change the GPIB timeout using c#

Hello,

I'm trying to use C# to control my GPIB equipment.  As long as I use the default timeout, i can read/write/query with no problems.  Today I wanted to try to change the timeout so I tried the following command:



mbSession = (MessageBasedSession)ResourceManager.GetLocalManager().Open(visaAlias, AccessModes.NoLock, 10000);

 

int originalVisaTimeout = mbSession.Timeout;

int newVisaTimeout = 120000;

 

mbSession.Timeout = newVisaTimeout; // this does not work and changes to either 3000, 180000, or 300000 depending on the values i've tried for the timeout so far

mbSession.Timeout = originalVisaTimeout // this correctly sets the timeout back ot the origianl value.

 

Am I using the wrong Timeout property to set the GPIB Timeout? The documentation shows the following information.

//
// Summary:
// Gets or sets the minimum timeout value to use in milliseconds when accessing
// the device associated with the session.
//
// Exceptions:
// NationalInstruments.VisaNS.VisaException:
// The property is set to an invalid state.
//
// System.ObjectDisposedException:
// This member is called after the Dispose method is called directly from code
// or indirectly through a finalizer.
//
// System.DllNotFoundException:
// The NI-VISA driver library cannot be found.
//
// System.EntryPointNotFoundException:
// A required operation in the NI-VISA driver library cannot be found.
public int Timeout { get; set; }

 

Thanks,
Frank

 

0 Kudos
Message 1 of 9
(6,219 Views)

I would just use the largest timeout value I would need.

 

Does the code work if you start the session using 12 seconds instead of trying to change it from 10 seconds to 12 seconds?

 

 

0 Kudos
Message 2 of 9
(6,210 Views)

By default, the session starts with 3 seconds.  I can get the session to use a high timeout so that it works, but i'd still have it set the timeout to the value I define.  I'm thinking it is possibl that this timeout is not the correct property to set.  By the way, that first line of code whic has the acquire, well, there is that 10000 that is passed in.  That 10000 does not define the GPIB timeout but rather a timeout to acquire the conection.  So basically, I want to change the timeout as a property that I'm passing in from a configuration file (code not shown for that), but no matter what, the mbsession.Timeout does not equal the value I choose unless I choose 3000, 180000, or 300000.  For other values I've tried, as an example, 100000, the setting is rounded to 180000 for some reason.  This just makes me think I'm doing it incorrectly.  I'd rather it be working as expected rather than just working.

0 Kudos
Message 3 of 9
(6,207 Views)

@fgperry_wms wrote:

By default, the session starts with 3 seconds.  I can get the session to use a high timeout so that it works, but i'd still have it set the timeout to the value I define.  I'm thinking it is possibl that this timeout is not the correct property to set.  By the way, that first line of code whic has the acquire, well, there is that 10000 that is passed in.  That 10000 does not define the GPIB timeout but rather a timeout to acquire the conection.  So basically, I want to change the timeout as a property that I'm passing in from a configuration file (code not shown for that), but no matter what, the mbsession.Timeout does not equal the value I choose unless I choose 3000, 180000, or 300000.  For other values I've tried, as an example, 100000, the setting is rounded to 180000 for some reason.  This just makes me think I'm doing it incorrectly.  I'd rather it be working as expected rather than just working.


I am at a different PC, but you need to do something like mbSession.SetAttributeInt32( , ) 

 

http://zone.ni.com/reference/en-XX/help/370627F-01/mstudiowebhelp/html/ed6dead2/

0 Kudos
Message 4 of 9
(6,203 Views)

I couldn't figure out how to do anything with what you mentioned, but here is the weirdness of the valueToSetTimeoutTo vs valueActual.  I'm not sure what the deal is with 1s and 3s, but they seem to be the trigger point for a new timeout.

Attempt Actual
3000000 1000000
600000 1000000
500000 1000000
400000 1000000
350000 1000000
300001 1000000
300000 300000
180000 300000
100001 300000
100000 100000
30001 100000
30000 30000
10001 30000
10000 10000
0 Kudos
Message 5 of 9
(6,082 Views)

@fgperry_wms wrote:

I couldn't figure out how to do anything with what you mentioned, but here is the weirdness of the valueToSetTimeoutTo vs valueActual.  I'm not sure what the deal is with 1s and 3s, but they seem to be the trigger point for a new timeout.

Attempt Actual
3000000 1000000
600000 1000000
500000 1000000
400000 1000000
350000 1000000
300001 1000000
300000 300000
180000 300000
100001 300000
100000 100000
30001 100000
30000 30000
10001 30000
10000 10000

All of that is pointless.

If you are not understanding what to do, then you are just running in circles.

0 Kudos
Message 6 of 9
(6,078 Views)

Well, as it turns out, the behavior is the correct behavior.  Go figure.  Opening NI Max and trying to adjust the timeout, you have 17 options (a subset is shown below):

Disabled

10 usec

30 usec

100 usec

300 usec

...

...

100 sec

300 sec

1000 sec

 

Problem Solved. 

 

0 Kudos
Message 7 of 9
(6,049 Views)

@fgperry_wms wrote:

Well, as it turns out, the behavior is the correct behavior.  Go figure.  Opening NI Max and trying to adjust the timeout, you have 17 options (a subset is shown below):

Disabled

10 usec

30 usec

100 usec

300 usec

...

...

100 sec

300 sec

1000 sec

 

Problem Solved. 

 


I was certainly able to set a timeout to 9000 (9 seconds) for a network analyzer data read.

 

 

0 Kudos
Message 8 of 9
(6,041 Views)

It is possible that i'm looking at the wrong property.  But if you open NI Max, go to the properties tag, and open the dropdown menu for I/O Timeout, you can see what i"m talking about.  Did you verify that it was set to 9 seconds by reading the timeout after you set it?

0 Kudos
Message 9 of 9
(6,037 Views)