BH2114 Posted January 9, 2018 Share Posted January 9, 2018 I have an oil pump that takes 3 seconds to develop pressure. I need to mask the oil pressure = 0 for 5 seconds after the oil pump is powered on, then evaluate. I have this in a function, which works, except that the 5 second delay hangs the display. return=0 alarm normal return=1 Fires Alarm private a = main_lubepumpmon[0] // 1 indicates that the pump is powered on. private b = main_Oil_press[0] // 1 indicates that oil pressure is up. if(b==1) private c = 2 else private c = 0 endif private d = c+a delay(5) switch case (d==1) return 1 endcase switch case (d==3) return 0 endcase switch case (d==2) return 0 endcase switch case (d==0) return 0 endcase Obviously, I'm doing something wrong here. Link to comment Share on other sites More sharing options...
AzeoTech Posted January 11, 2018 Share Posted January 11, 2018 Are you calling this function from an Alarm Fire expression? If so, then yes, it will likely hang things. Alarm expressions are typically evaluated as channel data comes in. So, a delay in an alarm evaluation will cause a delay in channel processing, and a delay in channel processing can lead back to lags in the user interface. And by channel processing I mean Channel Events, Alarms, and Logging sets (which would be pretty hard to delay as the actual logging is done in a separate thread). You could turn off the alarm processing that occurs with channel processing and instead trigger alarm processing from a sequence. This is a good idea in general if you have a lot of alarms. But, its not really going to achieve what you want. It will just cause your alarm processing to slow by 5 seconds. These sort of things are much better dealt with using subsetting by time and time markers. So, use an event on the pump that looks for the the transition from off to on and when that occurs, set a global flag with the time. Something like: if (pumpStat[0] && !pumpStat[1]) pumpTurnOnTime = pumpStat.time[0] endif where pumpTurnOnTime is a global you declared elsewhere. Then, when evaluating the alarm, you can just look and see if the pump is on, and if it is more than 5 seconds after the turn on time. So, if you want to alarm if OilPressure == 0, but only if the pump is on and has been on for more than 5 seconds, the Alarm expression would just be: (OilPressure[0] == 0) && (pumpStat[0]) && (systime() - pumpTurnOnTime > 5) and the reset expression would be the inverse: (OilPressure[0] == 1) || (!pumpStat[0]) || (systime() - pumpTurnOnTime <= 5) Note of course I could just put !OilPressure[0] and OilPressure[0] if these are boolean, but I wasn't sure if it was a flag for oil pressure, or an actual pressure reading. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.