IMDHMIControls LibraryShop main store

How-to

Set up a CODESYS adapter for explicit CIP messaging to Logix

Industrial networks Published 6 min read

Short answer

Register the custom CIP object in the adapter during startup with RegisterCIPObject, point both Logix MSG instructions at the same Class, Instance and Attribute 3 with Get and Set Attribute Single, and keep the exchanged value at or under 468 bytes. A ten-element DINT array is 40 bytes, well inside the limit; verify with the write MSG DN bit and matching readback on both sides.

On this page
  1. What explicit messaging does on this link
  2. Check the base connection first
  3. Import the object function block
  4. Register the object at startup
  5. Configure both MSG instructions
  6. Payload check: ten DINTs against the 468-byte limit
  7. Prove the exchange end to end
  8. Exchange other data types
  9. Questions asked

Explicit CIP messaging between a CODESYS EtherNet/IP adapter and a Logix controller comes down to three things lining up: the custom object is registered in the adapter at startup, both MSG instructions address the same Class, Instance and Attribute 3, and the exchanged value stays at or under the object 468-byte limit. The documented example exchanges a ten-element DINT array — 40 bytes — between a ctrlX CORE running the CODESYS EtherNet/IP Adapter and Studio 5000 on the Logix side. Register the object on the first task execution after download, set the Logix messages to CIP Generic with Get Attribute Single for the read and Set Attribute Single for the write, then prove the link with the write MSG DN bit and identical readback arrays.

Explicit messaging is the request/response half of EtherNet/IP: non-time-critical reads and writes carried as TCP transactions, each one aimed at a Class, Instance and Attribute instead of at a cyclic I/O connection. It suits configuration, diagnostics and data that does not need every-scan delivery. A healthy cyclic connection proves the two devices can talk; it proves nothing about a custom object, so do not troubleshoot a failed explicit request by editing I/O mappings — registration and message addressing are separate checks.

Every explicit request carries the same three-part address used across CIP networks, and the DeviceNet class, instance and attribute codes used for explicit messaging page shows how those addresses look in a real device table.

Direction matters. Here the CODESYS device is the adapter, answering requests the Logix scanner sends. When CODESYS must originate the requests instead, that is scanner work: reading and writing Logix tags from CODESYS with CIP GenericService covers that direction, and why the CODESYS EtherNet/IP scanner runs in demo mode covers the license symptom that appears when the scanner side is not licensed.

Check the base connection first #

The documented procedure builds on an adapter and scanner configuration that already runs. Before touching the custom object, confirm:

  • The adapter device is present in the Logix I/O tree and its connection reports healthy.
  • The CODESYS application holding the EtherNet/IP Adapter is downloaded and running on the controller.
  • Reachability and device configuration faults are fixed, because a sick base connection fails every explicit request stacked on top of it.

With those holding, every remaining failure lives in one of three places: registration, the message address, or the payload.

Import the object function block #

  1. Add the EtherNet/IP example libraries the project needs and resolve the references the engineering environment reports before download; library versions follow the environment version.
  2. In the Devices explorer, select the Application, then use Project Menu -> Import PLCopenXML to import the XML shipped with the example. It creates the CipObjectDintArray10 function block.
  3. Open the function block and write down the Class ID and Instance ID declared in its VAR section; both MSG instructions will use exactly these numbers.
  4. Note the declared type of Value, which defines the exchanged data — a ten-element DINT array in this example.

The Class and Instance numbers are yours to set. Keep them in the vendor-specific index ranges rather than numbers a standard object class already claims; the equivalent adapter example published for another runtime uses class ID 0x0070 with its attributes in the vendor-specific range.

Register the object at startup #

Importing the function block registers nothing: an instance has to be handed to the adapter while the application starts, or the scanner requests arrive with no object behind them. Create a program POU under the application, schedule it in a task, and register on first execution:

VAR
    bInit : BOOL;                  // starts FALSE, latches after the call
    CipObject1 : CipObjectDintArray10;
END_VAR

IF NOT bInit THEN
    EtherNet_IP_Adapter.RegisterCIPObject(CipObject1);
    bInit := TRUE;
END_IF

The names come from the example project; in your project the call targets the adapter device instance you configured.

  1. Put the POU in a task that runs. A POU left in the project tree outside any task never executes, and the object never registers.
  2. Download and watch bInit latch true. That is evidence the path executed, not proof the object is reachable — the deciding test is a Logix request completing against it.
  3. Keep bInit non-retained. After every download or restart the call must run again; a retained flag skips it and leaves the adapter with nothing registered.
  4. If the object stays unreachable, read the adapter device diagnostics before blaming the Logix side.

Configure both MSG instructions #

Both messages are CIP Generic; only the service differs.

  1. Read MSG: Service Type Get Attribute Single. Class and Instance are the IDs recorded from the function block, Attribute is 3, and the destination element is a DINT[10] tag matching Value.
  2. Write MSG: Service Type Set Attribute Single, with the same Class, Instance and Attribute 3. The source element is the DINT[10] tag, and Source Length is 40 — the value size in bytes, not its element count.
  3. Point both communication paths at the adapter module name in the Logix I/O tree, the same entry the cyclic connection uses.
  4. If one direction works and the other fails, compare the two instructions field by field: service, path, Class, Instance, Attribute, element type, length.

Attribute 3 is where this function block exposes Value; Get Attribute Single reads that slot and Set Attribute Single writes it. That mapping belongs to this implementation, so change it only by editing the block, never on one side alone.

Payload check: ten DINTs against the 468-byte limit #

Inputs: the example Value holds 10 elements (the example project), one DINT is 4 bytes (a DINT is a 32-bit integer), and the function block documented limit on the value is 468 bytes.

Rule: value size equals element count multiplied by bytes per element, and the result must stay at or under 468 bytes.

Arithmetic:

  • 10 elements × 4 bytes per element = 40 bytes
  • 468 bytes − 40 bytes = 428 bytes of headroom
  • 468 bytes ÷ 4 bytes per DINT = 117 DINTs, the largest array that fits
  • An 80-element array would be 80 elements × 4 bytes per element = 320 bytes, still inside the limit but with only 148 bytes of headroom

Result: the value is 40 bytes, and the write MSG Source Length is 40.

Decision: at 40 bytes the array ships unchanged, well inside the limit. Past 117 DINTs the value exceeds 468 bytes, so stop growing the array and split the data across a second object with its own Instance ID.

Prove the exchange end to end #

  1. Load random values into the source DINT[10] tag.
  2. Raise the write trigger bit and confirm the write MSG DN bit goes true, which says the service completed.
  3. Trigger the read MSG; the destination DINT[10] must equal the source element for element.
  4. On the adapter side, confirm the same ten values sit in Value.

A set DN bit with a wrong readback means the request landed somewhere other than your data: the wrong Instance, a duplicate object, a second writer, or a type and size mismatch. Compare the source tag, the adapter Value and the destination tag in that order; the first place the numbers disagree names the fault. If these values feed machine logic, validate them in the receiving program before acting on them — a completed message is still just data that arrived over TCP.

Exchange other data types #

Duplicate the function block for each additional data set: give each copy its own Instance ID, change the Value type, and register each instance the same way at startup. On the Logix side, build a tag with the same members in the same order and the same total size; structures can pad, so compare actual byte counts rather than member sizes alone. Strings are the known trouble spot, because CODESYS and Rockwell lay out string data differently: exchange the characters as an array and rebuild the string on the receiving controller instead of sending string types directly.

Questions asked

Does the 468-byte limit apply to every EtherNet/IP adapter?

No. It is the documented size limit on the value in this example function block, not a property of the protocol or of every adapter. Other devices and services state their own limits, so size each object against the limit documented for the implementation you run: element count times bytes per element against the stated maximum.

Can I register more than one CIP object in the same adapter?

Yes. Duplicate the function block for each data set, give each copy its own Instance ID, set that copy Value type, and register every instance with its own RegisterCIPObject call at startup. Mirror each object as a Logix tag with matching type and size, and add one Get and one Set message per object.

What happens to the object after a download or power cycle?

Registration does not persist. The startup program must call RegisterCIPObject again on the first task execution after every download and restart, so keep the one-shot flag non-retained. A retained flag skips the call after a warm restart and the scanner is left addressing an object that no longer exists.

How do I exchange strings between CODESYS and a Logix controller?

Not as native string types. The two platforms lay out string data differently, so a direct exchange arrives scrambled. Send the characters in a byte or DINT array sized inside the limit, carry the string length in its own element, and rebuild the string on the receiving controller.

Keep reading

  • Troubleshooting

    Why explicit writes to Omron assemblies fail over EtherNet/IP

    Your Set Attribute message carries service code E, which is Get Attribute Single, so it reads, succeeds and writes nothing — and the two codes are transposed, since Set Attribute Single is 10 hex. Even corrected, CS/CJ-series EtherNet/IP units do not accept explicit writes to assembly instances, because that service is optional in the specification. Carry the 240 bytes on a Generic Ethernet Module connection or use CIP Data Table Read and Write messages.

    Industrial networks

  • Troubleshooting

    Fix EtherNet/IP I/O between a ctrlX adapter and a Rockwell scanner

    Start at the Studio 5000 module status: a connection that never establishes points to the IP path or the assembly fields, while a connection with wrong or frozen data points to swapped input/output instances or the task interval. Match instance numbers and byte counts at both ends, instance 100 for consumed data with configuration instance 102 at length 0 in the documented example, and set the adapter I/O task interval equal to the scanner's RPI, 4 ms at priority 20 to 39.

    Industrial networks

  • How-to

    Read and write Logix tags from CODESYS with CIP GenericService

    Read a Logix tag from CODESYS with CIP service 16#4C against the tag's Symbol Object instance at class 16#6B: send a two-byte element-count body, expect a two-byte type word first (16#C4 is DINT), and take the DINT value from bytes 2-5. Write with service 16#4D, sending type word, element count, then data. Rebuild the name-to-instance table after every download or online edit, because the controller reassigns instance numbers.

    Industrial networks