Connect Method

The Connect method is overloaded, with the following options:

void Connect(string address)
void Connect(string address, int port)
void Connect(string address, int port, int timeout)
        

Summary

The Connect method is used to open a connection to an ETH32 device. You must call Connect and successfully connect to an ETH32 device before calling other methods or accessing other properties of the Eth32 object. This method does NOT reset the device or change its configuration in any way.

Parameters

  • address - The IP address or DNS name of the ETH32 device.

  • port - The TCP port to connect to. If an overloaded method without this parameter is called, the constant Eth32.DefaultPort (7152) is used, which is the port the ETH32 listens on.

  • timeout - Specifies the maximum time, in milliseconds, that the connection attempt may take, excluding resolving DNS. You may specify a timeout of zero to use the default timeout from the system's TCP/IP stack, which is the behavior for the overloaded methods without this parameter. Note that the method may time out in less time than you specify if the system's timeout is shorter than what you specify. If the method does time out, it will raise an Eth32Exception with ErrorCode of EthError.Timeout

Return Value

This method does not have a return value. If any error occurs, an Eth32Exception will be raised.

Remarks

Once an object is connected to a device, you may not call Connect again on that object unless you first disconnect using the Disconnect Method. Note that your application may have connections open to several ETH32 devices at once. Each requires a separate Eth32 object to be created in your application.

Example
Eth32 dev = new Eth32();

try
{
	// Attempt to connect.  If it takes longer than 10 seconds, time out.
	dev.Connect("192.168.1.100", Eth32.DefaultPort, 10000);

	// Now that we're connected, turn on an LED:
	dev.Led[0]=true;
}
catch (Eth32Exception e)
{
	if(e.ErrorCode==EthError.Timeout)
	{
		MessageBox.Show("Timed out while connecting to ETH32.");
	}
	else
	{
		MessageBox.Show("Error connecting to ETH32: " + Eth32.ErrorString(e.ErrorCode));
	}
}
        
See Also

Connected Property, Disconnect Method