Переглянути джерело

报警监控

样式分支
pry 2 роки тому
джерело
коміт
f16828098a
15 змінених файлів з 247 додано та 191 видалено
  1. +57
    -56
      BPASmartClient.Device/Alarm.cs
  2. +12
    -20
      BPASmartClient.Device/AlarmHelper.cs
  3. +1
    -0
      BPASmartClient.Device/BPASmartClient.Device.csproj
  4. +15
    -10
      BPASmartClient.Device/BaseDevice.cs
  5. +16
    -0
      BPASmartClient.Device/IDevice.cs
  6. +1
    -1
      BPASmartClient.Helper/Sqlite.cs
  7. +12
    -12
      BPASmartClient.IoT/DataVClient.cs
  8. +1
    -4
      BPASmartClient.Message/MessageLog.cs
  9. +61
    -5
      BPASmartClient.MorkS/Alarm.cs
  10. +28
    -10
      BPASmartClient.MorkS/Control_Morks.cs
  11. +30
    -71
      BPASmartClient.ViewModel/AlarmViewModel.cs
  12. +2
    -0
      BPASmartClient/App.xaml.cs
  13. +2
    -0
      BPASmartClient/Control/AlarmView.xaml
  14. +3
    -2
      BPASmartClient/DeviceInfo.xml
  15. +6
    -0
      BPASmartClient/MainWindow.xaml

+ 57
- 56
BPASmartClient.Device/Alarm.cs Переглянути файл

@@ -1,56 +1,57 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Device
{
public class Alarm
{
/// <summary>
/// ID
/// </summary>
[Key]
public int Id { get { return _mId; } set { _mId = value; } }
private int _mId;

/// <summary>
/// 编号ID
/// </summary>
public int NumId { get { return _mNumId; } set { _mNumId = value; } }
private int _mNumId;


/// <summary>
/// 日期
/// </summary>
public string Date { get { return _mDate; } set { _mDate = value; } }
private string _mDate;

/// <summary>
/// 时间
/// </summary>
public string Time { get { return _mTime; } set { _mTime = value; } }
private string _mTime;

/// <summary>
/// 报警信息
/// </summary>
public string Info { get { return _mInfo; } set { _mInfo = value; } }
private string _mInfo;

/// <summary>
/// 报警值
/// </summary>
public string Value { get { return _mValue; } set { _mValue = value; } }
private string _mValue;

/// <summary>
/// 报警等级
/// </summary>
public string Grade { get { return _mGrade; } set { _mGrade = value; } }
private string _mGrade;
}
}
//using System;
//using System.Collections.Generic;
//using System.ComponentModel.DataAnnotations;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;


//namespace BPASmartClient.Device
//{
// public class Alarm
// {
// /// <summary>
// /// ID
// /// </summary>
// [Key]
// public int Id { get { return _mId; } set { _mId = value; } }
// private int _mId;

// /// <summary>
// /// 编号ID
// /// </summary>
// public int NumId { get { return _mNumId; } set { _mNumId = value; } }
// private int _mNumId;


// /// <summary>
// /// 日期
// /// </summary>
// public string Date { get { return _mDate; } set { _mDate = value; } }
// private string _mDate;

// /// <summary>
// /// 时间
// /// </summary>
// public string Time { get { return _mTime; } set { _mTime = value; } }
// private string _mTime;

// /// <summary>
// /// 报警信息
// /// </summary>
// public string Info { get { return _mInfo; } set { _mInfo = value; } }
// private string _mInfo;

// /// <summary>
// /// 报警值
// /// </summary>
// public string Value { get { return _mValue; } set { _mValue = value; } }
// private string _mValue;

// /// <summary>
// /// 报警等级
// /// </summary>
// public string Grade { get { return _mGrade; } set { _mGrade = value; } }
// private string _mGrade;
// }
//}

+ 12
- 20
BPASmartClient.Device/AlarmHelper.cs Переглянути файл

