SCL loop through bits

Join Date
Jul 2014
Location
Here
Posts
17
Hello again,

SCL struggles continue but this time I'm trying to scan for 0 statuses in an array of boolean variables. Any ideas how to implement this?
 
maybe something



FUNCTION FC100 : VOID
VAR_TEMP
i: INT;
END_VAR

VAR_INPUT
in1 : arr_data; //data to compare, UDT array of bool [1..100]

END_VAR

VAR_IN_OUT
bit_count : INT; //bit counter
END_VAR

VAR_OUTPUT
cmp : BOOL; //compare result

END_VAR


bit_count:=0;

FOR i:=1 TO 100 BY 1 DO

IF in1.data = false THEN

bit_count:=bit_count+1; //counting bits with false-state

END_IF;

IF bit_count >0 THEN //count >0, at least one bit is false
cmp:= true; //set bit

ELSE
cmp:=false; //all bits are are true

END_IF;

END_FOR;



END_FUNCTION


 
Last edited:
Lare: that's more or less what I tried earlier myself. My DB consists of couple integer values and then an array [0..100] of bool. How can I access the array of my struct loop through that in SCL?
 
(y)

Pseudocode have little typing error.

End_for should be before

If bit_count>0 then

otherwise "cmp" can have 0-status for onescan even that there is bits with "1" status on array.
 

Similar Topics

Dear expert. This is my first try to program scl code. The problem is that the while loop dosen't count up. Here is my code, i hope someone can...
Replies
4
Views
4,206
HI i would like to know how to get a variable that will store the amount of times a program has been executed. The issue is I have 3 DBs for 1 FB...
Replies
2
Views
105
Hi, I have an intermediate-advance knowledge of programming with TIA Porta in Ladder, would you recommend me to start learning SCL for it to...
Replies
11
Views
583
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
357
Hi everyone, I am new to this amazing world of PLC, well... I mean, in practice, since I already knew electronics, programming languages, IT, and...
Replies
7
Views
667
Back
Top Bottom