CogEthernetPortSettings ClassCognex VisionPro
The CogEthernetPortSettings class groups together related IP network settings like IPAddress and SubnetMask. The CogEthernetPortSettings class is used by the CogEthernetPort class to read/write IP network configuration settings from/to Comm Card hardware.
Inheritance Hierarchy

System Object
  System MarshalByRefObject
    Cognex.VisionPro.Implementation CogObjectBase
      Cognex.VisionPro.Implementation CogChangedEventBase
        Cognex.VisionPro.Comm CogEthernetPortSettings

Namespace: Cognex.VisionPro.Comm
Assembly: Cognex.VisionPro.Comm (in Cognex.VisionPro.Comm.dll) Version: 65.1.0.0
Syntax

public class CogEthernetPortSettings : CogChangedEventBase

The CogEthernetPortSettings type exposes the following members.

Constructors

  NameDescription
Public methodCogEthernetPortSettings
Top
Methods

  NameDescription
Public methodCreateObjRef
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
Protected methodGetAttributes
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetClassName
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetComponentName
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetConverter
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetDefaultEvent
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetDefaultProperty
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetEditor
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetEvents 
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetEvents( Attribute )
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetLifetimeService
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Protected methodGetProperties 
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetProperties( Attribute )
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetPropertyOwner
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodInitializeLifetimeService
Obtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone 
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodMemberwiseClone(Boolean)
Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject.)
Protected methodOnChanged(Int64)
This method should be called internally whenever the object's state may have changed.
(Inherited from CogChangedEventBase.)
Protected methodOnChanged(CogChangedEventArgs)
This method may be called internally whenever a derived object's state may have changed and the derived object expresses this change via a derived CogChangedEventArgs class.
(Inherited from CogChangedEventBase.)
Public methodResumeAndRaiseChangedEvent
Re-enables raising of the Changed event after SuspendChangedEvent has been called, and raises the Changed event if the ChangedEventSuspended count is reduced to zero and any changes were made while events were suspended. Must be called once for each call to SuspendChangedEvent.
(Inherited from CogChangedEventBase.)
Public methodSuspendChangedEvent
Temporarily suspends the raising of the Changed event. May be called more than once, and a corresponding call to ResumeAndRaiseChangedEvent must be made for each call to SuspendChangedEvent.
(Inherited from CogChangedEventBase.)
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Top
Fields

  NameDescription
Public fieldStatic memberSfDefaultGateway
This bit will be set in the EventArgs of a Changed event every time the value returned by DefaultGateway may have changed.
Public fieldStatic memberSfDHCPEnable
This bit will be set in the EventArgs of a Changed event every time the value returned by DHCPEnable may have changed.
Public fieldStatic memberSfDomainName
This bit will be set in the EventArgs of a Changed event every time the value returned by DomainName may have changed.
Public fieldStatic memberSfHostName
This bit will be set in the EventArgs of a Changed event every time the value returned by HostName may have changed.
Public fieldStatic memberSfIPAddress
This bit will be set in the EventArgs of a Changed event every time the value returned by IPAddress may have changed.
Protected fieldStatic memberSfNextSf
Public fieldStatic memberSfSubnetMask
This bit will be set in the EventArgs of a Changed event every time the value returned by SubnetMask may have changed.
Top
Properties

  NameDescription
Public propertyChangedEventSuspended
If nonzero, indicates that the raising of the Changed event has been suspended. This value is incremented when SuspendChangedEvent is called and decremented when ResumeAndRaiseChangedEvent is called.
(Inherited from CogChangedEventBase.)
Public propertyDefaultGateway
Gets or sets the default gateway of the Ethernet port.

Attempts to set this property are ignored when DHCPEnable is true.

Public propertyDHCPEnable
Gets or sets whether DHCP is enabled for the Ethernet port.
Public propertyDomainName
Gets or sets the domain name.
Public propertyHostName
Gets or sets the host name.
Public propertyIPAddress
Gets or sets the IP address of the Ethernet port.

Attempts to set this property are ignored when DHCPEnable is true.

Public propertyStateFlags
Returns the complete set of state flags supported on this object. The flags may be indexed by name as shown in the following C# code snippet: if (changedObject.StateFlags["Color"] & eventArgs.StateFlags) { ... }
(Inherited from CogChangedEventBase.)
Public propertySubnetMask
Gets or sets the subnet mask of the Ethernet port.

Attempts to set this property are ignored when DHCPEnable is true.

Top
Events

  NameDescription
Public eventChanged
This event is raised when one or more parts of the object's state may have changed.
(Inherited from CogChangedEventBase.)
Top
Remarks

Ethernet settings are written to the Comm Card using WriteSettings . These settings are stored in flash memory directly on the Comm Card.

When a VisionPro application first connects to a Comm Card, the Comm Card automatically attempts to bring the Ethernet port interface "UP" using the stored settings. Later, when the VisionPro application exits, the Comm Card will automatically bring the Interface "DOWN", removing the card from the network.

Both the Link (physical connection present) and the Interface (IP settings activated) need to be in the "UP" state for the Ethernet port to participate in an IP network. When the link or interface is "DOWN", the Ethernet port cannot communicate over an IP network.

Use IsLinkUp to see if the Link is in the "UP" state. When the Link is up, the Ethenet port is physically connected to a network and can physically transmit and receive data.

Use IsInterfaceUp to see if the Interface is in the "UP" state. When the Interface is up, the Ethernet port has been activated with IP network settings and can participate in an IP network.

