RMCLink.Interop .NET Assembly

RMCLink.IsConnected Method

Checks to see if the link is currently connected to a controller.

Syntax

Visual Basic (Declaration)

Public Function IsConnected ( _

   ping As PingType, _

) As Boolean

 

Visual Basic (Usage)

Dim instance As RMCLink

Dim ping As PingType

Dim returnValue As Boolean

 

returnValue = instance.IsConnected(ping)

 

C#

public bool IsConnected (

   PingType ping

)

 

Visual C++/CLI

public:

bool IsConnected (

   PingType ping

)

Parameters

ping

This parameter determines if the link should try sending a test communication with the controller before deciding whether the connection is still established. Specify PingType.Ping to do the test communication, and PingType.DoNotPing to determine if the connection is established based on the last communication attempt. This parameter is ignored if the connection is known to be closed.

Return Value

Return true (True in Visual Basic) if the connection is established (after a ping is sent out if ping is set to PingType.Ping). Otherwise, returns false (False in Visual Basic).

Remarks

This method is synchronous, which means that it will not return until the method is completed. If ping is PingType.DoNotPing, then it will return immediately. If ping is PingType.Ping, then it may take several seconds to complete. 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.

Exceptions

Exception Type

Condition

ArgumentOutOfRangeException

The ping parameter is set to neither PingType.Ping nor PingType.DoNotPing.

Example

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

Visual Basic

Imports RMCLinkNET
 
Module Example
    Sub Main()
        ' Create the object itself.
        Console.Write("Creating RMCLink...")
        Dim rmc As RMCLink = RMCLink.CreateEthernetLink(DeviceType.RMC70, "192.168.0.10")
        Console.WriteLine("Done")
 
        ' Check to see if we are connected. This will return 'false' because
        ' the connection is not established until Connect() is called. Notice
        ' that the ping parameter could be either value.
        Console.WriteLine("Connected? " & rmc.IsConnected(PingType.DoNotPing))
 
        ' Connect to the controller.
        Console.Write("Connecting to the controller...")
        rmc.Connect()
        Console.WriteLine("Done")
 
        ' Check to see if we are connected. This should return 'true'.
        Console.WriteLine("Connected? " & rmc.IsConnected(PingType.DoNotPing))
 
        ' Prompt the user to physically break the connection.
        Console.WriteLine()
        Console.WriteLine("Power off the controller and press <ENTER>.")
        Console.ReadLine()
 
        ' Check to see if we are connected. If the user has powered off the
        ' controller, then you might expect this to return 'false', however
        ' since no communication has been done with the controller since it
        ' was powered off, the RMCLink does not know that the connection is
        ' broken, and since we used PingType.DoNotPing, IsConnected does not
        ' check before returning.
        Console.WriteLine("Connected (do not ping first)? " & rmc.IsConnected(PingType.DoNotPing))
 
        ' Check to see if we are connected. This time we will try a test
        ' communication before blindly deciding that the connection is still
        ' established. It should return 'false'.
        Console.WriteLine("Connected (ping first)? " & rmc.IsConnected(PingType.Ping))
 
        ' 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.
            Console.Write("Creating RMCLink...");
            RMCLink rmc = RMCLink.CreateEthernetLink(DeviceType.RMC70, "192.168.0.10");
            Console.WriteLine("Done");
 
            // Check to see if we are connected. This will return 'false' because
            // the connection is not established until Connect() is called. Notice
            // that the ping parameter could be either value.
            Console.WriteLine("Connected? " +
                rmc.IsConnected(PingType.DoNotPing));
 
            // Connect to the controller.
            Console.Write("Connecting to the controller...");
            rmc.Connect();
            Console.WriteLine("Done");
 
            // Check to see if we are connected. This should return 'true'.
            Console.WriteLine("Connected? " +
                rmc.IsConnected(PingType.DoNotPing));
 
            // Prompt the user to physically break the connection.
            Console.WriteLine();
            Console.WriteLine("Power off the controller and press <ENTER>.");
            Console.ReadLine();
 
            // Check to see if we are connected. If the user has powered off the
            // controller, then you might expect this to return 'false', however
            // since no communication has been done with the controller since it
            // was powered off, the RMCLink does not know that the connection is
            // broken, and since we used PingType.DoNotPing, IsConnected does not
            // check before returning.
            Console.WriteLine("Connected (do not ping first)? " +
                rmc.IsConnected(PingType.DoNotPing));
 
            // Check to see if we are connected. This time we will try a test
            // communication before blindly deciding that the connection is still
            // established. It should return 'false'.
            Console.WriteLine("Connected (ping first)? " +
                rmc.IsConnected(PingType.Ping));
 
            // Disconnect from the controller.
            rmc.Disconnect();
        }
    }
}

 

Visual C++/CLI

using namespace System;
using namespace RMCLinkNET;
 
int main()
{
    // Create the object itself.
    Console::Write("Creating RMCLink...");
    RMCLink^ rmc = RMCLink::CreateEthernetLink(DeviceType::RMC70, "192.168.0.10");
    Console::WriteLine("Done");
 
    // Check to see if we are connected. This will return 'false' because
    // the connection is not established until Connect() is called. Notice
    // that the ping parameter could be either value.
    Console::WriteLine("Connected? " +
        rmc->IsConnected(PingType::DoNotPing));
 
    // Connect to the controller.
    Console::Write("Connecting to the controller...");
    rmc->Connect();
    Console::WriteLine("Done");
 
    // Check to see if we are connected. This should return 'true'.
    Console::WriteLine("Connected? " +
        rmc->IsConnected(PingType::DoNotPing));
 
    // Prompt the user to physically break the connection.
    Console::WriteLine();
    Console::WriteLine("Power off the controller and press <ENTER>.");
    Console::ReadLine();
 
    // Check to see if we are connected. If the user has powered off the
    // controller, then you might expect this to return 'false', however
    // since no communication has been done with the controller since it
    // was powered off, the RMCLink does not know that the connection is
    // broken, and since we used PingType::DoNotPing, IsConnected does not
    // check before returning.
    Console::WriteLine("Connected (do not ping first)? " +
        rmc->IsConnected(PingType::DoNotPing));
 
    // Check to see if we are connected. This time we will try a test
    // communication before blindly deciding that the connection is still
    // established. It should return 'false'.
    Console::WriteLine("Connected (ping first)? " +
        rmc->IsConnected(PingType::Ping));
 
    // 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