NJ/CJ Variable Alignment On EtherNet/IP
Both the NJ and the CJ series PLC can work with Structure datatypes.
A Structure can consist of:
However the NJ and CJ controllers align the structures differently in memory. The CJ series controllers just place all members of a structure directly after each other.
A structure defined in a CJ controller consisting of a LWORD, WORD, LWORD is in total 8 bytes, 2 bytes, 8 bytes is 18 bytes in size.
The NJ controllers handle structures differently. The alignment of the members of a structure is according to their size. It can be on a byte, word, 2 word or 4 word boundary.
The same structure of LWORD, WORD, LWORD allocates more memory in the NJ. In this example the total memory allocated is 24 bytes.
If such a structure is then transfered by means of variable name as tagname from a NJ controller to a CJ controller (or vice versa) over EtherNet/IP then this will fail with a size mismatch.
The reason is that EtherNet/IP only transfers a block of data. During opening of the IO connection there is no information exchanged on the structure. Therefore both nodes conclude that the size is different and they will not start to exchange data.
Workaround is to insert so called dummy members to fill the gaps of not used memory. In this way both structures will allocated the same amount of memory and now the structures can be exchanged over EtherNet/IP.