@@ -1,4 +1,7 @@
using System;
using BPASmartClient.Helper;
using BPASmartClient.Message;
using BPASmartClient.Model;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
@@ -48,7 +51,7 @@ namespace BPASmartClient.Device
{
Alarm tempAlarm = new Alarm()
{
NumId = Alarms.Count,
NumId = Alarms.Count + 1,
Date = DateTime.Now.ToString("yyyy/MM/dd"),
Grade = alarmLevel.ToString(),
Info = AlarmInfo,
@@ -56,22 +59,15 @@ namespace BPASmartClient.Device
Time = DateTime.Now.ToString("HH:mm:ss"),
};

//tempAlarm.Id = IotReport.GetInstance.HttpAddAlarm(new BPA.Message.API请求.AlarmTable
//{
// AlarmTime=DateTime.Now,
// AlarmType= tempAlarm.Grade,
// AlarmMessage= tempAlarm.Info,
// AlarmVla= tempAlarm.Value,
// ClientId= InternetInfo.ClientId.ToString()
//});

//Sqlite<Alarm>.GetInstance.Base.Add(tempAlarm);
Sqlite<Alarm>.GetInstance.Base.Add(tempAlarm);

if (Alarms.FirstOrDefault(p => p.Info == AlarmInfo) == null)
{
Alarms.Add(tempAlarm);
if (AddAction != null) AddAction(AlarmInfo);//添加报警通知
if (ChangeAction != null) ChangeAction();//更改报警通知
Alarms.Insert(0, tempAlarm);
for (int i = 0; i < Alarms.Count; i++) { Alarms.ElementAt(i).NumId = i + 1; }
AddAction?.Invoke(AlarmInfo);//添加报警通知
ChangeAction?.Invoke();//更改报警通知
MessageLog.GetInstance.AddDeviceAlarmLogShow(tempAlarm.Info, Guid.NewGuid().ToString());
}
}

@@ -85,11 +81,7 @@ namespace BPASmartClient.Device
if (result != null)
{
Alarms.Remove(result);
//IotReport.GetInstance.HttpDeleteAlarm(result.Id);
for (int i = 0; i < Alarms.Count; i++)
{
Alarms.ElementAt(i).NumId = i + 1;
}
for (int i = 0; i < Alarms.Count; i++) { Alarms.ElementAt(i).NumId = i + 1; }
if (RemoveAction != null) RemoveAction(AlarmInfo);
if (ChangeAction != null) ChangeAction();
}


+ 1
- 0
BPASmartClient.Device/BPASmartClient.Device.csproj Переглянути файл

@@ -12,6 +12,7 @@

<ItemGroup>
<ProjectReference Include="..\BPASmartClient.Helper\BPASmartClient.Helper.csproj" />
<ProjectReference Include="..\BPASmartClient.Model\BPASmartClient.Model.csproj" />
<ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" />
</ItemGroup>



+ 15
- 10
BPASmartClient.Device/BaseDevice.cs Переглянути файл

@@ -2,6 +2,7 @@
using BPA.Message.Enum;
using BPASmartClient.Helper;
using BPASmartClient.Message;
using BPASmartClient.Model;
using BPASmartClient.Peripheral;
using System;
using System.Collections.Concurrent;
@@ -101,6 +102,9 @@ namespace BPASmartClient.Device

public Action<int, object> AddErrorAction { get; set; }
public Action<int, object> DeleteErrorAction { get; set; }
public List<Alarm> alarms { get; set; } = new List<Alarm>();
public IAlarm InterfaceAlarm { get; set; }
public AlarmHelper alarmHelper { get; set; } = new AlarmHelper();

#endregion

@@ -217,9 +221,10 @@ namespace BPASmartClient.Device
}
else if (faces.Name == "IAlarm")
{
IAlarm alarm = item.GetValue(this) as IAlarm;
AlarmHelper alarmHelper = new AlarmHelper();
alarmHelper.AddAction = new Action<string>((s) =>
InterfaceAlarm = item.GetValue(this) as IAlarm;
//IAlarm alarm = item.GetValue(this) as IAlarm;
//AlarmHelper alarmHelper = new AlarmHelper();
alarmHelper.AddAction += new Action<string>((s) =>
{
var res = alarmHelper.Alarms.FirstOrDefault(p => p.Info == s);
if (res != null)
@@ -234,7 +239,7 @@ namespace BPASmartClient.Device
AddErrorAction?.Invoke(DeviceId, obj);
}
});
alarmHelper.RemoveAction = new Action<string>((s) =>
alarmHelper.RemoveAction += new Action<string>((s) =>
{
var res = Error.FirstOrDefault(p => p.GetType().GetProperty("Text").GetValue(p).ToString() == s);
if (res != null && Error.Contains(res))
@@ -245,7 +250,7 @@ namespace BPASmartClient.Device
});
ThreadManage.GetInstance().StartLong(new Action(() =>
{
AlarmMonitoring(alarm, alarmHelper);
AlarmMonitoring();
Thread.Sleep(500);
}), $"报警检测监控:{DeviceId}");
}
@@ -261,17 +266,17 @@ namespace BPASmartClient.Device
/// </summary>
/// <param name="alarm"></param>
/// <param name="alarmHelper"></param>
private void AlarmMonitoring(IAlarm alarm, AlarmHelper alarmHelper)
private void AlarmMonitoring()
{
if (alarm == null) return;
foreach (var item in alarm.GetType().GetProperties())
if (InterfaceAlarm == null) return;
foreach (var item in InterfaceAlarm.GetType().GetProperties())
{
var res = item.GetValue(alarm);
var res = item.GetValue(InterfaceAlarm);
if (res != null && res is bool blen)
{
if (item.CustomAttributes.Count() > 0 && item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0)
{
var info = item.CustomAttributes.ElementAt(0)?.ConstructorArguments.ElementAt(0).Value;
var info = item.GetCustomAttribute<AlarmAttribute>().AlarmInfo;
if (info != null) alarmHelper.EdgeAlarm(blen, info.ToString());
}
}


+ 16
- 0
BPASmartClient.Device/IDevice.cs Переглянути файл

@@ -1,4 +1,5 @@
using BPA.Message.Enum;
using BPASmartClient.Model;
using BPASmartClient.Peripheral;
using System;
using System.Collections.Concurrent;
@@ -43,6 +44,21 @@ namespace BPASmartClient.Device
/// </summary>
List<VariableMonitor> variableMonitors { get; set; }

/// <summary>
/// 设备报警信息集合
/// </summary>
List<Alarm> alarms { get; set; }

/// <summary>
/// 接口报警对象
/// </summary>
IAlarm InterfaceAlarm { get; set; }

/// <summary>
/// 报警实体
/// </summary>
AlarmHelper alarmHelper { get; set; }

/// <summary>
/// 是否忙碌
/// </summary>


+ 1
- 1
BPASmartClient.Helper/Sqlite.cs Переглянути файл

@@ -39,7 +39,7 @@ namespace BPASmartClient.Helper
SaveChanges();
}

public object GetData()
public List<T> GetData()
{
Database.EnsureCreated();
return Base.ToList();


+ 12
- 12
BPASmartClient.IoT/DataVClient.cs Переглянути файл

@@ -39,7 +39,7 @@ namespace BPASmartClient.IoT
ProductKey = System.Configuration.ConfigurationManager.AppSettings["ProductKey"].ToString();
DeviceSecret = System.Configuration.ConfigurationManager.AppSettings["DeviceSecret"].ToString();
StartupMode = System.Configuration.ConfigurationManager.AppSettings["StartupMode"].ToString();
BroadcastPubTopic= System.Configuration.ConfigurationManager.AppSettings["BroadcastPubTopic"].ToString();
BroadcastPubTopic = System.Configuration.ConfigurationManager.AppSettings["BroadcastPubTopic"].ToString();
}
#endregion

@@ -68,7 +68,7 @@ namespace BPASmartClient.IoT
/// <summary>
/// key值
/// </summary>
public Dictionary<string,string> keyValues = new Dictionary<string, string>();
public Dictionary<string, string> keyValues = new Dictionary<string, string>();
#endregion

#region API调用
@@ -105,7 +105,7 @@ namespace BPASmartClient.IoT
string id = string.Empty;
try
{
if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable!=null)
if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null)
{
logTable.ClientId = ClientId;
logTable.devicename = DeviceDataV.deviceTable.devicename;
@@ -147,7 +147,7 @@ namespace BPASmartClient.IoT
}
else
{
MessageLog.GetInstance.ShowEx(message);
MessageLog.GetInstance.ShowEx(message);
}
}
else
@@ -161,7 +161,7 @@ namespace BPASmartClient.IoT
}
Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.ForEach(device =>
{
device.AddErrorAction+= AddErrorAction;
device.AddErrorAction += AddErrorAction;
device.DeleteErrorAction += DeleteErrorAction;
});
}
@@ -173,7 +173,7 @@ namespace BPASmartClient.IoT
{
ThreadManage.GetInstance().StartLong(new Action(() =>
{
if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null)
if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null)
{
List<object> dataVNode = new List<object>();
Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.ForEach(device =>
@@ -215,7 +215,7 @@ namespace BPASmartClient.IoT
private void AddErrorAction(int Devid, object obj)
{
string id = Guid.NewGuid().ToString();
HttpAddAlarm(new AlarmTable
HttpAddAlarm(new AlarmTable
{
AlarmTime = GetPropertyValue(obj, "Time").ToString(),
AlarmType = GetPropertyValue(obj, "Type").ToString(),
@@ -224,8 +224,8 @@ namespace BPASmartClient.IoT
DeviceId = Devid.ToString(),
KeyID = id,
});
keyValues[GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString()] =id ;
MessageLog.GetInstance.AddDeviceAlarmLogShow(GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString(),id);
keyValues[GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString()] = id;
//MessageLog.GetInstance.AddDeviceAlarmLogShow(GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString(),id);

}

@@ -244,11 +244,11 @@ namespace BPASmartClient.IoT
AlarmType = GetPropertyValue(obj, "Type").ToString(),
AlarmMessage = GetPropertyValue(obj, "Text").ToString(),
AlarmVla = "告警",
DeviceId= Devid.ToString(),
DeviceId = Devid.ToString(),
KeyID = keyValues[message],
State="n"
State = "n"
});
MessageLog.GetInstance.DeleteDeviceAlarmLogShow(message, keyValues[message]);
//MessageLog.GetInstance.DeleteDeviceAlarmLogShow(message, keyValues[message]);

}
}


+ 1
- 4
BPASmartClient.Message/MessageLog.cs Переглянути файл

@@ -84,10 +84,7 @@ namespace BPASmartClient.Message
else
DPLogInfo[id] = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {DPLogInfo[id]}";
Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
if (DeviceProcessLogNotify != null) DeviceProcessLogNotify(id, info);
//Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
// //ExLogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {ExLogInfo}";
// if (DeviceProcessLogNotify != null) DeviceProcessLogNotify(id,info);
DeviceProcessLogNotify?.Invoke(id, info);
}

#endregion


+ 61
- 5
BPASmartClient.MorkS/Alarm.cs Переглянути файл

@@ -89,9 +89,17 @@ namespace BPASmartClient.MorkS
[Alarm("机器人通讯异常")]
public bool RobotMacCommunicateError { get; set; }

/// <summary>
/// 机器人通讯异常
/// PLC ---> M231.2
/// ModbusTcp --> 1581
/// </summary>
[Alarm("设备急停")]
public bool DeviceEstop { get; set; }

/// <summary>
/// 机器人初始化失败
/// PLC ---> M551.3
/// PLC ---> M231.3
/// ModbusTcp --> 1583
/// </summary>
[Alarm("机器人初始化失败")]
@@ -99,7 +107,7 @@ namespace BPASmartClient.MorkS

/// <summary>
/// 机器人急停
/// PLC ---> M551.4
/// PLC ---> M231.4
/// ModbusTcp --> 1584
/// </summary>
[Alarm("机器人急停")]
@@ -107,7 +115,7 @@ namespace BPASmartClient.MorkS

/// <summary>
/// 机器人不在远程模式
/// PLC ---> M551.5
/// PLC ---> M231.5
/// ModbusTcp --> 1585
/// </summary>
[Alarm("机器人不在远程模式")]
@@ -115,7 +123,7 @@ namespace BPASmartClient.MorkS

/// <summary>
/// 机器人伺服未就绪
/// PLC ---> M551.6
/// PLC ---> M231.6
/// ModbusTcp --> 1586
/// </summary>
[Alarm("机器人伺服未就绪")]
@@ -123,7 +131,7 @@ namespace BPASmartClient.MorkS

/// <summary>
/// 机器人本体异常
/// PLC ---> M551.7
/// PLC ---> M231.7
/// ModbusTcp --> 1587
/// </summary>
[Alarm("机器人本体异常")]
@@ -144,5 +152,53 @@ namespace BPASmartClient.MorkS
/// </summary>
[Alarm("煮面机右侧缺水报警")]
public bool RightLackWater { get; set; }

/// <summary>
/// 丝杆初始化失败
/// PLC ---> M232.2
/// ModbusTcp --> 1571
/// </summary>
[Alarm("丝杆初始化失败")]
public bool SvrewInitFail { get; set; }

/// <summary>
/// 转盘初始化失败
/// PLC ---> M232.3
/// ModbusTcp --> 1571
/// </summary>
[Alarm("转盘初始化失败")]
public bool TurntableInitFail { get; set; }

/// <summary>
/// 机器人初始化失败
/// PLC ---> M232.4
/// ModbusTcp --> 1571
/// </summary>
[Alarm("机器人初始化失败")]
public bool RobotInitFail { get; set; }

/// <summary>
/// 煮面机初始化失败
/// PLC ---> M232.5
/// ModbusTcp --> 1571
/// </summary>
[Alarm("煮面机初始化失败")]
public bool NoodleCookerInitFail { get; set; }

/// <summary>
/// 推碗1步进推杆初始化失败
/// PLC ---> M232.6
/// ModbusTcp --> 1571
/// </summary>
[Alarm("推碗1步进推杆初始化失败")]
public bool PushBowlInitFail1 { get; set; }

/// <summary>
/// 推碗2步进推杆初始化失败
/// PLC ---> M232.7
/// ModbusTcp --> 1571
/// </summary>
[Alarm("推碗2步进推杆初始化失败")]
public bool PushBowlInitFail2 { get; set; }
}
}

+ 28
- 10
BPASmartClient.MorkS/Control_Morks.cs Переглянути файл

@@ -88,7 +88,11 @@ namespace BPASmartClient.MorkS
{
if (peripheralStatus.ContainsKey(key))
{
action((bool[])peripheralStatus[key]);
if (peripheralStatus[key] is bool[] bools)
{
action?.Invoke(bools);
}
//action((bool[])peripheralStatus[key]);
}
}

@@ -106,6 +110,7 @@ namespace BPASmartClient.MorkS
alarm.NoodleMacCommunicateError = bools[7];
alarm.DosingMacCommunicateError = bools[8];
alarm.RobotMacCommunicateError = bools[9];
alarm.DeviceEstop = bools[10];
alarm.RobotInitError = bools[11];
alarm.RobotUrgentStop = bools[12];
alarm.RobotNotInRemoteMode = bools[13];
@@ -113,6 +118,12 @@ namespace BPASmartClient.MorkS
alarm.RobotSelfInException = bools[15];
alarm.LeftLackWater = bools[16];
alarm.RightLackWater = bools[17];
alarm.SvrewInitFail = bools[18];
alarm.TurntableInitFail = bools[19];
alarm.RobotInitFail = bools[20];
alarm.NoodleCookerInitFail = bools[21];
alarm.PushBowlInitFail1 = bools[22];
alarm.PushBowlInitFail2 = bools[23];
}));

GetStatus("M0.3", new Action<bool[]>((bools) =>
@@ -165,13 +176,13 @@ namespace BPASmartClient.MorkS
}
}));

EventBus.EventBus.GetInstance().Publish(new ReadModel() { DeviceId = DeviceId, Address = "VW372", Length = 1 }, (o) =>
{
if (o != null && o.Length > 0 && o[0] is ushort value)
{
mORKS.TurntableFeedbackloc = value;
}
});
//EventBus.EventBus.GetInstance().Publish(new ReadModel() { DeviceId = DeviceId, Address = "VW372", Length = 1 }, (o) =>
//{
// if (o != null && o.Length > 0 && o[0] is ushort value)
// {
// mORKS.TurntableFeedbackloc = value;
// }
//});
}

