Studio 5000 code doubt

kuppe35

Member
Join Date
Nov 2020
Location
italy
Posts
15
hi all,
I'm working on Studio5000, structured text language.
I have several buildings and for one of each several BOOL alarms in an array ("Alm_building1[]" for example).
I need to create a BOOL variable, one for each buildings, that tells me if there's at least one alarm at 1 in that precise building.
How can I do this?
 
Welcome to the forum!


Have you made any effort to solve this on your own yet? This forum has a tradition of not solving homework assignments or similar, even if they are real tasks.


Show your work and then you get free advice.


Ciao!
 
thanks for the reply. I was thinking about:

-Aux_Int:LOCAL INT
-counter:LOCAL INT
-Alm_Summary:GLOBAL BOOL

//building 1 cabinet 1

Aux_Int:=0;
For counter:= 0 to #Alarms_cabinet1 do;
Aux_Int := Aux_Int + Alm_Building1[counter];
end_for;
if (Aux_Int>0) then
Alm_Summary:=1;
else
Alm_Summary:=0;
end_if;

The problem is that the array "Alm_Building1[]" is of BOOL and the program doesn't let me sum BOOL with an INT
 
thanks for the reply. I was thinking about:...

The problem is that the array "Alm_Building1[]" is of BOOL and the program doesn't let me sum BOOL with an INT


Well done! Except for (perhaps necessary) limitations that you note the language/compiler implementation, your logic is sound.


N.B. There are almost certainly some syntax errors in what follows.


In keeping with that approach, how about this:

Code:
if Alm_Building1[counter] then
  Aux_Int := Aux_Int + 1;
end_if;
inside the loop, or even more simply



Code:
Alm_Summary := 0;
for ... do;
  Alm_Summary := Alm_Summary OR Alm_Buklding1[counter];
[COLOR=Blue]  if Alm_Summary then[/COLOR]
[COLOR=Blue]    EXIT;[/COLOR]
[COLOR=Blue]  end_if;[/COLOR]
end_for;
to eliminate the variable Alm_Int, since it only needs to detect the first triggered alarm, not count all of them.


Another approach:

Code:
counter := #Alarms_Building1;

REPEAT
    counter = counter - 1;
UNTIL counter = 0 OR Alm_Building1[counter]
END_REPEAT;

 
Alm_Summary = Alm_Building1[counter];
Is it possible to move all of the alarms for each building into one (or more) 32-bit integers? the the code becomes summa



Code:
Alm_Summary1 := Alm_Building1_bits_[COLOR=Red][B][I]0[/I][/B][/COLOR] != 0;


/* and possibly this as well for more than 32 alarms */

Alm_Summary1 := Alm_Summary1 OR Alm_Building1_bits_[COLOR=red][I][B]1[/B][/I][/COLOR] != 0;
Alm_Summary1 := Alm_Summary1 OR Alm_Building1_bits_[COLOR=red][I][B]2[/B][/I][/COLOR] != 0;
...
Or, if there are fewer than 33 buildings, then the integer array has M members, where M is the maximum number of alarms in any building, and member N of the integer array contains the Alarms N for all buildings, and you look at bit K (0 to 31) in all members of the array, and then you don't have to code a loop for each building.
 
Last edited:
This is great, thank you very much ! :D
Do you know if there's some instruction to know the number of elements in the array like in java "array[].lenght " ?
This way I'd have the second limit for the counter in the FOR loop.
 
This is great, thank you very much ! :D
Do you know if there's some instruction to know the number of elements in the array like in java "array[].lenght " ?
This way I'd have the second limit for the counter in the FOR loop.

If I understand this correctly, look at the SIZE instruction
 
You could convert your bool array to a DINT(S) and write to the bits and an alarm is present if the DINT(S) > 0.

Nice and simple.
 
You could convert your bool array to a DINT(S) and write to the bits and an alarm is present if the DINT(S) > 0.

Nice and simple.


That wouldn't work if bit 31 was on, as the number would be negative. The test needs to be DINT(S) <> 0

But there's no getting away from the fact that BOOL Arrays, are not very friendly, you can't do much with them at all.

But if the BOOL Array is made a member of a UDT, you can then COP (or CPS) it into a DINT array of the same size, and you can do a whole lot more with DINT Arrays than you can with BOOL Arrays.

One way to detect a bit (or bits) ON, is to SUM the DINTs and test for a non-zero result. Ah, but there is no SUM instruction, no problem : AVG the DINT array and MUL by the length. But again, you will get caught out by the fact that DINTs are signed, so a +nnn in one DINT, and a -nnn in another will make the average zero, and hence the SUM will be zero also, even though there's loads of bits on.

If you have to know specifically which bit (or bits) are ON, most people just loop through the DINT array looking for non-zero elements, then loop through each non-zero DINT to find which bit is on. The equivalent bit index in the BOOL array would then be (DINT index * 32) + Bit index.

Unfortunately not available in Structured Text language, (but there's no reason you couldn't program an AOI in Ladder), is an instruction called DDT (Diagnostic Detect). This instruction is capable of recording all bit positions that differ from a "reference" array, but be aware that if you want to capture all the differences you will need a Result array of DINTs the same size as your original BOOL array. Of course the reference array could be written into, for example to say "this alarm has been acknowledged". The possibilities are endless.
 

Similar Topics

Does anyone know about the timeline for ACM support for the Library Designer in v36? Just wondering since the most recent version of ACM seems...
Replies
0
Views
216
Hi I have hms-en2mb-r module . When i configure and go online the module is faulted with error code 16#0009 and addition code 16#0001. Is there...
Replies
2
Views
731
Curious if anybody has any documentation or input on what this exactly does . Many times when I have a problem it is one of the first things tech...
Replies
3
Views
2,371
Hello everyone, any one knows how i can get the Error Code from the kinetix in the Studio?, i was looking on the CIP tags but theres no one that...
Replies
0
Views
1,076
Hi all, Anyone of you knows if it is possible to access the watchdog timer directly in my code somehow? I have formed the logic of replicating...
Replies
2
Views
1,623
Back
Top Bottom