Automatic assignment of instances

2011-01-19
2021-04-26
  • rahulnshinde

    rahulnshinde - 2011-01-19

    Device
    |-Drive
    | ^---Type1
    | ^---Type2
    | ^---Type3
    | ^---Type4
    |
    |-IO
    | ^---Type1
    | ^---Type2

    Hi,
    I have the product line as mentioned above. I have 4 types of drive devices and 2 types of IO devices.
    Please note that the number of each device may vary as per my PLC configuration.

    I wish to declare in my program a global variable as below:

    VAR
    device : Array [1..MAX_NO_OF_DEVICE] of Device ;
    END_VAR

    Is it possible that I can assign an individual type of device to the indexed element.

    For e.g.
    device[1] is (Drive > Type1)
    device[2] is (Drive > Type4)
    device[3] is (Drive > Type3)
    device[4] is (IO > Type2)
    device[5] is (IO> Type1)

    Regards,
    Rahul.

     

    Related

    Talk.ru: 1
    Talk.ru: 2
    Talk.ru: 3
    Talk.ru: 5

  • shooter

    shooter - 2011-01-23

    no impossible as a declaration is not dynamic.
    however you can compile it with a variable in the compile list.

     
  • Andreaz

    Andreaz - 2011-01-24

    Yes this is very possible indeed using the new OOP features in V3:

    Create a interface called IDevice and add a method Update to that interface (and the other methods you'd need ) and then create a few function blocks implementing the interface and the interface methods.

    FUNCTION_BLOCK FB_Drive1 IMPLEMENTS IDevice
    METHOD Update
    

    Zitat:
    VAR_GLOBAL
    Drive1: FB_Drive1;
    Drive2: FB_Drive2;

    IO1: FB_IO1;    
    Devices: ARRAY[0..9] OF IDevice;
    

    END_VAR

    Devices[0]:= Drive1;
    Devices[1]:= Drive2;
    Devices[2]:= IO1;
    FOR I:= 0 TO 2 DO
    Β  Β Devices[0].Update();
    END_FOR
    
     

    Related

    Talk.ru: 1
    Talk.ru: 2

  • lothar

    lothar - 2011-02-07

    Hi Andreaz,

    your suggestion sounds interesting but i still wasn't succeessfull getting this to run. I'm afraid I havn't understood the example. Could you please explain this a little bit more?

    best regards
    Lothar

     

Log in to post a comment.