CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Sun May 26, 2019 2:02 pm

All times are UTC+01:00

Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Nov 02, 2018 11:15 am 

Joined: Tue Oct 02, 2018 12:26 pm
Posts: 9

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

 Plt  : ARRAY[0..300] OF UDT_Plt;  

      i_Record : DInt;   
      i_Position : DInt; 
      i_Info : Int;   /
      i_State : UDT_PltEntryState; 

      o_ReturnValue : INT;   // Status: Error/Job Action

      io_C : UDT_Constants;   // Constants: User constants
      io_PLT : ARRAY[*] OF UDT_Plt; 

      t_SearchStartPosition : DInt;   
      t_SearchEndPosition : DInt; 
      t_EntryId : Int;   // Entry index counter
      t_ReturnValue : Int;   // Status of Job Action
      t_State : UDT_PltEntryState;   // State struct
     Testpos : DINT := 0;
     Testinfo : DINT :=0;

IF (i_Record < LOWER_BOUND(io_PLT, 1))
       OR (i_Record > UPPER_BOUND(io_PLT, 1))
       o_ReturnValue := io_C.ReturnValue.InvalidRecordId;
       RETURN; //Block end
   t_ReturnValue := io_C.ReturnValue.NoActionPresent;
   // Calculate start- and end-position of search-window
   t_SearchStartPosition := i_Position;
   IF io_PLT[i_Record].Header.Displacement > 0
       t_SearchEndPosition := i_Position - io_PLT[i_Record].Header.Displacement + 1;
       t_SearchEndPosition := i_Position;
   // Search for data in search-window & write State if data found.
   FOR t_EntryId := 1 TO io_PLT[i_Record].Header.EntriesUsed BY 1 DO
      Testpos := io_PLT[i_Record].Entry[t_EntryId].Position;
      Testinfo := io_PLT[i_Record].Entry[t_EntryId].Info;
       IF Testpos < t_SearchEndPosition
           EXIT; // Exit the for loop data can no longer be found
       IF Testpos <= t_SearchStartPosition
           AND Testpos >= t_SearchEndPosition
           AND Testinfo = i_Info

           t_State := io_PLT[i_Record].Entry[t_EntryId].State;
           // Make OR statement on all bits
           t_State.Claimed := t_State.Claimed OR i_State.Claimed;
           t_State.Owner := t_State.Owner OR i_State.Owner;
           t_State.OwnerDown := t_State.OwnerDown OR i_State.OwnerDown;
           t_State.OwnerHalted := t_State.OwnerHalted OR i_State.OwnerHalted;
           t_State.OwnerRequest := t_State.OwnerRequest OR i_State.OwnerRequest;
           t_State.OwnerUp := t_State.OwnerUp OR i_State.OwnerUp;
           t_State.Pec := t_State.Pec OR i_State.Pec;
           t_State.PecIo := t_State.PecIo OR i_State.PecIo;
           t_State.PecLatch := t_State.PecLatch OR i_State.PecLatch;
           t_State.PecRequest := t_State.PecRequest OR i_State.PecRequest;
           t_State.SparePecB03 := t_State.SparePecB03 OR i_State.SparePecB03;
           t_State.SpareW01 := t_State.SpareW01 OR i_State.SpareW01;
           t_State.SpareW02 := t_State.SpareW02 OR i_State.SpareW02;
           t_State.SpareW04 := t_State.SpareW04 OR i_State.SpareW04;
           t_State.SpareW08 := t_State.SpareW08 OR i_State.SpareW08;
           t_State.Virtual := t_State.Virtual OR i_State.Virtual;
           // Copy temp back to entry state
           io_PLT[i_Record].Entry[t_EntryId].State := t_State;
           // Update the return value
           t_ReturnValue := io_C.ReturnValue.DataWrite;
           EXIT; // Exit the for loop update is done
   // Update the return value   
   o_ReturnValue := t_ReturnValue;

Industrial automation student from The Netherlands

PostPosted: Fri Nov 02, 2018 1:39 pm 

Joined: Tue Oct 02, 2018 12:26 pm
Posts: 9
@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?
   TestPLT REF= io_PLT[i_Record];
      TestEntry  REF= TestPLT.Entry[t_EntryId];
      Testpos := TestEntry.Position;
      Testinfo := TestEntry.Info;

Industrial automation student from The Netherlands

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC+01:00

Who is online

Users browsing this forum: Andreas Kehrer and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited