This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-AM243: How to create a 4-byte counter (e.g., uint32_t) on the LP-AM243 that: Increments on a condition (e.g., button press, timer, signal) store in memory so CODESYS or Allen-Bradley can read it via EDS

Part Number: LP-AM243

Tool/software:

To create a 4-byte counter (e.g., uint32_t) on the LP-AM243 that:

  • Increments on a condition (e.g., button press, timer, signal)

  • Is exposed via EtherNet/IP Input Assembly (e.g., Assembly 101)

  • Stored in memory so CODESYS or Allen-Bradley can read it via EDS

  • Compatible with the EDS parameter / assembly model

  • Hi Thien,

    To help clarify how Assembly and attributes are used, I'll refer to the Generic Device example as a reference. By examining this example, you should be able to understand how to achieve your goal.

    In the generic_device.c file, the GENERIC_DEVICE_cipSetup function creates two Assembly instances, 0x64 and 0x65, which are used for exclusive owner connections. Assembly instance 0x64 is responsible for producing the output stream (Target to Originator), while Assembly instance 0x65 is responsible for consuming the input stream received from the PLC/Originator (Originator to Target).

    Before adding members to the Assemblies, a new class (class ID 0x70) with one instance (instance ID 1) and several attributes is created in the GENERIC_DEVICE_cipGenerateContent function. This class is then used to add attributes to each Assembly.

    For the consuming Assembly (0x65), attributes 0x308 to 0x30D are added from the class 0x70, instance 1. Similarly, attributes 0x300 to 0x305 are added to the producing Assembly (0x64) from the same object (class 0x70, instance 1).
    Since your question is about the producing part, let's focus on how changes to the attributes linked to the producing Assembly (0x64) affect the output stream. For example, if we change the value of attribute 0x300, which is linked to the producing Assembly 0x64, the change will be reflected in the output stream.
    To illustrate this, let's consider a scenario where we want to increment a counter whenever the first byte received from the PLC/Originator is changed. Here's an example of how you could modify the GENERIC_DEVICE_run function to achieve this:

    void GENERIC_DEVICE_run(EI_API_CIP_NODE_T* pCipNode)
    {
        uint32_t errCode = EI_API_CIP_eERR_OK;
        uint8_t  attrValue = 0;
        static uint8_t counter = 0;
        static uint8_t lastAttribute = 0xFF;
    
        EI_API_CIP_getAttr_usint(pCipNode, 0x0070, 0x0001, 0x0308, &attrValue); //read Class 0x70, Instance 1, attribute 0x308, which is linked to consuming assembly.
    
    #ifndef ENABLE_INTERCORE_TUNNELING
            if ( errCode == EI_API_CIP_eERR_OK)
            {
                DRV_LED_industrialSet(attrValue);
            }
    #endif
    
        if(lastAttribute != attrValue)
        {
            EI_API_CIP_setAttr_usint(pCipNode, 0x0070, 0x0001, 0x0300, counter); //change attribute 0x300, which is linked to producing assembly
            ++counter;
            lastAttribute = attrValue;
        }
    
    }