Showing results 1 to 4 of 4

Thread: Passing variables to an array by reference

  1. #1
    Join Date
    09.02.2018
    Posts
    9

    Default Passing variables to an array by reference

    Hi all, 

    I want to group some variables from a PLC in an array so I can process them with the same logic by just iterating the array with straton. The problem is that when I operate the variables in the array the change is not reflected in the original variables. Is there a way to pass the variables to the array by reference instead of value?

    Thanks 

  2. #2
    Join Date
    08.12.2015
    Posts
    32

    Default Re: Passing variables to an array by reference

    Hello,

    If I understand well, first of all you want to rebuild an array of variables from your PLC, so if your PLC variables are MyVar1, MyVar2, MyVar3... You have something like:
    MyArray[0] := MyVar1;
    MyArray[1] := MyVar2;
    MyArray[2] := MyVar3
    ...
    Then the goal is to change only the variables in the array, right?
    And as soon as you force MyArray[1] (for example) then MyVar2 is also updated?

    Then... This is not possible :/
    You have to force MyVar2 so the array is updated.

    But maybe there is another way to reach what you want to do!
    Is it what I described or... Not at all?

    Thank you,
    Regards,
    Anthony

  3. #3
    Join Date
    09.02.2018
    Posts
    9

    Default Re: Passing variables to an array by reference

    Hello, 

    Yes that's what I want to do. I thought that I could get the behavior I want by creating a function block and instantiate it multiple times with different inputs and outputs, but they don't work independently. Is there a way tho achieve that?

    Thanks 

  4. #4
    Join Date
    08.12.2015
    Posts
    32

    Beitrag Re: Passing variables to an array by reference

    Hello,

    Ok then...
    Speaking about Function Blocks...
    You can probably achieve this goal!

    The idea is to pass every parameters (the array and the variables from the PLC) to an User Define Function Block (UDFB).
    These parameters must be declared as INOUT so they can be forced in both ways.
    Then, depending if the variable is read from the PLC or forced via the array, what the UDFB is doing is different.

    I tried with 4 values.
    If the value is forced by the PLC, then it is stored in the array:



    If the value is forced from the Array (via the spy-list for example) then it is stored in the original value:



    I attached the project.
    If you are using straton Editor (the standalone Editor) then you can unzip the attached folded and open it doing:
    File > Add Existing Project > From zip

    In zenon, click on "zenon Logic (IEC61131-3)" on the left, then right-click in the zenon Logic area and "Import External zenon Logic Project", then select the unzipped folder.

    I hope it helps,
    Of course this is only an idea and a short program developed in order to do a simple test, maybe this is not optimized etc...
    Anthony

    Attached Thumbnails Attached Thumbnails FromPLC.png   FromArray.png  
    Attached Files Attached Files

Similar Threads

  1. Array and licensed I/O variables
    By florian in forum zenon Supervisor
    Replies: 1
    Last Post: 2nd June 2015, 07:35
  2. Passing ALC color between projects of multiserver model
    By stolyarov_as in forum zenon Energy Edition
    Replies: 3
    Last Post: 10th July 2013, 02:51
  3. How to reference zenrt32.tbl in VS?
    By jens1199 in forum VSTA
    Replies: 5
    Last Post: 28th September 2010, 12:53
  4. Empty Cross Reference List
    By mastr in forum zenon Supervisor
    Replies: 3
    Last Post: 2nd June 2009, 15:49
  5. Replies: 4
    Last Post: 29th September 2008, 10:44

Tags for this Thread

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •