Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Example Program
NI Supported: Yes
Publish Date: Jun 10, 2009


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

Sharing .NET Objects Between TestStand and LabVIEW using .NET Remoting

3 ratings | 5.00 out of 5
Print

Overview

The following Example Program demonstrates how to share/pass a .NET Object between TestStand and its code modules VIs written in LabVIEW.

Downloads

Filename: dotnet_remoting2.zip
Requirements: View

Challenge:
The challenge is that we cannot simply pass the reference of a typical .NET Object that we create in TestStand to a LabVIEW VI and access it from the VI.
This is because of a technology called Application Domains or AppDomains.
Objects exist in an AppDomain, and AppDomains protect the object from being manipulated from outside programs. So a .NET Object created in TestStand is part of TestStand's AppDomain, and as such, LabVIEW (being in its own AppDomain) cannot access the object.
The following is a good source of information on AppDomains:
Wikipedia: Application Domain

Solution:
The solution to this problem is another technology called .NET Remoting.
.NET Remoting is an API that allows for inter-process communication. Using .NET Remoting, we can share a .NET Object across different AppDomains, processes or even computers.
The way this works is that a reference to the shared or 'Remote' Object is made available to client applications through a .NET Remoting Server which registers and hosts the actual object.
In this way, both TestStand and LabVIEW VIs can access the same Remote Object by getting a reference to it.
The following is a good source of information on .NET Remoting:
Wikipedia: .NET Remoting
MSDN: .NET Remoting Overview

Example Program:
The Example Program contains

  • .NET Interface (DNRemotingInterface): An interface for the shared object. Also contains a static function to get a reference to the Remote Object.
  • .NET Remoting Server (DNRemotingServer): The server that registers and hosts the remote object. Also contains the definition of the Remote Object's class.
  • TestStand Sequence (TestStandSequence.seq): Creates a .NET Object and shares it with LabVIEW through .NET Remoting.
  • LabVIEW VI (SetSerialInLabVIEW.vi): Two versions of this file exists, one for LabVIEW 7.1.1 and another for LabVIEW 8.0 and higher.

In order to run the example, follow these steps:

  1. The .NET Assemblies must be registered in the GAC (Global Assembly Cache) so that TestStand and LabVIEW can find them.
    To do this, run the attached batch file: RegisterAssemblies.bat
  2. Select the right version of the LabVIEW VI:
    If you are using LabVIEW 7.1.1, rename SetSerialInLabVIEW71.vi to SetSerialInLabVIEW.vi
    If you are using LabVIEW 8.0 or higher rename SetSerialInLabVIEW80.vi to SetSerialInLabVIEW.vi (This is done by default)
  3. Open TestStand and load TestStandSequence.seq
  4. Run the TestStand Sequence

The TestStand Sequence will:

  1. Launch the .NET Remoting Server. This will also create the shared or 'Remote' Object
  2. Call the static function to get a reference to the Remote Object
  3. Use the reference to call a method on the Remote Object
  4. Call a LabVIEW VI that also gets a reference to the Remote Object and calls a method on it.
  5. Call a method on the Remote Object directly without the reference through Remote Call

This demonstrates both how to share an object between TestStand and LabVIEW and also two different ways of accessing this Remote Object in TestStand.

 

Requirements


Filename: dotnet_remoting2.zip

Software Requirements


Application Software: LabVIEW Professional Development System 7.1.1, NI TestStand Development System 3.1
Language(s): C#, Visual Studio .NET, LabVIEW
Additional Software: Visual Studio .NET 2005

 
3 ratings | 5.00 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This example program (this "program") was developed by a National Instruments ("NI") Applications Engineer. Although technical support of this program may be made available by National Instruments, this program may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this program with each new revision of related products and drivers. THIS EXAMPLE PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).