I am having strange issues with the initialization of variables while using a for loop and [*] Array. I added a video for the explanation. Wrong initiations at 1.22min, 1.31min, and 1.37min.
  VAR_INPUT   i_Record:DInt;     i_Position:DInt;    i_Info:Int;  /   i_State:UDT_PltEntryState;   END_VAR  VAR_OUTPUT   o_ReturnValue:INT;  //Status:Error/JobAction  END_VAR  VAR_IN_OUT   io_C:UDT_Constants;  //Constants:Userconstants   io_PLT:ARRAY[*]OFUDT_Plt;   END_VAR  VAR_STAT   t_SearchStartPosition:DInt;     t_SearchEndPosition:DInt;    t_EntryId:Int;  //Entryindexcounter   t_ReturnValue:Int;  //StatusofJobAction   t_State:UDT_PltEntryState;  //Statestruct   Testpos:DINT:=0;   Testinfo:DINT:=0;  END_VAR
IF(i_Record<LOWER_BOUND(io_PLT, 1))
    OR(i_Record>UPPER_BOUND(io_PLT, 1))
  THEN
    o_ReturnValue :=io_C.ReturnValue.InvalidRecordId;
    RETURN; //Block end
  END_IF;
  t_ReturnValue :=io_C.ReturnValue.NoActionPresent;
 Â
  //Calculatestart-andend-positionofsearch-window
  t_SearchStartPosition :=i_Position;
  IFio_PLT[i_Record].Header.Displacement>0
  THEN
    t_SearchEndPosition :=i_Position-io_PLT[i_Record].Header.Displacement+1;
  ELSE
    t_SearchEndPosition :=i_Position;
  END_IF;
 Â
  //Searchfordatainsearch-window&writeStateifdatafound.
  FORt_EntryId :=1TOio_PLT[i_Record].Header.EntriesUsedBY1DO
    Testpos :=io_PLT[i_Record].Entry[t_EntryId].Position;
    Testinfo :=io_PLT[i_Record].Entry[t_EntryId].Info;
   Â
    IFTestpos<t_SearchEndPosition
    THEN
      EXIT; // Exit the for loop data can no longer be found
    END_IF;
   Â
    IFTestpos<=t_SearchStartPosition
      ANDTestpos>=t_SearchEndPosition
      ANDTestinfo=i_Info
    THEN
      t_State :=io_PLT[i_Record].Entry[t_EntryId].State;
     Â
      //MakeORstatementonallbits
      t_State.Claimed :=t_State.ClaimedORi_State.Claimed;
      t_State.Owner :=t_State.OwnerORi_State.Owner;
      t_State.OwnerDown :=t_State.OwnerDownORi_State.OwnerDown;
      t_State.OwnerHalted :=t_State.OwnerHaltedORi_State.OwnerHalted;
      t_State.OwnerRequest :=t_State.OwnerRequestORi_State.OwnerRequest;
      t_State.OwnerUp :=t_State.OwnerUpORi_State.OwnerUp;
      t_State.Pec :=t_State.PecORi_State.Pec;
      t_State.PecIo :=t_State.PecIoORi_State.PecIo;
      t_State.PecLatch :=t_State.PecLatchORi_State.PecLatch;
      t_State.PecRequest :=t_State.PecRequestORi_State.PecRequest;
      t_State.SparePecB03 :=t_State.SparePecB03ORi_State.SparePecB03;
      t_State.SpareW01 :=t_State.SpareW01ORi_State.SpareW01;
      t_State.SpareW02 :=t_State.SpareW02ORi_State.SpareW02;
      t_State.SpareW04 :=t_State.SpareW04ORi_State.SpareW04;
      t_State.SpareW08 :=t_State.SpareW08ORi_State.SpareW08;
      t_State.Virtual :=t_State.VirtualORi_State.Virtual;
     Â
      //Copytempbacktoentrystate
      io_PLT[i_Record].Entry[t_EntryId].State :=t_State;
     Â
      //Updatethereturnvalue
      t_ReturnValue :=io_C.ReturnValue.DataWrite;
      EXIT; // Exit the for loop update is done
    END_IF;
  END_FOR;
  //Updatethereturnvalue Â
  o_ReturnValue :=t_ReturnValue;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Update. I manage to find the solution. I need to reference to the [*] Array
Unforituannly, I am not really satisfied with this solution. Does anyone have a better suggestion for a solution?
For example, this might be solved with a singe line of code?
  TestPLTREF=io_PLT[i_Record];    TestEntry REF=TestPLT.Entry[t_EntryId];        Testpos:=TestEntry.Position;    Testinfo:=TestEntry.Info;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I am having strange issues with the initialization of variables while using a for loop and [*] Array. I added a video for the explanation. Wrong initiations at 1.22min, 1.31min, and 1.37min.
Codesys Version 3.5 SP9 Patch 5
https://youtu.be/FAjKp9R6okQ
@Update. I manage to find the solution. I need to reference to the [*] Array
Unforituannly, I am not really satisfied with this solution. Does anyone have a better suggestion for a solution?
For example, this might be solved with a singe line of code?