/// <summary>
@@ -229,8 +240,8 @@ namespace BPASmartClient.MorkS
public override void MainTask()
{
mORKS.AllowRun = mORKS.InitComplete;
//IsHealth = mORKS.Error && mORKS.InitComplete;
IsHealth = true;
IsHealth = mORKS.Error && mORKS.InitComplete;
//IsHealth = true;

if (mORKS.AllowRun)
{
@@ -382,6 +393,13 @@ namespace BPASmartClient.MorkS
}
}

//补料中检测
if (RTrig.GetInstance("mORKS.Feeding").Start(mORKS.Feeding))
{
mORKS.AllowTakeNoodle = false;
mORKS.TakeNoodleInterlock = false;
}

//转台到位检测
if (RTrig.GetInstance("TurntableInPlace").Start(mORKS.TurntableMoveInPlace && mORKS.CurrentLoc == mORKS.TurntableFeedbackloc))
{


+ 30
- 71
BPASmartClient.ViewModel/AlarmViewModel.cs Переглянути файл

@@ -11,6 +11,7 @@ using Microsoft.Toolkit.Mvvm.ComponentModel;
using BPASmartClient.Device;
using BPASmartClient.Helper;
using BPASmartClient.Business;
using BPASmartClient.Model;

namespace BPASmartClient.ViewModel
{
@@ -26,7 +27,7 @@ namespace BPASmartClient.ViewModel
}
if (ControlButText == "开始查询")
{
var lists = Sqlite<Alarm>.GetInstance.Base.ToList();
var lists = Sqlite<Alarm>.GetInstance.GetData();
var res = lists.Where(p => Convert.ToDateTime(p.Date) >= StartDateTime && Convert.ToDateTime(p.Date) <= EndDateTime).ToList();
if (res != null)
{
@@ -63,87 +64,45 @@ namespace BPASmartClient.ViewModel
return;
}
});
AlarmMonitoring();
}


public static void AlarmMonitoring()
public void AlarmMonitoring()
{
AlarmInfos.Clear();
Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.ForEach(device =>
{
device.AddErrorAction = new Action<int, object>((id, o) =>
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
AlarmInfos.Add(new Alarm()
{
NumId = AlarmInfos.Count,
Date = DateTime.Now.ToString("yyyy/MM/dd"),
Grade = o?.GetType()?.GetProperty("Type")?.GetValue(o)?.ToString(),
Info = o?.GetType()?.GetProperty("Text")?.GetValue(o)?.ToString(),
Time = DateTime.Now.ToString("HH:mm:ss"),
});
}));
});

device.DeleteErrorAction = new Action<int, object>((id, o) =>
device.alarmHelper.Alarms.ForEach((item) => { AlarmInfos.Add(item); });
device.alarmHelper.AddAction += new Action<string>((s) =>
{
var info = o?.GetType()?.GetProperty("Text")?.GetValue(o)?.ToString();
var res = AlarmInfos.FirstOrDefault(p => p.Info == info);
if (res != null) AlarmInfos.Remove(res);
var res = device.alarmHelper.Alarms.FirstOrDefault(p => p.Info == s);
if (res != null) Application.Current.Dispatcher.Invoke(new Action(() => { AlarmInfos.Insert(0, res); }));
});
});



//ThreadManage.GetInstance.StartLong(new Action(() =>
//{
// if (SimpleFactory.GetInstance.Alarm != null)
// {
// foreach (var item in SimpleFactory.GetInstance.Alarm.GetType().GetProperties())
// {
// var res = item.GetValue(SimpleFactory.GetInstance.Alarm);
// if (res != null)
// {
// if (res is bool blen)
// {
// if (item.CustomAttributes.Count() > 0)
// {
// if (item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0)
// {
// var info = item.CustomAttributes.ElementAt(0)?.ConstructorArguments.ElementAt(0).Value;
// if (info != null)
// {
// App.Current.Dispatcher.Invoke(new Action(() =>
// {
// AlarmHelper.GetInstance.EdgeAlarm(blen, info.ToString());
// }));
// }
// }
// }
// }
// }
// }
// }
// Thread.Sleep(500);
//}), "报警检测监控");
device.alarmHelper.RemoveAction += new Action<string>((s) =>
{
var res = AlarmInfos.FirstOrDefault(p => p.Info == s);
if (res != null) Application.Current.Dispatcher.Invoke(new Action(() => { AlarmInfos.Remove(res); }));
});
});
}

