Siemens S7 TIA - Long If Statements with DB for Alarms

Con1924

Member
Join Date
Apr 2021
Location
UK
Posts
2
Does anyone have a good way of examining each element of a DB and if one is true then set a bit?

I have used structures in my DB, this would probably be easier with an array and array pointer but then I would have to write all my alarms to a datatype.

I have lots of alarms in a DB and if any one of those is true I want to set a bit that sounds a sounder.

I assume SCL is the way to go with this.

So far I have just been using long IF OR THEN statements, for example

IF Alarm1 Or
Alarm2 Or
Alarm 3 ......
Then
InAlarm := True;
Else
InAlarm := False;
 
Make first another DB which is array of bools and same lenght on bytes than your original DB.
Then copy original DB to new.
Then loop througt bool arrays and set bit.
 
I have lots of alarms in a DB and if any one of those is true I want to set a bit that sounds a sounder.


Is the DB optimised or not, does the DB contain alarm bits exclusively - give us a clue about lots - 1000, 10000, 100000?
 
It's currently optimised but I don't need to keep it that way. Yes it only contains alarms but are currently organised in structs. At the moment it's only a few 100's but could grow.

I also have some alarms in other DB's, I have a block for Profisafe VFD's that also has some alarm output tags. I assume I'd have to add these in extra. Have the code multiple times for alarms in different DB's. Then have them all set a global bit.

I'm trying to find a more robust solution that's quicker to implement on future, larger projects.
 
Dont know if possible but if you can get all data from the datablock into one large array, maybe you could pass this to a FC as variant. Then compare the IN variant with a similar sized TEMP variant that is 0. If not equal you have alarm. I have no idea if this is possible, just brainstorming.. :)
 
So you mean you have something like
if "DB_a".alarm_b or "DB_a".alarm_c or "DB_d".alarm_d ...
?


assuming those alarms are modeled as contiguous bits in each DB*, I would think the idea proposed earlier to copy the bits to an equivalent-sized array of ints, without regard to datatype, and then check for non-zero values in those ints, 16 or 32 or 64 bits at a time; it's still clumsy, but at least less so by an order and a half of magnitude or so.



What is the ratio of alarms to DBs?


* it appears that is what optimized means.
 
Last edited:
If your alarm bits are inside a struct of a DB, you can use the Serialize function to create a byte array out of the whole struct, and loop through the byte array using a For / Do ...
This works for "optimized" data blocks.
 

Similar Topics

I am currently am in a PLC class and need urgent help on how the ladder logic would be laid out. I understand how to get the traffic lights to...
Replies
19
Views
435
Hello, If the date on the license manager of tia Portal has expired, can I still work with it? or is this just to keep the program up to date...
Replies
7
Views
204
Does anyone know why my one string is displaying this way? It is causing issues with my HMI displaying it.
Replies
4
Views
265
Context: PLC= S7-1212C, HMI=KTP1200 Basic. Hi again, When the "REPORT" button is pressed (on a different screen), it takes the operator to the...
Replies
7
Views
659
Context: PLC= S7-1212C, HMI=KTP1200 Basic. Hi, The operator has reported that, from time-to-time, when he presses the "Generate Report" button...
Replies
5
Views
461
Back
Top Bottom