NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to assign a parameter with a call to a .Net method

I need to assign a parameter (of type Object Reference) with a call to a static .Net method.  For example, I wish to assign a parameter by calling TimeSpan.FromSeconds.

 

I asked a similar question previously and was directed to here.  However, I do not understand the answer there.

 

 

0 Kudos
Message 1 of 8
(2,494 Views)

 

Could you clarify which part of the forum post you didn't understand the answer to? It sounds like the "Object Reference" field needs to be blank for a static method.

The thread on Object References could also be a starting point to understanding the object references the other post mentions. I see that two other posters linked articles on the previous post "Cannot call.Net static method to specify parameter" - it could be helpful to ask them if you have a specific question about what they were linking.

Christine B
Technical Support Engineer
National Instruments
0 Kudos
Message 2 of 8
(2,463 Views)

I did not see the Create Object checkbox.  Not sure where that is.

0 Kudos
Message 3 of 8
(2,442 Views)

Hi TuscanDave, 

 

Could you clarify your question?

 

Are you wanting to call the Static Method TimeSpan.FromSeconds from TestStand and pass the TimeSpan result as an argument to the static method? You may be able to get an Object Reference to TimeSpan in TestStand, but I would pass the double to the static method and then call the TimeSpan.FromSeconds method from within the .NET method. That seems like the easier route. 

 

I also didn't see any posts by you in the thread you linked. 

 

Best,

 

David F.

Technical Support Engineer

National Instruments

www.ni.com/support 

0 Kudos
Message 4 of 8
(2,392 Views)

I want to call TimeSpan.FromSeconds and pass the result as a parameter to a non-static .Net method. 

 

You and others have mentioned an Object Reference.  I do not know what you refer to.  The other thread mentions a checkbox, but I do not know where that is.

 

While I own the code to the method I am calling, I do not wish to change its signature.  That would mostly defeat the purpose of the TimeSpan class.

0 Kudos
Message 5 of 8
(2,380 Views)

Hi TusconDave, 

 

Thank you for explaining. It makes sense that you don't wish to change the method.

 

I had to talk with some engineers in R&D on our TestStand team to figure this out. If you browse the GAC, you can call the TimeSpan.FromSeconds method from TestStand. You will need to know the assembly to target. We were able to target mscorlib, call FromSeconds, and use the return value in another .NET call. 

 

Best,

 

David F.

Technical Support Engineer

National Instruments

www.ni.com/support

Message 6 of 8
(2,371 Views)

Sorry, but I think I am missing something.

 

For example, let's say I wish to call Thread.Sleep, which takes a TimeSpan argument.  How do I specify that in the Value field for that parameter?  Put another way, how do I use the Expression Browser to call TimeSpan.FromSeconds?

 

The issue is more general than TimeSpan, static classes, etc.  The bigger question is how do I make method calls in the Value field of a parameter?

0 Kudos
Message 7 of 8
(2,360 Views)

Hi TuscanDave

 


The issue is more general than TimeSpan, static classes, etc.  The bigger question is how do I make method calls in the Value field of a parameter?


I now understand the thread's title. The short answer is that you can't if the method is static. You can still make the call, you will just need to build your arguments for the parameters in earlier steps.

 

It would be very nice to be able to call TimeSpan.FromSeconds from the Expression Browser, but I don't think you can given that the method is static. The fact that the method is static means that it is contained within the class's definition and not objects of that class. The issue is that you can't store a class definition in a variable. At least, I have never passed around a class definition before except with templates or with a makefile I suppose. However, you can call TimeSpan.FromSeconds() from an Action Step which will return an instance of the TimeSpan class and store that in a variable. Unfortunately, like I said above, you can't use this instance to call TimeSpan.FromSeconds() since FromSeconds is a static method. You can still pass that TimeSpan object into whatever function you want to call. 

 

Best,

 

David F.

Technical Support Engineer

National Instruments

www.ni.com/support

0 Kudos
Message 8 of 8
(2,348 Views)