RMCLink.Interop .NET Assembly

RMCLink.Connect Method

Establishes a connection with a controller using the settings specified when the RMCLink object was created (device type, port name, host name).

Syntax

Visual Basic (Declaration)

Public Sub Connect

 

Visual Basic (Usage)

Dim instance As RMCLink

 

instance.Connect()

 

C#

public void Connect ()

 

Visual C++/CLI

public:

void Connect ()

Remarks

This method is synchronous, which means that it will not return until the connection has been established, or the connection attempt fails and an exception is thrown, which may take several seconds to take place. If this method is called on the main thread, then the application will likely be unresponsive until this method completes. For applications where this is not acceptable, this and other synchronous methods should be called from a worker thread, and may use the CancelRequest method to cancel an in progress request.

WARNING: For Ethernet connections, it is highly recommended that the connection not be disconnected and re-connected between transactions. Doing so will have lower performance, and more importantly, each call to Connect() will consume a TCP connection in the Windows operating system. This TCP connection will not be fully released by the operating system until typically 2 minutes after Disconnect() is called. Therefore, it is possible to consume all available TCP connections by repeated calls to Connect()/Disconnect() and as a result be unable to re-connect over RMCLink or even adversely affect other applications running on the same PC.

Exceptions

Exception Type

Condition

CancelledException

This connection attempt was cancelled by a call on another thread to Disconnect or CancelRequest.

ConnectionNotMadeException

The link could not establish a connection. The exception's Message property will give a brief description of why. Check that the remote device is powered up, check the communication wiring, and check the communication configuration of both the local and remote devices.

InvalidOperationException

This link was already connected. Notice that the link will still be connected after this exception is thrown.

Example

The following code example illustrates the use of the Connect method.

Visual Basic

Imports RMCLinkNET
 
Module Example
    Sub Main()
        ' Create the object itself.
        Dim rmc As RMCLink = RMCLink.CreateSerialLink(DeviceType.RMC70, "COM1")
 
        ' Connect to the controller.
        rmc.Connect()
 
        ' Read and display Axis 0's Actual Position (F8:8).
        Dim data() As Single = New Single(0) {}
        rmc.ReadFFile(FileNumber70.fn70StatusAxis0,8,data,0,1)
        Console.WriteLine("Axis0 Actual Position = " & data(0) & " inches")
 
        ' Disconnect from the controller.
        rmc.Disconnect()
    End Sub
End Module

 

C#

using System;
using RMCLinkNET;
 
namespace Example
{
    public class Program
    {
        static void Main()
        {
            // Create the object itself.
            RMCLink rmc = RMCLink.CreateSerialLink(DeviceType.RMC70, "COM1");
 
            // Connect to the controller.
            rmc.Connect();
 
            // Read and display Axis 0's Actual Position.
            float[] data = new float[1];
            rmc.ReadFFile(FileNumber70.fn70StatusAxis0,8,data,0,1);
            Console.WriteLine("Axis0 Actual Position = " + data[0] + " inches");
 
            // Disconnect from the controller.
            rmc.Disconnect();
        }
    }
}

 

Visual C++/CLI

using namespace System;
using namespace RMCLinkNET;
 
int main()
{
    // Create the object itself.
    RMCLink^ rmc = RMCLink::CreateSerialLink(DeviceType::RMC70, "COM1");
 
    // Connect to the controller.
    rmc->Connect();
 
    // Read and display Axis 0's Actual Position.
    array<float>^ data = gcnew array<float>(1);
    rmc->ReadFFile(FileNumber70::fn70StatusAxis0,8,data,0,1);
    Console::WriteLine("Axis0 Actual Position = " + data[0] + " inches");
 
    // Disconnect from the controller.
    rmc->Disconnect();
 
    return 0;
}

 

See Also

RMCLink.Interop .NET Assembly | RMCLinkNET Namespace | RMCLink Class


Send comments on this topic.

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