private void GetHistoryAlarm()
{
//var data = Sqlite<Alarm>.GetInstance.Base.ToList();
//if (data != null)
//{
// AlarmHelper.GetInstance.HistoryAlarms.Clear();
// foreach (var item in data)
// {
// int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days;
// if (day == 0)
// {
// AlarmHelper.GetInstance.HistoryAlarms.Add(item);
// }
// }
//}
var data = Sqlite<Alarm>.GetInstance.GetData();
if (data != null)
{
HistoryAlarm.Clear();
foreach (var item in data)
{
int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days;
if (day == 0)
{
HistoryAlarm.Add(item);
}
}
}
}

public RelayCommand SwitchCommand { get; set; }
@@ -191,9 +150,9 @@ namespace BPASmartClient.ViewModel
private DateTime _mEndDateTime = DateTime.Now;


public static ObservableCollection<Alarm> AlarmInfos { get; set; } = new ObservableCollection<Alarm>();
public ObservableCollection<Alarm> AlarmInfos { get; set; } = new ObservableCollection<Alarm>();

public static ObservableCollection<Alarm> HistoryAlarm { get; set; } = new ObservableCollection<Alarm>();
public ObservableCollection<Alarm> HistoryAlarm { get; set; } = new ObservableCollection<Alarm>();

}
}

+ 2
- 0
BPASmartClient/App.xaml.cs Переглянути файл

@@ -114,6 +114,7 @@ namespace BPASmartClient
private void DataSave()
{
Json<KeepDataBase>.Save();
Sqlite<Alarm>.GetInstance.Save();
}

/// <summary>
@@ -122,6 +123,7 @@ namespace BPASmartClient
private void DataRead()
{
Json<KeepDataBase>.Read();
Task.Run(new Action(() => { Sqlite<Alarm>.GetInstance.GetData(); }));
}




+ 2
- 0
BPASmartClient/Control/AlarmView.xaml Переглянути файл

@@ -121,6 +121,7 @@

<Button
Width="140"
Height="30"
Background="#FF19B7EC"
Command="{Binding ControlCommand}"
Content="{Binding ControlButText}"
@@ -137,6 +138,7 @@

<Button
Width="140"
Height="30"
Margin="20,0,0,0"
Background="#FF19B7EC"
Command="{Binding SwitchCommand}"


+ 3
- 2
BPASmartClient/DeviceInfo.xml Переглянути файл

@@ -55,13 +55,14 @@
</Peripherals>
</Device>-->

<Device Name="Morks" Module="BPASmartClient.MorkS.Control_Morks" DeviceId="33">
<Device Name="Morks" Module="BPASmartClient.MorkS.Control_Morks" DeviceId="100">
<Peripherals>
<Peripheral Module="BPASmartClient.PLC.PLCMachine">
<Parameters>
<IpAddress>127.0.0.1</IpAddress>
<Port>502</Port>
<PLCReadAddress>M,M230.0,24;M,M0.3,3;M,M100.0,16;M,M235.0,1;M,M102.0,7;M,M103.0,6;VW,VW372,1</PLCReadAddress>
<!--<PLCReadAddress>M,M230.0,24;M,M0.3,3;M,M100.0,16;M,M235.0,1;M,M102.0,7;M,M103.0,6;VW,VW372,1</PLCReadAddress>-->
<PLCReadAddress>M,M230.0,24</PLCReadAddress>
</Parameters>
</Peripheral>
</Peripherals>


+ 6
- 0
BPASmartClient/MainWindow.xaml Переглянути файл

@@ -108,6 +108,12 @@
Header="设备监视"
Tag="DeviceMonitorView" />
<Separator />
<MenuItem
Click="MenuItem_Click"
FontSize="12"
Header="报警监视"
Tag="AlarmView" />
<Separator />
<MenuItem
Click="MenuItem_Click"
FontSize="12"


Завантаження…
Відмінити
Зберегти