CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Tue Sep 25, 2018 5:53 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Thu May 24, 2018 9:05 am 
Offline

Joined: Mon May 21, 2018 2:08 pm
Posts: 2
Hello everybody,

I would like to create a loop in codesys which would check DI status and then activate DO. For this experiment I'm using wago 750-831 controller and wago 750-330 bacnet coupler.

In my mind it should look like this (I'm puting this example just to show what I have in mind):

VAR

Input_1,Input_2, Input_3;
Output_1, Output_2, Output_3;
i:INT;

END VAR

FOR i:=1 TO 3 BY 1
DO
If Input_i = TRUE THEN;
Output_i = TRUE;
ELSE
Output_i:=FALSE;
END_IF
END_FOR

Basicly what I though I could do is to create string variable with CONCAT (varname:=CONCAT('Input_',INT_TO_STRING(i)) and then put it into IF but not as string but as variable name somehow. I couldn't find function or function block that would do that. Is it even posible?
I of course could do the whole page of IF and ELSE IF but I would like to use more "beutiful" solution than this. Keep in mind that these variables is phisical DI DO signals and Bacnet variables.


Top
   
PostPosted: Fri May 25, 2018 6:08 pm 
Offline

Joined: Tue Dec 03, 2013 11:52 pm
Posts: 89
Could you just use an array?
Code:
VAR
    aInput : ARRAY[1..IOMAXSIZE] OF BOOL;
    aOutput : ARRAY[1..IOMAXSIZE] OF BOOL;
    iCount : INT;
END_VAR
VAR_CONSTANT
    IOMAXSIZE : INT := 3;
END_VAR

FOR iCount := 1 TO IOMAXSIZE BY 1 DO
    aOutput[iCount] := aInput[iCount];
END_FOR


Top
   
PostPosted: Sat May 26, 2018 10:08 am 
Offline

Joined: Wed Dec 09, 2015 4:05 am
Posts: 49
I think I know what you mean but I'm not aware of a way to manipulate variable names dynamically.
I have applications like a number of compactors where the IOs are called something like Compactor1_xExtLimit but I have to hand over the IO to a function block call at some point.
An array won't help either because then you will have to assign the array element as the IO variable. Same Same but different, same amount of work.

Sent from my SM-G935F using Tapatalk


Top
   
PostPosted: Mon May 28, 2018 5:49 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 288
Maybe use REFERENCE TO BOOL like this:

RefDigIn:ARRAY(0..15) OF REFERENCE TO BOOL;
RefDigOut:ARRAY(0..15) OF REFERENCE TO BOOL;

Later, explicitly map you speaking variable and the ref array...

RefDigIn[0] := Input_0;
RefDigIn[1] := Input_1;

RefDigOut[0] := Output_0;
RefDigOut[1] := Output_1;

Then you can do you loop:

FOR I:= 0 TO 15 DO
RefDigOut[I] := RefDigIn[I];
END_FOR

It’s a little work, but if you really need to “roll through” the VARs, this can help.

_________________
Scott Cunningham
KEB America, Inc.
www.kebblog.com
www.kebamerica.com


Top
   
PostPosted: Mon May 28, 2018 7:26 am 
Offline

Joined: Wed Dec 09, 2015 4:05 am
Posts: 49
Scott but then he may simply map the variable straight into for example an array of bool or if it's more complex an array of struct. The work of allocating each input remains the same.

Sent from my SM-G935F using Tapatalk


Top
   
PostPosted: Mon May 28, 2018 11:59 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 288
You are stuck with the amount of work. CoDeSys doesn’t offer building a variable name dynamically except by array. I usually use generic arrays for the EtherCAT IO mapping, use speaking variable names in my code and then have one program that maps all of the generic names with the software names. This means I have doubled my variables usage space and added some CPU time, but then I have one place to see or adjust my hardware IO mapping. Customers sometimes decide to change wires or maybe a IO is damaged... easy change in the code. Just requires extra setup work in the beginning.

_________________
Scott Cunningham
KEB America, Inc.
www.kebblog.com
www.kebamerica.com


Top
   
PostPosted: Tue May 29, 2018 6:57 am 
Offline

Joined: Mon May 21, 2018 2:08 pm
Posts: 2
All of your answers were great, I'll probably try using arrays, I hope that extra work in the beginning will help me in the future project adjustments :)


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 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