NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Updating Locals in TestStand from C#

Hi,

 

I want to update a variable in TestStand from C#.

I have problems with synchronization, after updating the variable in C# and reading back the variable, it seems to work in Visual Studio.

But the variable is not updated in the GUI of TestStand, only if the test is stopped in TestStand, de variable gets updated.

I have changed TestStandDialog example to show this behavior, attached TestStandDialog1.

If the demo sequence is executed in TestStand, all tests will fail, if the execution is stopped then the local variable strTextBox gets updated!

If you step through the code in Visual Studio it seems to be that it is possible to set a variable and to read back, but the TestStand GUI is not updated.

 

 string strVarNameTextBox = "Locals.strTextBox";

// Update the TestStand variable 'Locals.strTextBox'

m_propertyObject.SetValString(strVarNameTextBox, 0, strTest);

// Readback the content of TestStand variable 'Locals.strTextBox'

 string strContentVariable = m_propertyObject.GetValString(strVarNameTextBox, 0);

// Check the value of the TestStand variable

 if (strContentVariable != strTest)

{

MessageBox.Show("Problem detected");

}

 

Does someone now what the reason is for this behavior?

 

Best regards

0 Kudos
Message 1 of 19
(5,872 Views)

Hi,

 

Would save the Demo.seq as TS4.0

Have to time to upgrade

 

Juergen

 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 2 of 19
(5,872 Views)

Are you setting the runtime copy of the variables or the edit time? The runtime copy are the ones located in the sequence context under Runstate.Locals or Locals. The edit time copy would be under RunState.SequenceFile.Data.Seq["sequencename"].Locals.

 

If you make an edit to the edit time version of the file you need to increment the change count on the file (i.e. call IncChangeCount() on the SequenceFile).

 

Also if you just want to force a refresh of the GUI in the sequence editor (you are probably updating the value, just not refreshing the UI), you can use the following API:

 

If you are editing the edit time copy of the locals (NOTE: you should be incrementing the change count even if you do this refreshing):

 

RunState.Engine.PostUIMessage(RunState.Execution, RunState.Thread, UIMsg_RefreshWindows, 0, "", mysequencefile, true)

 

Please see the online help documentation for the  UIMessageCodes enumeration for more details about the UIMsg_RefreshWindows ui message and for a link to an example.

 

Hope this helps,

-Doug

Message 3 of 19
(5,860 Views)

Hi Doug,

 

I am setting the runtime copy of the variables.

If I understand you correctly, there is no additonal action needed for the runtime locals, but my sequence still fails?

 

I want to change locals from C#, what do you recommend, do I have to use the runtime copy or the edit time copy of the locals?

 

public class DialogMaster : IDisposable

{

# region private Membervariablen

private PropertyObject m_propertyObject = null;

#endregion

 

# region public Constructor public DialogMaster(NationalInstruments.TestStand.Interop.API.SequenceContext sequenceContext)

{

m_propertyObject = sequenceContext.AsPropertyObject();

}

#endregion

# region
public Members public void Test(string strTest, out bool errorOccurred, out int errorCode, out String errorMsg)

{

errorOccurred =
false;

errorCode = 0;

errorMsg = String.Empty;

try

{

string strVarNameTextBox = "Locals.strTextBox";

// Update the TestStand variable 'Locals.strTextBox'

m_propertyObject.SetValString(strVarNameTextBox, 0, strTest);

// Readback the content of TestStand variable 'Locals.strTextBox'

 string strContentVariable = m_propertyObject.GetValString(strVarNameTextBox, 0);

// Check the value of the TestStand variable

 if (strContentVariable != strTest)

{

MessageBox.Show("Problem detected");

}

}

catch (COMException e)

{

errorOccurred =
true;

errorMsg = e.Message;

errorCode = e.ErrorCode;

}

}

#endregion

#region
IDisposable Members public void Dispose()

{

}

#endregion

}

Best regards

0 Kudos
Message 4 of 19
(5,846 Views)

Hi,

 

If you want to beable to load the sequence file with values from a previous run then you have to change the static copy and save the file, as Doug outlined.

 

Regards

Ray

Regards
Ray Farmer
0 Kudos
Message 5 of 19
(5,841 Views)

Because teststand is multithreaded and more than one version of a sequence could be running in parallel, each version of a sequence that's running has its own "runtime" copy of the sequence and locals. If you modify a runtime copy, you are only changing the version for that run of the sequence. If, instead, you want to actually make an edit to the file (the original version from which runtime copies are created) then you need to edit the version of the locals under RunState.SequenceFile.Data.Seq["SeqName"].Locals as I explained earlier, though that won't effect already running runtime copies. If you just want to change the runtime copy, that version of the variables only shows the changes in the variables view of the execution and those changes are temporary and only effect the currently running copy. The variables view of the execution is only shown and updated on trace events and when at a break point. It should be refreshed automatically when either of those occurs. What exactly are you trying to do? Do you want to edit the actual sequence file, or just the runtime version of the variables?

 

