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

Addressing I/O by string configuration

mikeardy
2018-11-28
2019-02-14
  • mikeardy - 2018-11-28

    Hi,
    I'm trying to address some input and output lines not directly by a statement like this:

    INPUT_START_BUTTON1               AT %IX0.0   : BOOL;
    

    but something like

    INPUT_START_BUTTON1               AT [MYSTRING]   : BOOL;
    

    and finally I need to pass my I/O declaration variables to a function like

    function(parameter1, [MY I/O Assigned by a String]); 
    

    How can I achieve this?

    Thanks

     
  • dFx

    dFx - 2018-11-28

    Hi,

    go to your IO card, then edit IO/mapping tab. If you have bits, they may be grouped, so expand it to see each individual ones.

    Then, just map the tag to the bit.

    Regards,
    dFx

     
  • mikeardy - 2018-11-29

    I need this functionality because we are going to implement many systems in different places so through a txt file we will release the same system but with the file we will arrange "dynamically" the address and in case of plc exchange we are able to address again the right I/O...
    so I need to obtain a way to do that.
    thank you

     
  • hermsen

    hermsen - 2018-11-29

    Hi,

    Take a look at https://store.codesys.com/io-mapping-tool.html.
    That will probably solve many of your issue's:

    "With the IEC library “IO Mapping Tool”, the inputs and outputs of a program can be remapped via a visualization in runtime mode."

    I know that this can be done visually (online) and programmaticly (offline), the settings can also be saved to disk.

    Good Luck!

     
  • yannickasselin1 - 2018-11-29

    Is there a way to link variables in a separate file just like in TwinCAT when declaring IOs like this:

    myInput AT%I: BOOL;
    myOutput AT%Q
    : BOOL;

    I am sure there is a way to do it, I just don't know how. I am mostly using TwinCAT but I would really like to be able to do this in CODESYS.

    Thank you.

     
  • mikeardy - 2018-11-30

    Hermsen hat geschrieben:
    Hi,
    Take a look at https://store.codesys.com/io-mapping-tool.html.
    That will probably solve many of your issue's:
    "With the IEC library “IO Mapping Tool”, the inputs and outputs of a program can be remapped via a visualization in runtime mode."
    I know that this can be done visually (online) and programmaticly (offline), the settings can also be saved to disk.
    Good Luck!

    I'm not sure what the library really do. The example attached did not help me.
    Is there a simpler solution without any libraries?

     
  • dFx

    dFx - 2018-11-30

    So, you want to late bind.

    I would proceed as follow :
    1) Define array for my I/Os : binaryInput[0..99] and map it to I/Os, same for outputs and analog
    2) Define mapping array : FunctionMapping[0..99]
    3) OPTIONAL FOR CODE READABILITY
    Define constant for each function, that would be index of mapping array : exemple PUMP_BREAKER := 1, PUMP_HIGH_PRESSURE:=2
    4) Use in code, binaryInput[FunctionMapping[PUMP_BREAKER]] when you need it in program
    5) Configure your program I/Os by setting the rigth value in FunctionMapping array, knowing the constant values and your I/Os (that may come from a string)

     
  • mikeardy - 2018-12-03

    Could you show me an example of what you are explaining me?
    Thank you

     
  • dFx

    dFx - 2018-12-03

    To correctly map your inputs to the wired inputs, just change the value of :
    IoMapDO[MAP.PUMP_RUN]
    IoMapDI[MAP.PUMP_REQUEST]
    IoMapDI[MAP.PUMP_FAULT]

    to the index of your input.

    Sample project attached.

    For more code readability, but requiring more treatment, you may also copy every IO_DI/DO array value to the right tag (adding one more layer, but every access will have the same tag)

    IMG: 1.png

    IMG: 2.png

    IMG: 3.png

    IMG: 4.png

    IMG: 5.png

     
  • mikeardy - 2018-12-04

    Hi,
    it is not my situation.
    Let me explain in deep.
    I need a solution to address the I/O on different systems that may differ between them.
    For example one system may have only one valve and a feedback and the other may have three valves and some other feedback. The main program must be the same but via txt file I would like to "configure' the behaviour of the system, so a dynamic block could address different I/O based on the file.
    I don't have to modify the application program. Just download to the destination PLC, change the txt file and... that's it.
    Thank you

     
  • dFx

    dFx - 2018-12-04

    So you mean, you have different number of process instances ? -> just do a loop call for each instances, with variable count.
    this exemple totally conforms with your needings, assuming you write by yourself TXT file reading and values setting from it (functionnal mapping, number of instances …)

     
  • mikeardy - 2018-12-05

    No no, maybe I'm not so clear...

    I have to deploy many PLC in different sites.
    Every sites can have a different configuration in term of I/O.
    So the idea is to write one time the generic application program and configure the behaviour by a TXT file read at startup.
    In the past I managed something like that but for parameters only, not for I/O.
    So I need to be able to configure dynamically this I/O.

     
  • dFx

    dFx - 2018-12-05

    give us at least 3 exemples sites

     
  • mikeardy - 2018-12-06

    ok

    1. a plc on a site must manage for example a tank with 1 valve (output) and 1 feedback (input)

    2. a plc must manage a tank with 2 valves (2 outputs) and 2 feedbacks (inputs)

    3. a plc must manage two tanks with 1 valve each and 1 feedback each (2 outputs and 2 inputs)

    in my idea I will develop only one application delivered to all plcs and send the plcs to the destination, remotely I will put the txt file and the application will arrange dynamically the addressing, that is my need
    a text file like
    I0.0
    I0.1
    I0.2
    ....
    O0.2
    O0.3
    and the plc will address the relatives I/O.
    if some input or output gate is going out for some reason a qualified person could switch physically to another and I remotely could change the txt file addressing correctly the new one.

     
  • dFx

    dFx - 2018-12-06

    What I purposed earlier totaly conforms in your needings.

    So step 1 : create a generic plc program that address all I/Os (IO_DI/DOs arrays, Mapping arrays). You can forget about the constants.
    Step 2 : create an array for each FB type you will have to use (tank with 1 outlet, tank with inlet+outlet …)
    Step 3 : create fb call Inside a loop for each different fb you got, with a independant variable max loop count (1 for each fb type), using mapped I/Os as fb I/Os
    Step 4 : just configure your program by whatever way you want (like reading txt file or settings manually values) by settings the right values in ioMap arrays and loop counts (loop count = 0 if you have no instance of this type)

    exemple :

    // FB calls
    FOR index:=0 TO MaxFbTankOneValve DO
       FbTankOneValve[index] (ValveInput:=IO_DI[ioMapDI[0 + index]],
          ValveOutput=>IO_DO[ioMapDO[0 + index]]);
    END_FOR;
    FOR index:=0 TO MaxFbTankTwoValves DO
       FbTankTwoValves[index] (ValveInput:=IO_DI[ioMapDI[100 + index]],
          ValveOutput=>IO_DO[ioMapDO[100 + index]]);
    END_FOR;
    

    Assuming you will later set :
    MaxFbTankOneValve as the count of instances of tanks with 1 valve
    MaxFbTankTwoValves as the count of instances of tanks with 2 valves
    ioMapDI[0] + MaxFbTankOneValve to the correct inputs indexes of tanks with 1 valve
    ioMapDO[0] + MaxFbTankOneValve to the correct outputs indexes of tanks with 1 valve
    ioMapDI[100] + MaxFbTankTwoValves to the correct inputs indexes of tanks with 2 valves
    ioMapDO[100] + MaxFbTankTwoValves to the correct outputs indexes of tanks with 2 valves

    Edited for code correction

     
  • josepmariarams - 2019-02-10

    Hi

    Another solution

    Create an FB_dio.

    Inside, put an (which could be static) pointer to array[0..1024] of usint (call him iomem).

    Create two persistent vars:

    Index:int
    Bit:int

    In your fb code, if is an dinput.

    Iomem:= adr(ib0);

    Out:= iomem^[index] and (shl(1, bit))<>0.

    Changing index and bit, you can, programaticaly change your map.

    Best regards

    Sent from my Moto G (5S) Plus using Tapatalk

     
  • aliazzz

    aliazzz - 2019-02-10

    There is a free package in the Codesys store for this. That package is very very powerful. I have used this package in a project and using it was a breeze.
    Apart from providing a mechanic for free arrangeable IO channels, with different datatypes (BOOL, BYTE, WORD etc etc), it can restore previous made configurations and store current configurations onto disk.

    https://store.codesys.com/io-mapping-tool.html
    Plus, it's open source so you can take a look inside the library to learn more about it's mechanics

     

Log in to post a comment.