RMCLink C++ Wrapper Class CRMCLink::Connect Method |
Establishes a connection with a controller using the settings specified when the CRMCLink object was created (device type, port name, host name).
C++ |
HRESULT Connect(); |
Returns S_OK on success. Otherwise, an error code is returned. Possible error codes are listed below.
This method is synchronous, which means that it will not return until the connection has been established, or the connection attempt fails, 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.
Member Name |
Description |
E_OUTOFMEMORY |
Out of memory. |
RMCLINK_E_ALREADY_CONN |
The link was already connected. To avoid this error, avoid calling Connect when the link is already connected. Use IsConnected if you are not sure if the connection is already made. |
RMCLINK_E_SOCK_INTERNAL |
Internal socket error. |
RMCLINK_E_SOCK_CONN_FAIL |
Unable to connect over TCP/IP to requested device. |
RMCLINK_E_CANCELLED |
Operation cancelled by call to CancelRequest. |
RMCLINK_E_TIMEOUT |
Operation timed out. |
RMCLINK_E_SOCK_HOSTNAME_NOTIP |
Host name did not resolve to an IPv4 address. |
RMCLINK_E_SOCK_HOSTNAME_FAIL |
Host name did not resolve. |
RMCLINK_E_SOCK_GRACEFUL_CLOSE |
TCP/IP connection closed by remote device. |
RMCLINK_E_SOCK_ERROR_RD |
Connection error while waiting for response from the remote device. |
RMCLINK_E_SOCK_INV_RD_LEN |
Connection error while waiting for response from the remote device. |
RMCLINK_E_SOCK_ERROR_WR |
Connection error while sending request to the remote device. |
RMCLINK_E_SOCK_INV_WR_LEN |
Connection error while sending request to the remote device. |
RMCLINK_E_PORT_ACCESS_DENIED |
Access to serial port denied. Verify not in use by another application. |
RMCLINK_E_PORT_NOT_FOUND |
Serial port not found. |
RMCLINK_E_CE_IOE |
Serial IOE error. |
RMCLINK_E_CE_FRAME |
Serial framing error. |
RMCLINK_E_CE_BREAK |
Serial Break error. |
RMCLINK_E_CE_OVERRUN |
Serial overrun. |
RMCLINK_E_CE_RXOVER |
Serial receive overrun. |
RMCLINK_E_CE_RXPARITY |
Serial parity error. |
RMCLINK_E_CE_TXFULL |
Serial transmitter full. |
RMCLINK_E_CONN_BROKEN |
Connection broken. |
RMCLINK_E_PARTIAL_WRITE |
Unable to send full request to the remote device. |
RMCLINK_E_SOCK_HOSTNAME_INV |
Invalid host name format. |
RMCLINK_E_WRONG_CONTROLLER |
Remote device is the wrong controller type. |
RMCLINK_E_USB_NO_DRIVERS |
Unable to access RMC USB driver. Please ensure that the driver has been properly installed. |
RMCLINK_E_USB_DEV_NOT_FOUND |
The controller with the specified DeviceId was not found on any USB port. |
RMCLINK_E_USB_SETTIMEOUT |
Internal USB driver error. |
RMCLINK_E_USB_TXRXCLEAR |
Internal USB driver error. |
RMCLINK_E_USB_OP_ABORT |
Unsuccessful transfer of data between the PC and the controller. Ensure that the physical connection between the PC and controller is still intact. |
RMCLINK_E_USB_DISCONNECT |
The controller appears to have been disconnected from the USB port. Ensure that the physical connection between the PC and controller is still intact. |
RMCLINK_E_USB_UNK_FAILURE |
The requested RMC is plugged into a USB port, but cannot be accessed. Ensure that no other applications are using this RMC. If the problem persists, try unplugging and re-plugging the USB cable to this controller and retry. |
RMCLINK_E_USB_IN_USE |
The requested RMC is plugged into a USB port, but cannot be accessed. Ensure that no other applications are using this RMC. If the problem persists, try unplugging and re-plugging the USB cable to this controller and retry. |
RMCLINK_E_USB_NO_SETUPAPI |
Unable to access operating system functionality for connecting to USB devices. |
The following code example illustrates the use of the Connect 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) )
{
// Read F8:8 and F8:9 (Axis 0 Actual Position and Velocity)
float afData[2];
hr = pRMC->ReadFFile(CRMCLink::fn70StatusAxis0, 8, 2, afData);
if ( SUCCEEDED(hr) )
{
printf("Actual Position = %.3f, Actual Velocity = %.3f\n",
afData[0], afData[1]);
}
// Close the connection.
pRMC->Disconnect();
}
// Free the RMCLink object we created.
delete pRMC;
}
// Release the COM sub-system.
::CoUninitialize();
}
|
See Also
CRMCLink Class | RMCLink C++ Wrapper Class
Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion