Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Modbus configuration

joanm
2021-06-30
2021-07-06
  • joanm - 2021-06-30

    Hello all,

    INTRODUCTION
    Started using Codesys this week, been using TWinCAT for years though.

    Programming is not an issue given my background, but the configuration part changes a little and I have a doubt about the ModbusTCPSlave I/O Mapping.

    I have to communicate the PLC (Modbus TCP master) to a small device (slave) which will send me 1 BYTEs, 1 WORDs, 1 BYTEs and 15 REALs (64 bytes or 32 words in total).

    I have put all those variables are inside a structure:

    TYPE ST_MODBUS_DATA_FROM_DEVICE_1 :
    STRUCT
        B01 : BYTE := 0;
        w01 : WORD := 0;
        B02 : BYTE := 0;
        r01 : REAL := 0.0;
        r02 : REAL := 0.0;
        r03 : REAL := 0.0;
        r04 : REAL := 0.0;
        r05 : REAL := 0.0;
        r06 : REAL := 0.0;
        r07 : REAL := 0.0;
        r08 : REAL := 0.0;
        r09 : REAL := 0.0;
        r10 : REAL := 0.0;
        r11 : REAL := 0.0;
        r12 : REAL := 0.0;
        r13 : REAL := 0.0;
        r14 : REAL := 0.0;
        r15 : REAL := 0.0;
    END_STRUCT
    END_TYPE
    

    In the configuration, I've added 1 channel, with an offset of 16#7531 and a length of 32.

    This has created an array[0..31] of WORD in the ModbusTCPSlave I/O Mapping.

    Now, I want to link/map the variables into the channel, but I have BYTEs and REALs not WORDs.

    QUESTION
    How can I map my structure (or it's components) to the Modbus channel?

    Any hint (related to this ;) ) will be appreciated.

    Thank you very much for your time and help.

     

    Last edit: joanm 2021-07-01
  • joanm - 2021-07-06

    OK, solved... in TWinCAT you MUST put the variable you want to connect to any IO channel as %I / %Q or similar... it looks like in Codesys you MUST NOT.

    After reading the message slowly (good for me) I've been able to solve it and now I can directly assign the structure to the beginning of the Modbus channel.

    ^^Β‘

     
    πŸ‘
    1

Log in to post a comment.