RMCLink Component

How to: Use from Visual C++/CLI

C++/CLI is a variant of the C++ programming language created by Microsoft in 2005 to provide interoperability with other .NET languages such as C# and Visual Basic .NET. It is not recommended for use in standalone applications, and as such we do not provide a walkthrough or complete example.

C++/CLI programmers should use the RMCLink.Interop .NET Assembly instead of using the RMCLink COM Component directly. Specifics on using this component from Visual C++/CLI are described below.

Adding a Reference to the RMCLink.Interop .NET Assembly

Before referencing types in the RMCLinkNET namespace, you must add a reference to the RMCLink.Interop .NET assembly.

To add this reference:

  1. Open your project in Visual C++ 2005 or later.

  2. On the Project menu, click [Project] Properties. This opens the project Property Pages dialog box. However, because of a Visual C++ bug, this dialog box will sometimes show up empty. If this happens, try re-opening the property page.

  3. Under Common Properties, select Framework and References (References in Visual C++ 2005).

  4. Click Add New Reference.

  5. Select the Browse tab.

  6. Browse to the RMCLink.Interop.dll file. It is located in your RMCLink install folder, which is C:\Program Files\RMCLink by default.

  7. Click Open.

  8. The RMCLink.Interop assembly appears in the References list.

  9. Click OK.

You can now browse the RMCLinkNET namespace using the Object Browser:

  1. On the View menu, click Object Browser.

  2. You should see the RMCLink.Interop assembly and be able to browse all the types included in it.

  3. Close the Object Browser when you are done.

Using the RMCLinkNET Namespace

All types in the RMCLink.Interop assembly are contained within the namespace RMCLinkNET. When any .NET type is referenced in the program, the compiler must know which namespace(s) to look in. Notice that adding a reference to the assembly does not make the compiler look in its namespace by default. In C++/CLI, use one of the following to specify the namespace.

First, you can qualify each type located in the RMCLinkNET namespace by prefixing them with the RMCLinkNET:: as shown below.

RMCLinkNET::RMCLink^ rmc = RMCLinkNET::RMCLink::CreateEthernetLink(RMCLinkNET::DeviceType::RMC70, "192.168.0.10");

However, most .NET programmers prefer the using namespace statement, as shown below.

using namespace RMCLinkNET;

...

RMCLink^ rmc = RMCLink::CreateEthernetLink(DeviceType::RMC70, "192.168.0.10");

The using namespace statement tells the compiler to always check the given namespace when resolving a type, and eliminates the need to specify the namespace on every type reference.

Creating an RMCLink Object

The first step is to create an instance of the RMCLink class. Use one of the static CreateEthernetLink, CreateSerialLink or CreateUSBLink methods to create the instance; because there is no public constructor, the new keyword cannot be used. The following line demonstrates how this is done in Visual C++/CLI:

using namespace RMCLinkNET;

  ...

RMCLink^ rmc = RMCLink::CreateEthernetLink(DeviceType::RMC70, "192.168.0.10");

Notice that this line will only compile correctly if the reference to the RMCLink.Interop assembly has been added to the project as described above.

Lifetime of the RMCLink Object

Notice that although most Visual C++ samples in this documentation control the entire lifetime of the RMCLink object within a single function, this is often not the most efficient way of using the RMCLink control. Generally, when you first want to connect to a controller, you will create the RMCLink object and call its Connect method. This RMCLink object should be located outside of the function or subroutine that creates and connects it, so that it can be used by other functions and subroutines to read or write from it.

 

See Also

RMCLink.Interop .NET Assembly | How Do I Overview | RMCLink Component


Send comments on this topic.

Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion