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):
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2018-05-28
Originally created by: scott_cunningham
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...
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2018-05-28
Originally created by: scott_cunningham
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
Could you just use an array?
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
Originally created by: scott_cunningham
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.
Related
Talk.ru: 1
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
Originally created by: scott_cunningham
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.
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