Creates an Ethernet port object.
Namespace: Cognex.VisionPro.CommUse 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.
Assembly: Cognex.VisionPro.Comm (in Cognex.VisionPro.Comm.dll) Version: 65.1.0.0
Syntax
Parameters
- index
- Type: System Int32
The index of the physical Ethernet port to create the configuration object for.
Return Value
Type: CogEthernetPortExceptions
| Exception | Condition |
|---|---|
| CogAcqHardwareInUseException | Thrown if the hardware is already in use by another process. |
| ArgumentOutOfRangeException | Thrown if the index is greater than or equal to NumPorts. |
| InvalidOperationException | Thrown if the Ethernet port has already been created. |
| CogHardwareInUseException | Thrown if the hardware is in use by another process. Only a single process may access the hardware. When this exception is thrown, you must close any other processes that are using the hardware, and re-start this process in order to access the hardware. |
| CogIncompatibleFirmwareException | Thrown if the version of the Comm Card firmware is incompatible with the version of the host library. Run "%VPRO_ROOT%\bin\fwuphost.exe --pkg vm56_firmware_X_X_X_X.pkg" to upgrade firmware." |
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