Use WriteSettings  and ReadSettings  to read and write network settings to the Comm Card.

Use BringInterfaceUpAsync  and BringInterfaceDownAsync  to manually bring the interface "UP" and "DOWN" using the settings stored on the Card.

Use ReadActiveSettings  to read the currently active settings while the Interface is "UP". The currently active settings may be different from the settings stored on the card in cases where the card is configured for DHCP, or if something (i.e. PROFINET) changes the active settings without also writing them to the storage location on the card.

Note that CogEthernetPort does not have exclusive control over the Ethernet port hardware. The Ethernet port interface may already be "UP" when a CogEthernetPort is created. Furthermore, the state of the Ethernet interface may report changes and events that were _not_ initiated from user calls into its own properties and methods.

Note also that the lifetime of this object is not related to the state ("UP" or "DOWN") of the Ethernet port interface. Disposing the CogEthernetPort object will not affect the state of actual Ethernet settings running on the card (even though exiting the _process_ will bring the network interface "DOWN").

Examples

using Cognex.VisionPro;
using Cognex.VisionPro.Comm;

// Change the IP address on a Comm Card Ethernet port. 
public void ChangeIPAddress(
  string newAddress,
  string newSubnet,
  string newDefaultGateway)
{
CogCommCards commCardCollection = new CogCommCards();

Console.WriteLine("Found: {0} Comm Cards", commCardCollection.Count);
if (commCardCollection.Count == 0) return;

// Get a reference to the the comm card object.
CogCommCard card = commCardCollection[0];

Console.WriteLine("Name: {0}", card.Name);
Console.WriteLine("Serial: {0}", card.SerialNumber);

Console.WriteLine("NumEthernetPorts: {0}", card.EthernetPortAccess.NumPorts);
if (card.EthernetPortAccess.NumPorts == 0) return;

// Create a software object to interact with Ethernet port.
CogEthernetPort etherPort = card.EthernetPortAccess.CreateEthernetPort(0);

Console.WriteLine("Current Ethernet Port Settings:");
Console.WriteLine("  link up: {0}", etherPort.IsLinkUp);
Console.WriteLine("  iface up: {0}", etherPort.IsInterfaceUp);

// Read the persistant settings from the Comm Card.
CogEthernetPortSettings settings = etherPort.ReadSettings();

Console.WriteLine("  ip: {0}", settings.IPAddress);
Console.WriteLine("  subnet: {0}", settings.SubnetMask);
Console.WriteLine("  default gateway: {0}", settings.DefaultGateway);
Console.WriteLine("  host name: {0}", settings.HostName);
Console.WriteLine("  domain name: {0}", settings.DomainName);
Console.WriteLine("  dhcpEnable: {0}", settings.DHCPEnable);

if (etherPort.IsInterfaceUp)
{
  Console.WriteLine("Bringing Interface DOWN...");

  bool timedOut = !etherPort.BringInterfaceDownAsync().Wait(2000);
  if (timedOut)
  {
    Console.WriteLine("Bringing Interface Down TIMED OUT!!");
    return;
  }
  Console.WriteLine("The Interface is DOWN.");
}

Console.WriteLine("Writing new IP address to Comm Card.");

// Change the settings to the new ip address.
settings.IPAddress = IPAddress.Parse(newAddress);
settings.SubnetMask = IPAddress.Parse(newSubnet);
settings.DefaultGateway = IPAddress.Parse(newDefaultGateway);
settings.HostName = "hostname";
settings.DomainName = "";
settings.DHCPEnable = false;

// Write the new settings to the card.
etherPort.WriteSettings(settings);

// Bring up the interface with the new IP address. 
if (!etherPort.IsInterfaceUp)
{
  Console.WriteLine("Bringing Interface UP...");

  bool timedOut = !etherPort.BringInterfaceUpAsync().Wait(2000);
  if (timedOut)
  {
    Console.WriteLine("Bringing Interface UP TIMED OUT!!");
    return;
  }
  Console.WriteLine("The Interface is UP.");
}

Console.WriteLine("New Ethernet Port Settings:");
Console.WriteLine("  link up: {0}", etherPort.IsLinkUp);
Console.WriteLine("  iface up: {0}", etherPort.IsInterfaceUp);

// Read the current settings from the Comm Card.
settings = etherPort.ReadActiveSettings();

Console.WriteLine("  ip: {0}", settings.IPAddress);
Console.WriteLine("  subnet: {0}", settings.SubnetMask);
Console.WriteLine("  default gateway: {0}", settings.DefaultGateway);
Console.WriteLine("  host name: {0}", settings.HostName);
Console.WriteLine("  domain name: {0}", settings.DomainName);
Console.WriteLine("  dhcpEnable: {0}", settings.DHCPEnable);
}


------
Output
------

Found: 1 Comm Cards
Name: Cognex Communications Card 24C
Serial: 1A1410XN002183
NumEthernetPorts: 1
Current Ethernet Port Settings:
  link up: False
  iface up: True
  ip: 192.168.1.42
  subnet: 255.255.0.0 
  default gateway: 192.168.1.3
  host name: HostName
  domain name: 
  dhcpEnable: False
Bringing Interface DOWN...
The Interface is DOWN.
Writing new IP address to Comm Card.
Bringing Interface UP...
The Interface is UP.
New Ethernet Port Settings:
  link up: False
  iface up: True
  ip: 192.168.1.100
  subnet: 255.255.255.255 
  default gateway: 192.168.1.1
  host name: hostname
  domain name: 
  dhcpEnable: False
See Also