Codesys Instantiation Help

Hi,


Has anyone ever done indirect addressing /instantiation in CodeSys 3.5?


I have an application where I have a lot of similar objects.(Valves, Pumps, instruments) etc. I've built the function blocks but can't for the life of me figure out how to instantiate them in CodeSys visualisation.


Any links or sample projects would be greatly appreciated.


Thanks
 
Hi,
Has anyone ever done indirect addressing /instantiation in CodeSys 3.5?
No sure whether this can help. I wrote a Codesys program to test three devices that my company developed. The devices work in EtherCAT, EtherNet/IP and PROFINET IO. The cyclic data or PDO is the same for the three protocols. I did a visualization that can select the device so the visualization shows the value of the selected device on the same screen, by means of indirect addressing.

First I defined some global variables, based on some user-defined data type, and as you can see the variables are mapped to actual IO. The I defined two pointers, one for the input and one for the output user-defined data type.
Code:
    AdvInpEIP       AT %ID0    :    T_LSM_InAdv;
    LSM_DatOutEIP   AT %QW0    :    T_LSM_Out;
    
    AdvInpPN        AT %IB184  :    T_LSM_InAdv;
    LSM_DatOutPN    AT %QB4    :    T_LSM_Out;
    
    AdvInpECAT      AT %IB368  :     T_LSM_InAdv;
    LSM_DatOutEC    AT %QB8    :     T_LSM_Out;
    
    pAdvInp            : POINTER TO T_LSM_InAdv;
    pLSM_DatOut        : POINTER TO T_LSM_Out;

    b_EIP_Selected        : BOOL := FALSE;
    b_PN_Selected        : BOOL := FALSE;
    b_EC_Selected        : BOOL := TRUE;
In one of the programs, the following happens, while in the visualizations I am using the pointers, not the actual variables. The functions below starting with T_ are rising triggers.

Code:
     T_Profi(CLK := GVL.b_PN_Selected);
    IF T_Profi.Q THEN
        GVL.pAdvInp            := ADR( GVL.AdvInpPN );
        GVL.pLSM_DatOut        := ADR( GVL.LSM_DatOutPN );
        GVL.b_EIP_Selected         := FALSE;
        GVL.b_EC_Selected        := FALSE;
    END_IF
    
    T_EIP(CLK := GVL.b_EIP_Selected);
    IF T_EIP.Q THEN
        GVL.pAdvInp            := ADR( GVL.AdvInpEIP );
        GVL.pLSM_DatOut        := ADR( GVL.LSM_DatOutEIP );
        GVL.b_PN_Selected         := FALSE;
        GVL.b_EC_Selected        := FALSE;
    END_IF

    T_ECAT(CLK := GVL.b_EC_Selected);
    IF T_ECAT.Q THEN
        GVL.pAdvInp            := ADR( GVL.AdvInpECAT );
        GVL.pLSM_DatOut        := ADR( GVL.LSM_DatOutEC );
        GVL.b_PN_Selected         := FALSE;
        GVL.b_EIP_Selected        := FALSE;
    END_IF
Finally, in the visualization, you need to address the text variables as, for example "GVL.pAdvInp^.STS._16iVALNUMDATA":
Hope this is useful.

2022-06-03_CodesysVisu_IndirectRef.PNG.jpg
 

Similar Topics

Hi everyone, I'm New here I am currently working on a personal/learning project involving industrial communication and experimenting with a...
4
Replies
227
Views
Hi everyone! I'm not going to lie and claim this is my work at all or that I was the one to figure this out. Definitely all ChatGPT lol. But I...
1
Replies
214
Views
I asked this question in a CODESYS forum, but didn't get any replies , as I don't know how busy that forum is. Was wondering if anyone here could...
4
Replies
434
Views
Hi, I'm completely new to CODESYS so I'm guessing this is a basic error in my HMI Visualisation. When I try to go online with my Simulation, I get...
2
Replies
299
Views
I need Codesys v2.3 and eCockpit "the Programming software of WAGO". do you have installation files?
5
Replies
635
Views
Top