10-04-2016 12:11 PM
If I have a calculation in the calculation manager that loops over all groups (using @@CCR@@), how do I get the calculation manager to ignore a certain group if the channel is already there?
10-05-2016 04:40 PM
Hi RussellSenior,
What channel's existence in the group are you looking to check for? Are you storing the results of the calculation in the group the calculation occurs on?
Thanks,
Kevin Flanagan
Applications Engineer
10-05-2016 04:43 PM
I want to look for the channel itself. So, if I have a calculation that results in the creation of "[1]/ExampleChannel", I want the calculation manager to check to see if "[1]/ExampleChannel" exists. If it DOES exist, I want the calculation manager to not overwrite the existing channel.
10-06-2016 12:43 PM
Hi Russell,
I think in order to apply custom logic like this, you'll need to switch to the Advanced tab of the Calculation Manager and write the looping and IF THEN statements yourself in the VBScript that the Calculation Manager will call for that calculation. I don't know of a feature you can invoke with the formula-based tab of the Calculation Manager to perform the channel exist check, reasonable though it is.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
10-06-2016 12:54 PM - edited 10-06-2016 12:56 PM
Thanks, I figured a validation script would be the perscription. 😛
Is there a programming reference for variables available to the validation script? I see CCR represents the current cycle. Is there another variable that represents the output channel?
Specifically Is there a way to dynamically specify the output channel in the validation script, or do I have to explicity check for the channel in each and every calculation. So, for example, if my output channel is "EngineSpeed", can my validation script do this:
If Data.Root.ChannelGroups(@@CCR@@).Channels.Exists(SOMEVARIABLE) then
Failed = "Chan exists"
End if
If SOMEVARIABLE can be dynamic, I can copy_paste my validation script. Or, is there someway to return the current calculation number, then I can just check the output name.
Thanks.
10-07-2016 09:40 AM - edited 10-07-2016 09:43 AM
Hi Russell,
Here's what I've learned playing around with this topic today. The Calculation Manager will always create the empty result channel (if the LED is green) prior to running the formula or script for that calculation. So checking if the channel exists doesn't help, but you CAN check for any channel properties. Here's an example of editing the shipping "Power" calculation so that it only executes if it has not already been run once (which is what I think you mean). The "CurrSymbols" variable is a 0-indexed array of the symbols in the equation, in this case {"M","n","P"}. The "CurrValues" variable is a 0-indexed array of channel objects associated with each symbol. Since the return symbol and channel are each in array index 2, you have to use CurrValues(2) in the IF THEN condition below:
IF NOT CurrValues(2).Properties.Exists("CalcDateTime") THEN Call Calculate("P = n * M",CurrSymbols,CurrValues,"Default") CurrValues(2).Properties.Add "CalcDateTime", Now END IF
I figured out the array index order by using the following lines before the Calculate command one at a time:
MsgBox CurrValues(0).Name
MsgBox CurrValues(1).Name
MsgBox CurrValues(2).Name
Brad Turpin
DIAdem Product Support Engineer
National Instruments
10-11-2016 01:15 PM
So, sometimes the data we get has certain channels, sometimes it doesn't. So, I wanted to be able to have the calculation manager check these for me, and not do a particular calculation. So, if I load some data and "Power" exists, then don't do the power calculation. It seems that this isn't easy, so I'll just overwrite the values, and let it be.