How to determine the type of a pointer indexed member

SiegeLion
2022-05-31
2022-06-02
  • SiegeLion - 2022-05-31

    How to determine the type of a pointer indexed member. I intend to use:

    TYPE DUT_DemoStruct :
    STRUCT
            Member_1: BOOL;
            Member_2: INT;
    END_STRUCT
    END_TYPE
    
    
    PROGRAM Prg_Main
    VAR
            DemoStructPointer:
            Obj_DemoStruct1: DUT_DemoStruct ;
            Obj_DemoStruct2: DUT_DemoStruct ;
            Obj_DemoStruct3: DUT_DemoStruct ;
            Demo_INT: INT;
            Index: INT;
            _pointer: POINTER TO DUT_DemoStruct;
    END_VAR
    
    
    FOR Index:=0 TO 5 DO
            IF _pointer[Index] THEN  //**whether the _pointer[Index] (pointer index member) is of type DUT_DemoStruct**
                _pointer[Index].Member_1:=TRUE;
            END_IF;
    END_FOR;
    

    In addition, Do you have any application cases for CheckPointer?

     
  • ludecus

    ludecus - 2022-05-31

    I don't understand your point.

    Please use the dereference of a pointer to address the variables.

    IF _pointer<>0 THEN  // check pointer has a reference
       _pointer^.Member_1 := TRUE; // access the variables by dereference
       _pointer^.Member_2 := 1;
    END_IF
    
     
  • SiegeLion - 2022-06-02

    H:
    Obviously misunderstood the question.
    This is to better implement the contracted part of the HMSD(Hierarchical Master-Slave Distribution) framework. For example, batch initialization of states.
    For example: if you want to implement batch initialization of objects of class Step, you only need to pass the pointer of the first Step to the initialization function, and the function will automatically search down according to the first pointer until it finds an object that is not of the Step class and stops searching. This process needs to be automated. To achieve such a function, you need the index of the pointer, and determine the type of the pointer index member.
    Ideal code:

    FUNCTION_BLOCK Exe_PalletShuttle EXTENDS Frame.Base_LocalScope
    VAR
        {attribute 'hide'}pointer_Step: POINTER TO Frame.Base_Step;
        {attribute 'hide'}step_Start: Frame.Base_Step;
    
        {attribute 'hide'}step_StartRecharg: Frame.Base_Step;
    
        {attribute 'hide'}step_LengthwaysMove_Start: Frame.Base_Step;
        {attribute 'hide'}step_LiftShuttleCyd_PutDown: Frame.Base_Step;
        {attribute 'hide'}step_LengthwaysMove_GoTarget: Frame.Base_Step;
        {attribute 'hide'}step_LengthwaysMove_End: Frame.Base_Step;
    
       {attribute 'hide'}step_WidthwaysMove_Start: Frame.Base_Step;
        {attribute 'hide'}step_LiftShuttleCyd_Uplift: Frame.Base_Step;
        {attribute 'hide'}step_WidthwaysMove_GoTarget: Frame.Base_Step;
        {attribute 'hide'}step_WidthwaysMove_End: Frame.Base_Step;
    
        {attribute 'hide'}step_UpliftPallet_Start: Frame.Base_Step;
        {attribute 'hide'}step_LiftPalletCyd_Uplift: Frame.Base_Step;
        {attribute 'hide'}step_UpliftPallet_End: Frame.Base_Step;   
    
        {attribute 'hide'}step_PutdownPallet_Start: Frame.Base_Step;
        {attribute 'hide'}step_LiftPalletCyd_Putdown: Frame.Base_Step;
        {attribute 'hide'}step_PutdownPallet_End: Frame.Base_Step;  
    
       {attribute 'hide'}step_End: Frame.Base_Step;
    
       {attribute 'hide'}VividerMark: BOOL;
    
       {attribute 'hide'}obj_PalletLiftCyd: Frame.Device_Actuator;
        {attribute 'hide'}obj_DiverterLiftCyd: Frame.Device_Actuator;
    END_VAR
    
    pointer_Step:= ADR(step_Start);
    InitialStepScope(FirstAdr:=pointer_Step );
    

    Feeling the current mechanism of pointer implementation, such a function seems to be difficult to achieve. Looking forward to the launch of the collection function.

     
    πŸ‘
    2

    Last edit: SiegeLion 2022-06-02

Log in to post a comment.