当信号从1和0不断变化的机器发出时,如何保持警报保持红色?
我有一个代码,用于指示机器发出的警报,当机器遇到问题时,机器的警报会闪烁以显示...
当警报闪烁时,输出将在1和0之间不断变化当然我的视觉C#会写一个if else语句来显示闹钟响了,如果alarm=1,那么闹钟图片会变成红色,否则alarm=0,那么闹钟图片会变成绿色。
但是当接收到来自机器的信号时,它在1和0之间闪烁,并且我在视觉c#中的警报图片也会在红色和绿色之间不断变化,我该怎么办,这样当警报闪烁时,我的警报图片在视觉上c# 一直显示红色?因为一旦警报响起,我也需要存储在数据库中。 这是我的 if else 语句...
if (bn4 == "1" || bn4 == "0")
{
if ((cmdstop4 == 1) || bn4 == "0")
{
alarm.Stop();
pictureBox6.Show();
pictureBox14.Hide();
bn4 = "0";
}
if (bn4 == "1")
{
alarm.PlayLooping();
pictureBox14.Show();
pictureBox6.Hide();
}
}
i have a code that using to indicate the alarm from a machine, and the alarm of the machine will be flash to show when the machine facing some problem...
when it flashing the alarm, the output will be keep changing between 1 and 0. and of course my visual C# will write a if else statement to show that the alarm is ringing, if alarm=1, then alarm picture will become red, else alarm=0, then alarm picture will become green.
but when receive the signal from the machine was flash between 1 and 0, and my alarm picture at the visual c# will also keep changing between red and green, what could i do so that when the alarm is flashing, and my alarm picture in visual c# just keep showing red? because i need to store in the database too once alarm is sound.
here is my if else statement...
if (bn4 == "1" || bn4 == "0")
{
if ((cmdstop4 == 1) || bn4 == "0")
{
alarm.Stop();
pictureBox6.Show();
pictureBox14.Hide();
bn4 = "0";
}
if (bn4 == "1")
{
alarm.PlayLooping();
pictureBox14.Show();
pictureBox6.Hide();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用哨兵值来确定之前是否已触发警报。它不需要很复杂,只需将一个 int 设置为 0(如果警报关闭)和 1(如果警报已触发)。
You could use a sentinal value to determine if the alarm has been previously triggered. It doesn't need to be complex, just an int set to 0 if the alarm is off and 1 if the alarm has been triggered.