FB referencing I/Os (resolved)

2017-06-06
2017-06-11
  • nothinrandom

    nothinrandom - 2017-06-06

    Is there a way to pass an array of I/Os into a function block? For example, I have a program (called TEST) that references an array of inputs on the EtherNet/IP adapter: _iStatus AT %IW10: ARRAY[1..8] OF WORD;

    However, I would like to turn this program into a function block so that I can create instances of program in PLC_PRG. To be able to do this, I can't be referencing the same %IW10 because each EtherNet/IP module will give back different address. If there's not a cleaner way of doing this, how can I pass the address into the function block and allow it to reference the correct address?

    Thanks,

     
  • nothinrandom

    nothinrandom - 2017-06-06

    So what I've done is:

    VAR_INPUT
    iStatus: POINTER TO ARRAY[1..8] OF WORD;
    END_VAR

    On the function block's input, I put in %IW10. Issue is that only the first word is accessible. The rest are not.

    Not sure how to solve this. Any comments? Thanks

     
  • Comingback4u

    Comingback4u - 2017-06-07

    Taking a guess here but what if you tried passing in something like:
    VAR
    aInputs AT %IW10 : ARRAY[1..8] OF WORD;
    END VAR

    Then pass in ADR(aInputs) to the function block.

     
  • nothinrandom

    nothinrandom - 2017-06-07

    Comingback4u hat geschrieben:
    Taking a guess here but what if you tried passing in something like:
    VAR
    aInputs AT %IW10 : ARRAY[1..8] OF WORD;
    END VAR
    Then pass in ADR(aInputs) to the function block.

    Hey Comingback4u,

    Thanks for replying. That's very close, but I'm actually referring to passing an initial address and the FB handles the rest.

    Let's say inside the function block I have:
    VAR_INPUT
    iStatus: POINTER TO ARRAY[1..8] OF WORD;
    END_VAR

    When I call this function block, I can pass in something like %IW11. The function block should be able to recognize and evaluate information for an array of 8 words starting at %IW11...[%IW10,%IW11,%IW12...%IW17].

    I can then deference using iStatus^[1], iStatus^[2], etc to do something with information. Hope this makes sense. Thanks

     

    Related

    Talk.ru: 1
    Talk.ru: 2

  • Comingback4u

    Comingback4u - 2017-06-07

    OK, doing it either way provides the same results from my tests but I was able to see the values of the inputs if I had update variables set to enable 1 or enable 2. If not then it was just garbage values. I'm not familiar with EtherNet/IP adapters but if it has something like input mapping where you can specify to update variables, see image, even if they aren't in your application try changing it to Enable 1 or Enable 2. If there isn't this option then I'm not sure and hope someone can provide an answer. I like learning this stuff.

    IMG: UpdateVars.PNG

     
  • Anonymous - 2017-06-07

    Originally created by: scott_cunningham

    The setting "use parent settings" on a fieldbus slave means it should use the setting from the master device. You can find the setting not in the fieldbus master, but in the device itself under the PLC settings tab.

    Regarding your initial question on linking an array to a memory location... Why not use the variables created in the IO mapping from your screenshot? Hard memory locations will change if you insert another fieldbus slave. You can also change the variable from a created one to one of your existing variables in your application.

    Here is a simple screenshot of an EtherCAT system. EtherNet/IP should be the similar.

    IMG: io_mapping.png

     
  • nothinrandom

    nothinrandom - 2017-06-09

    Hey Guys,

    Thank you both very much for your response! The whole purpose behind my thinking is so I can drop instances of my function block and just change the starting point address for each block. The FB will handle the rest of the task.

    @Comingback4u,
    I know right? It really weird if I set the pointer to array[] to the address (i.e. %IW10). For some reason, %IW11, 12, 13, etc are all grayed out, their values are all set to 0 and can't be updated. This is when I use "Use parent device setting". I'll update to Enabled1 or Enabled2 and test it out tomorrow. Maybe it's to prevent bad memory overwrite (similar to segmentation fault in C?). Yes, the option to name and link the variable is available. However, I'm trying to move away from this due to scalability. I can do manual mapping for 1 EtherNet/IP device, but imagine what if I have 10+ EtherNet/IP devices. I wouldn't want to have to map each address out in order to access the values.

    @scott_cunningham,
    Maybe it's different on my end, but the address (i.e. %IW10) doesn't change for that one module if I add in more EtherNet/IP devices. Even if I copy the module and rename it to something else different, the new module's address automatically updates to a different index of %IW. Just need to update IP address.

     
  • nothinrandom

    nothinrandom - 2017-06-10

    @Comingback4u,

    That was it. Changing from "Use parent device setting" to "Enabled 1" did the trick. Makes life much easier this way!

     
  • josepmariarams

    josepmariarams - 2017-06-11

    See l viewtopic.php?t=7861 l . There are some discussion abut it.

    From the memory space, the inouts have some memory space reserved ( by default 4k i think), and you can change it in project propwrties. If you are not going out of this space there could has not to be problems.

     

Log in to post a comment.