ni.com is currently undergoing scheduled maintenance.
Some services may be unavailable at this time. Please contact us for help or try again later.
03-18-2010 12:04 AM
Hi All,
I have an Analog In channel inside a task that I have set up in MAX. It has an associated scale.
The Max/Min signal input ranges are set up to be +/-30 degC. The scale I have set up is a Linear scale with a Slope of 1, and obviously I have its Scaled units titled "degC"
I load up the task and access the channel like this:
AcqTask = DaqSystem.Local.LoadTask(taskName); AcqTask.Control(TaskAction.Verify);
The task is correctly loaded, so now I want to retrieve the Minimum and Maximum for the first channel
AIChannel thisChannel = AcqTask.AIChannels[channelNumber]; double min = thisChannel.Minimum;
The my double 'min' ends up becomming -100. I figured this didnt make any sense so I put a watch on the variable AcqTask.AIChannels[0].Minimum and it always says -100. It should be -30.
So I used the Local's debug viewer and found my variable thisChannel and scrolled down to minimum, and it says -30!!!
If i put a breakpoint on the line where I access the Minimum, then I go and view the minimum inside the channel and then let it run the my variable 'min' ends up being -30,as it should be!
Any ideas on what in the world could be going on?
It feels like the task isnt verified or something.
The help no the .Minimum property says "When you query this property, it returns the coerced minimum value that the device can measure with the current settings", but I dont really know what the coerced minimum values is.
I am using VS2008 with Measurement Studio 8.6.
Thanks
- Justin
03-18-2010 06:12 PM
bump...
Just tried the same thing with Measurement Studio Q4 2009. It only happens incorrectly on some channels...
03-18-2010 07:45 PM
I have sort or solved my own problem here, but the solution is a bit rediculous.
I worked out that one of the properties I was viewing inside my AIChannel class must have been triggering an internal refresh of some variables and hence having the Max/Min recalculated correctly.
So I wanted to work out which property this was. I used reflection in C# to extract all the public properties from AIChannel, and then went through and read each one and watched for when the minimum value changed to what it should be.
System.Reflection.PropertyInfo[] propInf; propInf = typeof(AIChannel).GetProperties(); foreach (System.Reflection.PropertyInfo prop in propInf) { if (prop.CanRead) { try { prop.GetValue(thisChannel, null); } catch (Exception) { } } double minTest = thisChannel.Minimum; /* Watch for the my minimum becomes -30, like it should be, when it does we know which property did it */ if (minTest == -30) { string thePropertyOfLove = prop.Name; } }
It makes no sense to me, but the property AIChannel.CalibrationDescription is actually refreshing the values in my AIChannel object 'thisChannel'
Who would have guess
So now if I go
AIChannel thisChannel = AcqTask.AIChannels[channelNumber]; double min = thisChannel.Minimum;
Then my minimum is incorrectly returned as -100
But if I try
AIChannel thisChannel = AcqTask.AIChannels[channelNumber]; string blah = thisChannel.CalibrationDescription; double min = thisChannel.Minimum;
Then my minimum is CORRECTLY returned as -30.
If any of you NI guru's have any clue on this behaviour, I'd be very happy to hear about it.
Obviously something in the getter of the CalibrationDescription property is doing something special.