That said, I see a potential problem with your code below. You should generally avoid holding onto the sequence context between method calls like you are doing. The reason is that a sequence context is only valid for the life of a particular run of a sequence. To avoid issues with incorrectly accessing a sequence context that is no longer being used or even potentially accessing the wrong sequence context, you are better off passing in the sequence context to each method in which you need it and using it only for the lifetime of the call. I'm not saying you can't hold onto it if you are careful about it, it's just more likely to lead to problems if you don't fully understand how it's used. If you are only holding onto it for the life of one run of a sequence and all your calls are from that same sequence it's ok, but you need to make sure that that's the only way you use it.

 

Hope this helps,

-Doug

0 Kudos
Message 6 of 19
(5,826 Views)

I want to make a sequence with TestStand using custom step types. By executing the step stypes I want to directly updating the variables in TestStand. So, I do not want to use output parameters from the function call to update the variables. Because I want to update the variables directly I need a method to do this. Using the method listed above, the variables are not updated in the TestStand. I suppose using this method I have updated the runtime version of the variables, is this correct?

If not, could you point me in the right direction, how to update the RunTime variables using C#.

 

Best regards

0 Kudos
Message 7 of 19
(5,811 Views)

Are you running your code module by running a sequence or is it being run as the edit substep of a step type? An edit substep is not run as part of an execution so there is no runtime copy in that case. When an edit substep is run the sequence context properties Step, Sequence, Locals etc, actually point to the edit time copies, when a step is run as part of an execution though, these point to the runtime copies.

 

I think you are still misunderstanding the difference between edit time and runtime copies of sequences/variables.

 

1) The runtime copies only exist temporarily for the  current run of the sequence. It seems like updating these in your situation does not make sense if what you want is to update the variables that get persisted when the user saves the file. If what you want to update is just the values for the current run then this is the correct place to update them, but they will only apply to the current run and not subsequent runs. Subsequent runs of the sequence will get their initial values from the edit time version of the sequence.

 

2) The edit time version of sequences are the version that is actually saved in the file, and the version from which the runtime copies are made. If you want to make actual edits to the file that get persisted and apply to all future runs, these are the ones you need to change.

 

Since I still do not full understand what you are trying to do, I can't for certain tell you which one it is you want. What do you mean by "executing the step types"? Step types are not normally executed, they are like a class definition for steps. Steps are created as instances of a step type. Additionally step types define special substep code modules that do get called in certain situations as I've described previously, but I do not think that's what you mean. Also how are you determining that the variables are not updated in teststand? Are you looking at the varibales view in the execution window? The variables view in the sequence file window? Or are you determining this based on the results of running your sequence?

 

-Doug

0 Kudos
Message 8 of 19
(5,804 Views)

I will try to explain in more detail.

 

Currently we have an in house written sequencer and a lot of devicedrivers for different devices. Each devicedriver  is a software component (.net assembly) with a graphical user interface to configure a device. For example for a DMM we have a GUI to configure the DMM, all settings are stored in a descriptive string. Another GUI to take a measurement, in fact here we select a variable defined in our sequencer that will contain the measurement, again this setting is stored into a descriptive string. De descriptive strings are stored by our sequencer in an XML file. By executing such steps in our sequencer, first the configuration string will be taken from the XML file and is given back to the devicedriver. The devicedriver interpretes this string and creates executable commands (Ex. GPIB commands). Finally the device driver sents this commands to the device to configure the DMM. By executing the next step to take the measurement, a measurement is made and stored into the selected variable. In our case updating the variable in the sequencer is done by means of an event mechanism.

 

Now, the whole idea is to use Teststand as sequencer instead of our in house written one. So, I want to reuse all my already written device drivers.

-I have define in TestStand a string local variable, let say 'Measurement'.

-I have create a StepType to instantiate my device driver for the DMM. So I have added a step using an instance of my Steptype and in the substep edit I am able to view the GUI of the DMM. So after making the correct settings for the DMM (Ex. configuring for DC Voltage), the settings string is build and this string is given back to TestStand, so far so good.

-Next I have added a step to take the measurement, in the subset edit I have selected the Teststand local variable 'Measurement'. The sequence context is given as argument to this function, so I was able to stuff my combobox with all TestStand variables.

-Finally I have added a test step in Teststand to verify that my measurement is between the limits.

 

Now, if I run this sequence in Teststand, my sequence fails because Teststand does not see that I have updated the local variable 'Measurement' after executing the step that takes the measurement.

 

I hope that I have made the question clear.

Looking forward for your respons

 

Best regards.

 

Pccds 

  

 

0 Kudos
Message 9 of 19
(5,798 Views)

Hi,

 

This a complete other suggestion for your task!

I am bad in using the keyboard, so i will keep it short !  

 

You have a Xml-File  right! What about automatic sequncefile generation?

The are two ways.

 

1.) Use the TS - API in our own generator.exe (see attachment) to ... 

2.) Write a TS-Sequence (programmfolder/National Instruments\TestStand 4.0\Examples\SequenceBuilderTool)

       and let it execute to ...

  

 ... create your Teststand SequenceFiles.

 

juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 10 of 19
(5,798 Views)