Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read state cache for an attribute when not in simulation mode

Is there an easy way to read the cached value of an attribute?

I can create a state machine and use an additional attribute that is read by the read callback to determine whether the value should be read from the instrument or cache. The SetAttribute functions allow an option for set the cache without writing to the instrument but this option is not available for the ReadAttribute functions.

Thanks.
0 Kudos
Message 1 of 3
(3,033 Views)
The purpose of the read callback is to read data from the instrument. Typically, if you are inside the read callback, you've already determined that you want to read from the instrument.

The read callback gets called when the attribute's cache is marked as invalid. So one solution is for you to modify your application to call Ivi_InvalidAttribute on the attribute when you are in the state where you want to read from the instrument (instead of implementing this logic *in* the read callback).

If this doesn't work, here's something else you can try:
  1. Add an attribute to your driver that is marked as IVI_VAL_ALWAYS_CACHE and doesn;t have any read/write callbacks. Essentially, its a session-based global variable. e.g. if your attribute is called IVI_ATTR_
    VOLTAGE, call this attribute IVI_ATTR_VOLTAGE_CACHE.
  2. In the attirbute's write callback, make sure you set IVI_ATTR_VOLTAGE_CACHE to the same value as that of IVI_ATTR_VOLTAGE.
  3. In the attribute's read callback, return the value of IVI_ATTR_VOLTAGE_CACHE when you want to return the cache value.

Basically, you're using IVI_ATTR_VOLTAGE_CACHE as a session based variable to store the cache value and return it when needed. Keep in mind that this requires you to make sure the values of both attirbutes are always synchronized.
0 Kudos
Message 2 of 3
(3,033 Views)
Hi,

I had the same troubles and I did not find any solution, how easy solve this problem.

I made hidden attribute, which does not have any callback and flag always cache. In write callabck of the public attribute I'm setting this attribute to same value. If I need data from cahce I query hidden attribute. This implementation is possible for driver where you have this mechanism for couple attributes(2-3).

Next solution is better design, where you will not need query chache value. I agree thet it's not solution for all drivers, but I'm preferring this way in my drivers.

Zdenek
0 Kudos
Message 3 of 3
(3,033 Views)