123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- namespace MinicsUI.AlarmHandler;
- public class AlarmRealtime(Hardwares hardwares, Alarms alarms)
- {
- public bool InsertAlarm(byte mini8Index, byte channelIndex, double current)
- {
- if (!hardwares.Mini8s.TryGetValue(mini8Index, out Mini8Info? mini8) || mini8 is null)
- return false;
- if (!hardwares.Mini8Channels.TryGetValue(mini8Index, out var channels) || channels is null)
- return false;
- if (!channels.TryGetValue(channelIndex, out Channel? channel) || channel is null)
- return false;
- AlarmInfo alarmInfo = new()
- {
- Mini8Index = mini8.Index,
- EventTime = DateTime.Now,
- AlarmLevel = AlarmLevel.Error,
- AlarmMini8 = mini8.Name,
- AlarmChannel = channel.Name,
- ChannelName = channel.Name,
- ChannelIndex = channel.ChannelIndex,
- AlarmDetail = $"Current Temperature: {current:0.00}℃ Caps: {channel.Caps}℃ Floor: {channel.Floor}℃"
- };
- try
- {
- Application.Current?.Dispatcher?.Invoke(() =>
- {
- if (alarms is null)
- return;
- if (!alarms.DisplayAlarm.ContainsKey(mini8.Index))
- alarms.DisplayAlarm[mini8.Index] = [];
- alarms.DisplayAlarm[mini8.Index][channel.ChannelIndex] = alarmInfo;
- });
- }
- catch
- {
- }
- return true;
- }
- public bool CancelAlarm(byte mini8, byte channel)
- {
- try
- {
- if (Application.Current is null)
- return false;
- Application.Current.Dispatcher.Invoke(() =>
- {
- if (!alarms.DisplayAlarm.TryGetValue(mini8, out var channels) || channels is null)
- return;
- channels.Remove(channel);
- if (channels.Count == 0)
- alarms.DisplayAlarm.Remove(mini8);
- });
- }
- catch
- {
- }
- return true;
- }
- public bool InsertTcBrocken(byte mini8Index, byte channelIndex)
- {
- if (!hardwares.Mini8s.TryGetValue(mini8Index, out Mini8Info? mini8) || mini8 is null)
- return false;
- if (!hardwares.Mini8Channels.TryGetValue(mini8Index, out var channels) || channels is null)
- return false;
- if (!channels.TryGetValue(channelIndex, out Channel? channel) || channel is null)
- return false;
- AlarmInfo alarmInfo = new()
- {
- Mini8Index = mini8.Index,
- EventTime = DateTime.Now,
- AlarmLevel = AlarmLevel.Error,
- AlarmMini8 = mini8.Name,
- AlarmChannel = channel.Name,
- ChannelName = channel.Name,
- ChannelIndex = channel.ChannelIndex,
- AlarmDetail = $"Tc Broken"
- };
- Application.Current.Dispatcher.Invoke(() =>
- {
- if (!alarms.DisplayAlarm.ContainsKey(mini8.Index))
- alarms.DisplayAlarm[mini8.Index] = [];
- alarms.DisplayAlarm[mini8.Index][channel.ChannelIndex] = alarmInfo;
- });
- return true;
- }
- }
|