CogEthernetPortAccess ClassCognex VisionPro 9.5
Instances of CogEthernetPortAccess class are held by the CogCommCard class.

Use CreateEthernetPort(Int32) to factory/initialize instances of the CogEthernetPort.

Inheritance Hierarchy

System Object
  Cognex.VisionPro.Comm CogEthernetPortAccess

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

public class CogEthernetPortAccess : IDisposable

The CogEthernetPortAccess type exposes the following members.

Methods

  NameDescription
Public methodCreateEthernetPort
Creates an Ethernet port object.

Use the Ethernet port object to configure the properties of an Ethernet port of the hardware.

Note that the lifetime of the created object is not related to the state of the actual Ethernet interface. Also note that the created Ethernet port object does not have exclusive control over the Ethernet port hardware. This means, for example, that the Ethernet port interface may already be "up" and running when this method returns. Or that the properties of the created object may report changed events that were not instigated via its property setters.

Public methodDispose 
Protected methodDispose(Boolean)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize (Overrides Object Finalize .)
Public methodGetActiveEthernetPort
Returns a reference to a currently active Ethernet port object held by the Comm Card, or null if no currently active Ethernet port object exists for the given index.

An active Ethernet port will only exist if CreateEthernetPort(Int32) has been called previously.

Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodReset
Dispose any outstanding Ethernet ports.
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Top
Properties

  NameDescription
Public propertyNumPorts
Gets the number of physical Ethernet ports on the hardware.
Top
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