Hello good sirs. I'm currently working on a project where I'm simulating a patientmonitor. Im using background worker to update the values every second. I got a treshhold on the values receives, so lets say that pulse = 140, its > 120, so it sends an alarm message to the sentral. All this works, but the problem is that i keep on sending "alarm on" messages. How can i fix, so that if the value stays the same, it only sends one message?

Some of the code:

private int _pulse

public int Pulse { get { return _pulse; } set { _pulse = value; } }

public void Alarm()
{
    MinMaxPulse= ("0-120");
    string[] splittp = MinMaxPulse.Split('-');
    int minpulse = Int32.Parse(splittp[0]);
    int maxpulse = Int32.Parse(splittp[1]);
    if (_pulse > maxpulse || _pulse < minpulse)
            {
                alarmPulse = true;
                alarmPActive = true; 
                SendAlarmOnToSentral(Alarm.PULSE);

            }
            else
            {
                alarmPuls = false;
                if (alarmPActive == true && alarmPulse == false)
                {
                    SendAlarmStopToSentral(Alarm.PULSE);
                    alarmPactiv = false;
                }

            }

}

Regards, asotop

Recommended Answers

All 7 Replies

Add a boolean that is set to true once the alarm is triggered, and adjust the alarm if-statements accordingly to only run when it is false?

Once the value falls back into the threshold it can be reset ready for the next time?

Don't know if it is of any imortance but on line 20 you have alarmPuls instead of what it should be alarmPulse

Just a typo, the code works. But I didnt manage to fix it with your answer Mikey.

The problem is that, as long as the value keeps updating, it keeps sending a message. We're using a simulator which the teacher provided, and updating it with backgroundworker. I just want 1 message if the alarm went on.

Solved the problem! :D Thanks anyway.

Good to hear you solved it, what was the solution?

Hey Mikey, this was the solution. Added a counter :

private int p_counter = 0;
if (_pulse > maxpulse || _pulse < minpulse)
{
                alarmPulse = true;
                alarmPActive = true;
                if(p_counter < 1)
                {
                    SendAlarmToSentral(Alarm.PULSE);
                    p_counter++;
                }

}
            else
            {
                alarmPulse = false;
                if (alarmPActive == true && alarmPulse == false)
                {
                    SendAlarmStopToSentral(Alarm.PULSE);
                    alarmPActive = false;
                    p_counter = 0;
                }    
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.