RMCLink C++ Wrapper Class

CRMCLink::IsConnected Method

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

Syntax

C++

bool IsConnected(

   bool 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 true to do the test communication, or false 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

Returns true if the connection is established (after a ping is sent out if ping is set to true). Otherwise, returns false.

Remarks

This method is synchronous, which means that it will not return until the method is completed. If ping is false, then it will return immediately. If ping is true, 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.

Example

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

C++

#include <windows.h>
#include <stdio.h>
#include "RMCLink.h"
 
void main()
{
    // In order to create COM objects, we must initialize the COM sub-system.
    ::CoInitialize(0);
 
    // Create a new RMCLink object.
    CRMCLink* pRMC = CRMCLink::CreateEthernetLink(CRMCLink::dtRMC70, _T("192.168.0.22"));
    if ( pRMC != NULL )
    {
        // Establish the connection.
        HRESULT hr = pRMC->Connect();
        if ( SUCCEEDED(hr) )
        {
            // Do some long task...
 
            // Check to see if the link is still connected.
            if ( pRMC->IsConnected(true) )
            {
                printf("Connection is still made.\n");
 
                // Use the connection...
 
                // Close the connection.
                pRMC->Disconnect();
            }
            else
            {
                printf("Connection has been broken.\n");
            }
        }
 
        // Free the RMCLink object we created.
        delete pRMC;
    }
 
    // Release the COM sub-system.
    ::CoUninitialize();
}

 

See Also

CRMCLink Class | RMCLink C++ Wrapper Class


Send comments on this topic.

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