NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Using CSharp daqmx code with TestStand?

I have a bunch of code using .Net libraries (not LabView) for NI Daqmx. How can I use this code with TestStand (esp hooking up the library function calls)?
0 Kudos
Message 1 of 8
(4,017 Views)
Hi,
 
In Teststand there is the .Net Adapter that allows you to calling .Net Assemlies in TestStand.
If you are new to TestStand please refer the "Reference Manual" and take a look into chapter 5.
 
 
And of course there a lot of examples shipped with TestStand and on this web site
I recommed the demo/dotNet/computer.seq.  The computer.seq is let me say the "Hello World" application in TestStand
 
Hope this helps
 
Juergen
 
 
 
--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 2 of 8
(4,005 Views)

I have a fully developed C# program with many classes. It uses several threads. I have created a new class to hold TestStand compliant functions depending upon type (Action, NumLimit, etc.). My main program uses many double arrays in the test class to store data. I haven't been able to hook up TestStand to this class. I created StationGlobal variables of the ref type and can set them to my test arrays on start. When I run a sequence however the StationGlobal references become null. I ended up putting a custom container class in TestStand to hold test arrays.

The second problem is hooking up my hardware class that references DAQmx libraries from CSharp. Will references to these functions cause a problem when run from within TestStand? Can I use the existing reference to my hardware class or do I need to create a separate instance in TestStand by using my class constructor. My board will only allow one reference at a time.

This is just a exploratory program to see how involved it will be to incorporate TestStand into our existing programs. 

0 Kudos
Message 3 of 8
(3,988 Views)

Hi,

In this there is an access to TestStand arrays.
http://forums.ni.com/ni/board/message?board.id=330&message.id=17787&query.id=56418#M17787

By the way i know thats not what your are looking for. You are searching the other way round.
Makeing the arrays accessible to Teststand.

Can you please post a small example of your code. Constructor and maybe 2 public Members with dummy stuff in enough
(source code in VS8 would be great). So I can and ohter members here can take a look into it.

For your second problem: Reference Storage can be done. Take a look in upper exsample.

Greetings

juergen

 

  

 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 4 of 8
(3,980 Views)

Some code snippets

//This is in the main csharp code (_Load)
//set StationGlobals for TestStand
TS.API.PropertyObject obj3 = axApplicationMgr.GetEngine().Globals;
//These are all StationGlobal 'ref' types
//TF is an instance of a class in my program
//MainForm is the CSharp form class
obj3.SetValVariant("TF", 0, CTF);
obj3.SetValVariant("ApplicationManager", 0, this.axApplicationMgr);
obj3.SetValVariant("MainForm", 0, MainForm1);

//at  this point I can access all members of these instances like this
TestFunctions TF = (TestFunctions) obj3.GetValVariant("TF", 0);
MainForm MF = (MainForm) obj3.GetValVariant("MainForm", 0);

//the sequence file is loaded in the main module
Sequence += TestSuite.Substring(0, TestSuite.Length - 4) + ".seq";
//load test stand sequence
TS.API.SequenceFile sf = axApplicationMgr.OpenSequenceFile(Sequence);
//reload limits
TS.API.Step step = axSequenceFileViewMgr.Sequence.GetStep(2, TS.API.StepGroups.StepGroup_Main);
//MessageBox.Show(step.StepType.Name);
TS.API.PropertyObject obj = step.AsPropertyObject();
obj.SetValNumber("Limits.Low", 0, 0);
limit += 1.0;
obj.SetValNumber("Limits.High", 0, 2000);

//at  this point I can still access all members of these instances like this
TestFunctions TF = (TestFunctions) obj3.GetValVariant("TF", 0);
MainForm MF = (MainForm) obj3.GetValVariant("MainForm", 0);

 

 


//code the sequence calls defined by Specify Module - Action step
//this code is in a separate class
public void CollectSimulatedData(SequenceContext seqContext, out String reportText, out bool errorOccurred, out int errorCode, out String errorMsg)
{
 reportText = "CollectSimulatedData";
 errorOccurred = false;
 errorCode = 0;
 errorMsg = String.Empty;

 try
 {
  //connect to the current TestStand app
  TS.API.PropertyObject obj3 = seqContext.StationGlobals;
  axApplicationMgr = (NationalInstruments.TestStand.Interop.UI.Ax.AxApplicationMgr) obj3.GetValVariant("ApplicationManager", 0);
  //create objects from station references
  TestFunctions TF = (TestFunctions) obj3.GetValVariant("TF", 0);
  MainForm frm = (MainForm) obj3.GetValVariant("MainForm", 0);

  //this results in a null value for TF
 }
 catch
 {
 }
}

It appears that user defined classes need to be defined in TestStand as CustomContainers.
We can discuss hardware later.

0 Kudos
Message 5 of 8
(3,969 Views)

Hi ,

I have rewritten my Example LocalLoader and and played with Excel Application reference.
Now there are 2 classes.

Class LocalLoader creates an Excel Application and stores the reference in a "Locals.hExcel" all this is done in the constructor
There is only one public member it gets the Excel reference and creates a xls on disk.

Class LocalLoaderExtern only gets only the SequenceContext ( in LocalLoader,too) in constructor.
The member get the Excel Handle from Variable and read the xls file.

In your code i saw you are using StationGlobals. I do not recommend this because the variables are stored on disk.
But when TS is running they are on File and on Memory, too and when Execution is over they do strange thinks. At the moment have not used to them for "dynamic" data.
I used them only for Machine initialisation stuff like path reading.
There are lot of good answers out in this forum, escpecially from Ray Farmer.
http://forums.ni.com/ni/board/message?board.id=330&thread.id=18389

So let's hope that Ray Farmer will read this thread and give us some advice

Greetings

juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 6 of 8
(3,947 Views)
For all that are following this thread I have some updates. Remember I defined my main form and my user class in TestStand as ref StationGlobals. I was finally able to get an instance of a class to persist during a TestStand sequence. I had to use CommitGlobalsToDisk (engine) but in order for this to work I had to make my class Serializable. I didn't have to add the ISerialize interface functions though. I can now use all the members of my user class without adding them as CustomTypes (container). I didn't have this problem with my main form. I was able to access members from the start. It must have something to do with writing to the StationGlobals file. By the way, TestStand doesn't actually save my class data to the file it apparently just holds the reference. Thanks for everyone's help.
0 Kudos
Message 7 of 8
(3,922 Views)

Hello,

 

I'am the new about the c# developing using NI daq.

 

I'm trying to get the data using several daq.

 

However, there are errors when I connect several daq...

 

How can I get multi data using c#?

 

Can I get a sample code?

 

Thanks

0 Kudos
Message 8 of 8
(1,132 Views)