From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending a pointer to TestStand current sequence to C#

Hi,
 
I am currently trying to perform various smaplings of current TestStand step from C# dll, called after the step.
Now in CVI is quite obvious and the fucntion looks like this :
 
void TX_TEST DLLEXPORT Get_Display_Step_Data_String(tTestData *data,tTestError *testError)
{
 TSObj_Step my_step;
 TSObj_SeqContext main_context;
 char *low_limit;
 low_limit=calloc(100,1);
//get the limit of the step
 tsErrChk(TS_PropertyGetValString(data->seqContextCVI, &errorInfo, "Parameters.Step.Limits.String",
                            0, &low_limit));
//now something more tricky - get a calling step's name
TS_SeqContextGetCallingStep (data->seqContextCVI, NULL, &my_step);
    //get the step's name
TS_StepGetProperty (my_step, NULL, TS_StepName, CAVT_CSTRING,&step_name_temp );
}
 
 
Now no metter how hard i tried, i just can't do it in C#.
It looks like i am unbale to obtain that tTestStand *data pointer.
Could anyone please give a clue about how to do it in C# (we are using Measurement Studio of course).
 
Thanks,
Serge
 
 
 
0 Kudos
Message 1 of 4
(3,379 Views)
Hey Serge,

I believe the main problem that you are having in C# is that you are expecting to use the tTestData structure within C# as in CVI.  Since C# is natively an object oriented language there is a different object you can pass into your function that acts like the tTestData structure.  I have included a sample piece of code below in C# that performs the same function as the code you posted.  If you have Measurement Studio with TestStand, I would highly recommend using the generate code option within TestStand to automatically create your Function prototypes for you.  Also if you are having trouble running this code, make sure to include the reference to the NationalInstruments.TestStand.Interop.API assembly.  Hope this helps!

public void myfunc(SequenceContext seqContext, out String reportText, out bool errorOccurred, out int errorCode, out String errorMsg)
        {
            reportText = String.Empty;
            errorOccurred = false;
            errorCode = 0;
            errorMsg = String.Empty;

            try
            {
                //Take the sequence context as a property object
                PropertyObject propertyObject = seqContext.AsPropertyObject();
                //Get the limit of the step
                String myLimit = propertyObject.GetValString("Parameters.Step.Limits.String", 0);
                //Get the calling step
                Step myStep = seqContext.CallingStep;
                //Display the step name
                MessageBox.Show(myStep.Name);
               
            }
            catch(COMException e)
            {
                errorOccurred = true;
                errorMsg = e.Message;
                errorCode = e.ErrorCode;
            }
        }

Pat P.
Software Engineer
National Instruments
Message 2 of 4
(3,361 Views)

Thanks Pat !

 It works fine for me - i am able to actually recode my whole old CVI application.

We have just recentky moved to V.S.+Measurement S. , so it still looks a bit tricky.

One more question - could you elaborate about the TS "automatic code generation" option ?

I have never actually heard of it .

 

Thank you very much,

Serge

0 Kudos
Message 3 of 4
(3,362 Views)
Hey Serge,

If you have Measurement Studio, within TestStand when you right click on a .NET step and go to the specify module window, there is a tab labeled source code.  From this tab you can specify your C# project and source files, and you can create a new method inside this project.  There is a create code button at the bottom of this tab that automatically generates some skeleton code for you inside that project.  One catch to this is that it currently does not work with Visual Studio 2005.  It will only work in Visual Studio 2003.  Let us know if there is anything else we can do to help!  Have a good one!
Pat P.
Software Engineer
National Instruments
0 Kudos
Message 4 of 4
(3,357 Views)