09-09-2025 03:56 PM
I have a small C# application to collect information from a user/operator and to post a status periodically. I have a TestStand application that is running multithreaded applications. How do I pass the information back and forth between TestStand and the C# winforms application? I would be happy to read TestStand variables/parameters with C# and write data to TestStand variables/parameters, all being unidirectional. Also, how do I invoke the C# application with TestStand? So far I have tried launching it as an STA Sequence thread but I can't seem to get the TestStand to acknowledge the code is there. I think it is looking for a sequence. I have also tried to use "Call Executable" which launches the application just fine but there is no place to specify which variables/parameters C# should have access to. Running in circles on this. I need to get started properly. Anyone ever done this?
09-09-2025 06:45 PM
Your code (dll) needs to be built with a reference to the NI API. After you add the reference, set the Embed Interop Types to No.
Put a using statement in.
using NationalInstruments.TestStand.Interop.API;
Once you do that, call your public method from the sequence that has a parameter where you pass the ThisContext. This gives you access to the Sequence Context, where you can use the NI API to access Locals, FileGlobals, etc.
09-10-2025 08:11 AM
Allow me to clarify a little... the C# is an application. I think I can get it to accept a parameter but what is the parameter type? Is it a string?
I have already added the reference, that was a no brainer. Now, how do I call this application? I have tried the call sequence step type (found literature that said this was the way to go) but had no luck. Then I tried the Call Executable step type and the application ran but left me short on the parameters part.
Then, which API method do I use to access parameters/variables and what would be an example syntax?
My goal is to collect a pile of information with C# then populate variables or parameters with the information. I really need some examples to get me going...
Thanks for the support and response!
09-10-2025 10:31 AM
public void DoSomething(SequenceContext seqContext)
{
double data = seqContext.Locals.GetValNumber("myLocalNumber", 0);
string stringData = seqContext.Parameters.GetValString("myStringPara", 0);
bool boolData = seqContext.FileGlobals.GetValBoolean("myBoolean", 0);
double stationData = seqContext.StationGlobals.GetValNumber("myStationData", 0);
double runTimeData = seqContext.RunState.GetValNumber("myRunTimeData", 0);
// process and/or update data
}
09-11-2025 10:09 AM
What I described depends on your application (exe) having a dll that TestStand can call into. This is the easiest way to do what you want. If you absolutely can't create a supporting DLL for your app, let me know and I can share another way where your exe uses the TestStand synchronization manager.
09-11-2025 11:01 AM
Thanks for all the help thus far. I have been able to read and write TestStand variables from C#. Until I get 2025Q3 TestStand I am stuck using the .NET Framework 4.8 and it doesn't seem to create a .dll. What I have had to do is to create a "forms launcher" to be able to pass the "ThisContext" to the form:
public void LaunchForm(SequenceContext mySeqContext)
{
Form UserInterface = new Form1();
UserInterface.Show();
myFormSeqContext = mySeqContext;
}
(I have defined static SequenceContext myFormSeqContext; elsewhere)
This could work as long as all of my methods I/O is done through the API. What I am saying is, any other method calls using the Action .NET adapter are returning the values from Form1() and not from UserInterface(). TestStand only recognizes Form1() for method calls when I really want UserInterface(), the launched Form1().
If you have a slick way around this I could use the tip, lol. I think I can live with this if I limit my application to being a front end to the TestStand and communicated through variables. My only real issue might be when exiting the application from TestStand. I can't invoke the Exit() method of the launched Form1().
Any thoughts? I really appreciate all the help. TestStand is new to me so I am stumbling through it a bit.