Mapping members of a struct to Inputs/outputs

kurvanov
2015-09-24
2021-09-03
  • kurvanov - 2015-09-24

    Hello
    I am using Codesys control WIN on windows 7.

    I have defined the following STRUCT for building up IO communication with an Ethercat slave

    TYPE ST_InputList :
       STRUCT
          nVal0        : UINT;
          nVal1        : UINT;
          nValD        : UDINT;
          nValF         : REAL;
       END_STRUCT
    END_TYPE
    

    and

    TYPE ST_IOModule :
       STRUCT
          iData    AT %I*       : ST_InputList;
       END_STRUCT
    END_TYPE
    

    In my application, I have defined a variable

    VAR_GLOBAL
       comModule         : ST_IOModule;
    END_VAR
    VAR_CONFIG
       GVL.comModule.iData    AT %IW1   : ST_InputList;
       (*VL.comModule.oData   AT %QB0      : ST_OutputList;*)
       
    END_VAR
    

    I attach the process data of my slave.
    The first 4 Bytes builds up a bit register. So my first numerical value start at 5th Byte (32nd bit, that's why you see EtherCAT-1\%IW32 although I agree %IW2 would be more consistent).
    I see in the Ethercat I/O mapping that the address is %IW1, I would have expected %IW2 also --> Might there be a problem with ESI file I used to install my slave into codesys ?
    as a result :
    In my slave, when I set a value for the outputs corresponding to the members nVal0 and nVal1, I see the right value in my Ethercat master (running on codesys control WIN) --> everything Ok so far for UINT value
    But, for nValD, when I write the value 1 on the salve side, I see 65536 on the Master side.
    I don't understand how Bytes,Word,Dword are arranged.

    I would appreciate any help. thank you

    IMG: Codesys mapping.JPG

     
  • Anonymous - 2015-11-25

    Originally created by: scott_cunningham

    I have seen this before with other hardware. Basically, the data is copied byte by byte starting at the left. So if your data is 16 bit variable and you map it to a 32 bit ethercat register, your variable is copied to the upper word. You should be able to avoid this problem by using data of the same size (variable versus ethercat register). If you cannot change the data size, then you can make special bit shifting to get your data....

     
  • pato - 2021-09-03

    some PLCs place the bytes into the memory as little endian and others as big endians. You will have to check when this happen and to do the swapping of the words when needed

     

Log in to post a comment.