EEIP.NET

repository·master·Indexed 43 days ago

https://github.com/rossmann-engineering/eeip.net

A .NET library for communicating with Ethernet/IP devices. It supports both Explicit Messaging (client-based requests/responses) and Implicit Messaging (cyclic I/O scanning), providing a simplified interface for data exchange, device discovery via ListIdentity(), and interaction with CIP-defined objects.

Tokens
2.1K
Snippets
7
Records
8
Agent score
5%

What's inside EEIP.NET

  1. Overview of EEIP.NET capabilities

    master

    EEIP.NET provides a simplified interface for interacting with Ethernet/IP devices without requiring deep knowledge of the underlying protocol. Key features include:

    • Messaging Support: Both Explicit Messaging (client-based requests/responses) and Implicit Messaging (cyclic I/O scanning).
    • Object Library: Includes a library of CIP-defined objects.
    • Data Exchange: Facilitates communication with various Ethernet/IP compatible hardware.
  2. Establish Implicit Messaging (I/O) connections

    master

    Implicit Messaging (often called I/O messaging) is used for high-speed, cyclic data exchange. Unlike Explicit Messaging, you must configure connection parameters for both the Originator $\rightarrow$ Target (O_T) and Target $\rightarrow$ Originator (T_O) paths before calling ForwardOpen().

    Key configuration properties:

    • O_T_InstanceID / T_O_InstanceID: The assembly instance IDs.
    • O_T_Length / T_O_Length: The size of the data packets.
    • O_T_ConnectionType / T_O_ConnectionType: Connection type (e.g., Point_to_Point or Multicast).
    • RequestedPacketRate_O_T / RequestedPacketRate_T_O: The RPI (Requested Packet Interval) in microseconds.
    • O_T_Priority / T_O_Priority: The priority of the connection (e.g., Scheduled or Low).

    Once ForwardOpen() is called, you can access the cyclic data via O_T_IOData (for outputs) and T_O_IOData (for inputs). Use ForwardClose() to terminate the connection.

    // Setup Originator to Target (Outputs)
    eeipClient.O_T_InstanceID = 0x64;
    eeipClient.O_T_Length = 4;
    eeipClient.O_T_ConnectionType = ConnectionType.Point_to_Point;
    eeipClient.RequestedPacketRate_O_T = 500000; // 500ms
    
    // Setup Target to Originator (Inputs)
    eeipClient.T_O_InstanceID = 0x65;
    eeipClient.T_O_Length = 16;
    eeipClient.T_O_ConnectionType = ConnectionType.Multicast;
    eeipClient.RequestedPacketRate_T_O = 500000;
    
    // Start cyclic communication
    eeipClient.ForwardOpen();
    
    // Access data in a loop
    // eeipClient.O_T_IOData[index] = value;
    // byte input = eeipClient.T_O_IOData[index];
    
    eeipClient.ForwardClose();
  3. Install EEIP.NET

    master

    EEIP.NET is an Ethernet/IP compatible library for .NET implementations designed for data exchange with Ethernet/IP devices. It supports both IO Scanner (Implicit Messaging) and Explicit Message Client functionality. You can download the library from SourceForge.

    https://sourceforge.net/projects/eeip-net/files/latest/download
  4. Discover Ethernet/IP devices on the network

    master

    Use the ListIdentity() method to perform device discovery on the network. This returns a list of CIPIdentityItem objects containing metadata about the discovered devices, such as Product Name, IP Address, Vendor ID, and Product Code.

    EEIPClient eipClient = new EEIPClient();
    List<Encapsulation.CIPIdentityItem> cipIdentityItems = eipClient.ListIdentity();
    
    foreach (var item in cipIdentityItems)
    {
        Console.WriteLine($"Device: {item.ProductName1}, IP: {Encapsulation.CIPIdentityItem.getIPAddress(item.SocketAddress.SIN_Address)}");
    }
  5. Read analog inputs using Explicit Messaging

    master

    To read analog inputs, use AssemblyObject.getInstance to fetch the data bytes. Since analog values are often represented as 16-bit integers, use EEIPClient.ToUshort(byte[] data) to convert the byte array into a usable unsigned short value.

    EEIPClient eeipClient = new EEIPClient();
    eeipClient.RegisterSession("192.168.178.66");
    
    // Get analog input data (Instance 0x6D)
    byte[] analogInputs = eeipClient.AssemblyObject.getInstance(0x6D);
    
    // Convert bytes to ushort (e.g., for temperature)
    ushort val1 = EEIPClient.ToUshort(new byte[] { analogInputs[0], analogInputs[1] });
    
    eeipClient.UnRegisterSession();
  6. Read digital inputs using Explicit Messaging

    master

    To read digital inputs, use AssemblyObject.getInstance to retrieve a byte array from a specific instance ID. You can then parse individual bits from the returned bytes using the EEIPClient.ToBool(byte[] data, int bitIndex) helper method.

    Example workflow:

    1. RegisterSession(ipAddress)
    2. AssemblyObject.getInstance(instanceId)
    3. Parse bits using EEIPClient.ToBool.
    EEIPClient eeipClient = new EEIPClient();
    eeipClient.RegisterSession("192.168.178.66");
    
    // Get the state of digital inputs (Instance 0x6C)
    byte[] digitalInputs = eeipClient.AssemblyObject.getInstance(0x6c);
    
    // Read specific bits
    bool input1 = EEIPClient.ToBool(digitalInputs[0], 0);
    bool input2 = EEIPClient.ToBool(digitalInputs[0], 1);
    
    eeipClient.UnRegisterSession();
  7. Read and write sensor parameters using GetAttributeSingle and SetAttributeSingle

    master

    For devices like the Keyence NU-EP1, you can interact with specific attributes using GetAttributeSingle and SetAttributeSingle.

    • GetAttributeSingle(class, instance, attribute): Retrieves a single attribute value.
    • SetAttributeSingle(class, instance, attribute, byte[] value): Sets a single attribute value.

    These methods allow for fine-grained control over sensor parameters (like light intensity) beyond simple assembly object reads/writes.

    EEIPClient eeipClient = new EEIPClient();
    eeipClient.IPAddress = "192.168.0.123";
    eeipClient.RegisterSession();
    
    // Read an attribute (e.g., sensor value)
    byte[] response = eeipClient.GetAttributeSingle(0x66, 1, 0x325);
    
    // Write an attribute (e.g., set intensity)
    byte[] newValue = new byte[] { 50, 0 };
    eeipClient.SetAttributeSingle(0x66, 1, 0x389, newValue);
    
    eeipClient.UnRegisterSession();
  8. Write digital outputs using Explicit Messaging

    master

    To write digital outputs to an Ethernet/IP device using Explicit Messaging, use the AssemblyObject.setInstance method. You must first register a session with the device's IP address using RegisterSession.

    Note that the specific Instance ID and the byte array format depend on your device's manual (e.g., a Wago device might use instance 0x66 for digital outputs).

    EEIPClient eeipClient = new EEIPClient();
    
    // Register Session
    eeipClient.RegisterSession("192.168.178.66");
    
    // Write an Output to the device (Instance 0x66)
    eeipClient.AssemblyObject.setInstance(0x66, new byte[] { 0x01 });
    
    // When done, unregister
    eeipClient.UnRegisterSession();