Establishing a connection

<< Click to Display Table of Contents >>

Navigation:  NmxDLL Reference Guide > HowTo >

Establishing a connection

A connection is established using NMX_DeviceIPv4Open_1. All required connection parameters are assigned via its function parameters. No additional configuration file or similar is required.

Before establishing a connection, a connection handle must be declared.

Establishing a connection can last a few hundred milliseconds, since the Windows IP stack may need to determine device-specific network data (e.g. MAC address).

 

Please note: if a firewall is active, the connection must be allowed by this firewall. With common firewalls, e.g. Windows Firewall, the user is asked one-time, if the connection shall be allowed. This has to be answered with "Yes".

 

In the following examples, the connection is established to the IP address 192.168.3.99. The port numbers 22517 and 22516 are fixed.
It is strongly recommended to store all these parameters in an INI-File, XML-File, in the Registry or something similar.

 

C / C++


// Global definition

NMX_PHANDLE pHandle = NULL;

 

// Establish the connection.

NMX_STATUS tStatus = NMX_DeviceIPv4Open_1(192, 168, 3, 99, 22517, 22516, &pHandle);

if (tStatus == NST_SUCCESS) {

 // Connection has been established successfully.

 // Do some further initialization here, e.g. register notifications.

}

else {

 // Failed establishing the connection. Show an error message.

}

 

 

Delphi


// Global definition

pNmxHandle : NMX_PHANDLE;

 

// Example: Establish connection within a button event handler.

procedure TMainForm.btnConnectClick(Sender: TObject);

var

   tNmxStat : NMX_STATUS;

begin

   tNmxStat := NMX_DeviceIPv4Open_1(192, 168, 3, 99, 22517, 22516, pNmxHandle);

   if (tNmxStat = NST_SUCCESS) then begin

      // Connection has been established successfully.

      // Do some further initialization here, e.g. register notifications.

   end

   else begin

      // Failed establishing the connection. Show an error message.

   end;

end;

 

C# / .Net


// Global definition

IntPtr pDevice = IntPtr.Zero;

 

// Establish the connection.

if (cNmx.DeviceIPv4Open_1(192, 168, 3, 99, 22517, 22516, ref pDevice) == NMX_MSTATUS.SUCCESS) {

 // Connection has been established successfully.

 // Do some further initialization here, e.g. register notifications.

}

else {

 // Failed establishing the connection. Show an error message.

}