NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

TestStand interop threading conflic

Solved!
Go to solution

Ok, I'll detail my project first and then introduce my dilemma:-

 

I am creating a driver to control some environmental chambers (sort of like a small class driver). I need to be able to set parametres for this driver eg. temperature, max humidity alarm, dew point alarm etc.etc... Having "set it off", I want to continue executing whatever testing needs to be performed; there is no necessity for the driver to discuss anything more with TestStand, it knows what it needs to do and will get on with it. At some point in the sequence, I will likely access some properties in the class, so that I know what the temperature is or if the device has reported any errors etc.ect..

 

Problem:- For the class to continue to "supervise / control" it's device, it needs to be working in it's own thread. I have proven that this isn't the case, even though the data is persistent.

If I try and create my own thread to instantiate my class in:-

     
myClass = new myClass();

Thread myThread = newThread(new ThreadStart(myClass.myMethod()));

there apears to be some conflict with the threading in the interop api:-

 

Error    
 1 The type or namespace name 'ThreadStart' could not be found (are you missing a using directive or an assembly reference?)                  

Error
2 Cannot create an instance of the abstract class or interface 'NationalInstruments.TestStand.Interop.API.Thread'    

I have tried using system.threading and any combination I could think of but its never happy even pre-compile time.

 

I can't be the first person to want to do this, so my question is: How ? or, am I approaching this driver in the correct way ? Is there some other way of doing what I want to do ?

 

Many thanks

0 Kudos
Message 1 of 5
(3,459 Views)

I think you have a type name conflict. TestStand has a class named Thread and so does the .NET framework. You need to get rid of the "using" declaration for one or the other library and type the full scope of the class where you are using it. This is how things work in C# with two libraries with the same class name in different namespaces and is not TestStand specific.

 

Hope this helps,

-Doug

Message 2 of 5
(3,437 Views)

Thanks Doug,

 

Yes, this was the line of thought I was going down; there is no "using system.threading", I removed this early on to get rid of another array of errors. I have also tried being more explicit as you say:-

 

NationalInstruments.TestStand.Interop.API.

Thread myThread = new NationalInstruments.TestStand.Interop.API.Thread(new NationalInstruments.TestStand.Interop.API.ThreadStart(myClass.myMethod)));

 

Here are the errors:-

Error 1 The type or namespace name 'ThreadStart' does not exist in the namespace 'NationalInstruments.TestStand.Interop.API' (are you missing an assembly reference?)
Error 2 Cannot create an instance of the abstract class or interface 'NationalInstruments.TestStand.Interop.API.Thread'

 

I found this from the interop Api:-

   

// Summary:

//     Threads are elements of an Execution. Each thread maintains a call stack  

//     that contains a SequenceContext object for each active sequence invocation. 

//     You can obtain a thread of an execution by calling the Execution.GetThread

//     method.

 

Looking at the public interface, I can see that there are a number of thing you can do with your existing thread eg.

DisplayName, Resume etc.... but it's not clear of how to create a new one ? There is no Execution.GetThread.

 

0 Kudos
Message 3 of 5
(3,426 Views)
Solution
Accepted by topic author LizzardSB

@LizzardSB wrote:

Thanks Doug,

 

Yes, this was the line of thought I was going down; there is no "using system.threading", I removed this early on to get rid of another array of errors. I have also tried being more explicit as you say:-

 

NationalInstruments.TestStand.Interop.API.

Thread myThread = new NationalInstruments.TestStand.Interop.API.Thread(new NationalInstruments.TestStand.Interop.API.ThreadStart(myClass.myMethod)));

 

Here are the errors:-

Error 1 The type or namespace name 'ThreadStart' does not exist in the namespace 'NationalInstruments.TestStand.Interop.API' (are you missing an assembly reference?)
Error 2 Cannot create an instance of the abstract class or interface 'NationalInstruments.TestStand.Interop.API.Thread'

 

I found this from the interop Api:-

   

// Summary:

//     Threads are elements of an Execution. Each thread maintains a call stack  

//     that contains a SequenceContext object for each active sequence invocation. 

//     You can obtain a thread of an execution by calling the Execution.GetThread

//     method.

 

Looking at the public interface, I can see that there are a number of thing you can do with your existing thread eg.

DisplayName, Resume etc.... but it's not clear of how to create a new one ? There is no Execution.GetThread.

 


 

You are using the wrong class. You don't want the National Instruments version of the Thread class in this case, you want the .NET framework one. These are Microsoft APIs you are trying to use, not National Instruments ones. If you want to create a TestStand thread then you need to use completely different APIs.

 

Probably something more like the following in order to use Microsoft's APIs:

 

System.Threading.Thread myThread = new System.Threading.Thread(new System.Threading.ThreadStart(myClass.myMethod)));

 

-Doug

Message 4 of 5
(3,409 Views)

Thanks Doug,

 

I don't know why I didn't try that; what a doofus ! It (the compiler) has been appeased and is quiet for the time being. I can move on...

 

Many thanks

0 Kudos
Message 5 of 5
(3,404 Views)