NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

.Net enums

Solved!
Go to solution

I have a .Net DLL that returns an enum status code.

Here is the defintion:

public enum eStatus
{
           OK = 0,
           Except = 1,
           IOError = 2,
}

How can I import the enum into Test Stand so that I don't have to recreate it in TestStand?

 

0 Kudos
Message 1 of 8
(4,773 Views)

mef526, 

 

This forum thread might help you get on the right track with using the enum data type in TestStand (not a native TestStand type). 

 

Thanks,

--
Peter Rifken - Field Engineer & Business Manager
Boston / North New England & Maine
0 Kudos
Message 2 of 8
(4,756 Views)

I looked at the thread you reccomended and it implies that there is no way to import an enum from .Net into TestStand.

The only solution is to recreate the enum as a container value in TestStand.

I am already doing that by using explicit integer values in the TestStand code.

I was hoping to avoid managing 2 sets of code with the same enum in each. 

 

 

0 Kudos
Message 3 of 8
(4,752 Views)

You can also specify an enum value by string which is a little less error prone since you don't have to ensure that you keep values up to date. The string will be converted into whatever the current value for the type is at runtime.

 

-Doug

0 Kudos
Message 4 of 8
(4,744 Views)

Right now I am using the interger values instead of the enum's names. If I use the names in TestStand then somehow the name's integer values are associated with them.

If I don't have to maintain the name / value association by duplicating the enum in TestStand then TestStand must be getting those integer values from the .Net code. If not, then how does TestStand use the enum's names?

What is the best way to accomplish this method (using the .Net enum names) in TestStand without having to recreate the enum in TestStand?

0 Kudos
Message 5 of 8
(4,738 Views)
Solution
Accepted by topic author mef526

TestStand gets the enum values via reflection at load time. They are not hardcoded anywhere. Thus if the values change in the assembly and you specify enum values by name, teststand will pick this up automatically when it reloads the assembly.

 

Regarding your question:


mef526 wrote:What is the best way to accomplish this method (using the .Net enum names) in TestStand without having to recreate the enum in TestStand?

It depends on what you are wanting to do. Please explain in more detail as I'm not sure what you are trying to do.

 

-Doug

0 Kudos
Message 6 of 8
(4,728 Views)

Thank you for your time in considering this issue.

 

In the .Net code:

       public enum eStatus
       {
           OK = 0,
           Except = 1,
           IOError = 2,
       }

       public eStatus GetErrorsAndClearQueue()
       {
           try
           {
               _SysErrs = GetErrorsAndClearQueue(_formattedIO488);
               return Instrument.eStatus.OK;
           }
           catch (Exception e)
           {
               _lastException = e;
               return Instrument.eStatus.Except;
           }
       }

I changed the TestStand step Settings for the function "GetErrorsAndClearQueue" to return a string, not an int and I got the proper value value back. As an int I get 0, as a string I get "OK". So it works as you said it would.

 

 

 

 

0 Kudos
Message 7 of 8
(4,714 Views)

Sounds good. Did you have any further questions reguarding this? Does this feature meet your requirements?

 

-Doug

0 Kudos
Message 8 of 8
(4,703 Views)