@@ -0,0 +1,28 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace HBLConsole.Attributes | |||
{ | |||
public class HardwareStatusAttribute : Attribute | |||
{ | |||
public HardwareStatusAttribute(string describe, string address) | |||
{ | |||
Describe = describe; | |||
this.Address = address; | |||
} | |||
/// <summary> | |||
/// 描述 | |||
/// </summary> | |||
public string Describe { get; set; } | |||
/// <summary> | |||
/// 地址 | |||
/// </summary> | |||
public string Address { get; set; } | |||
} | |||
} |
@@ -96,6 +96,7 @@ namespace HBLConsole.Factory | |||
public IControl control { get; set; } | |||
public IGvl GVL { get; set; } | |||
public IAlarm Alarm { get; set; } | |||
public IHardwareStatus HardwareStatus { get; set; } | |||
public ControlAbstract controlAbstract { get; set; } | |||
/// <summary> | |||
@@ -116,6 +117,7 @@ namespace HBLConsole.Factory | |||
ActionManage.GetInstance.Register(new Action<object>((o) => { control?.SimOrder(o); }), "SimOrder"); | |||
ActionManage.GetInstance.Register(new Action<object>((o) => { control?.IotBroadcast(o); }), "IotBroadcast"); | |||
ConnectHelper.GetInstance.Init(); | |||
ActionManage.GetInstance.Send("监控数据初始化"); | |||
//GetControlBase(); | |||
} | |||
@@ -142,12 +144,15 @@ namespace HBLConsole.Factory | |||
{ | |||
GVL = (item.GetValue(control)) as IGvl; | |||
GvlName = item.Name; | |||
} | |||
else if (inters.Name.Equals("IAlarm")) | |||
{ | |||
Alarm = (item.GetValue(control)) as IAlarm; | |||
} | |||
else if (inters.Name.Equals("IHardwareStatus")) | |||
{ | |||
HardwareStatus = (item.GetValue(control)) as IHardwareStatus; | |||
} | |||
} | |||
} | |||
} | |||
@@ -0,0 +1,15 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace HBLConsole.Interface | |||
{ | |||
/// <summary> | |||
/// 硬件状态接口 | |||
/// </summary> | |||
public interface IHardwareStatus | |||
{ | |||
} | |||
} |
@@ -0,0 +1,22 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using HBLConsole.Interface; | |||
using HBLConsole.Attributes; | |||
namespace HBLConsole.MORKS | |||
{ | |||
public class Alarm : IAlarm | |||
{ | |||
[Alarm("报警测试1")] | |||
public bool AlarmTest1 { get; set; } | |||
[Alarm("报警测试2")] | |||
public bool AlarmTest2 { get; set; } | |||
[Alarm("报警测试3")] | |||
public bool AlarmTest3 { get; set; } | |||
} | |||
} |
@@ -1,5 +1,4 @@ | |||
//#define test | |||
using BPA.Message; | |||
using BPA.Message; | |||
using HBLConsole.Communication; | |||
using HBLConsole.Factory; | |||
using HBLConsole.Interface; | |||
@@ -22,6 +21,9 @@ namespace HBLConsole.MORKS | |||
public class Control_MORKS : IControl | |||
{ | |||
GVL_MORKS mORKS = new GVL_MORKS(); | |||
Alarm alarm = new Alarm(); | |||
HardwareStatus hardwareStatus = new HardwareStatus(); | |||
public void Init() | |||
{ | |||
ActionManage.GetInstance.Register(new Action(() => { WriteRecipeBoms(); }), "recipeBom"); | |||
@@ -0,0 +1,19 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using HBLConsole.Interface; | |||
using HBLConsole.Attributes; | |||
namespace HBLConsole.MORKS | |||
{ | |||
public class HardwareStatus : IHardwareStatus | |||
{ | |||
[HardwareStatus("输入状态", "I0.0")] | |||
public bool Input1 { get; set; } | |||
[HardwareStatus("输出状态", "Q0.0")] | |||
public bool OutPut1 { get; set; } | |||
} | |||
} |
@@ -9,6 +9,8 @@ using System.Windows; | |||
using HBLConsole.Model; | |||
using HBLConsole.Service; | |||
using HBLConsole.Business; | |||
using HBLConsole.Factory; | |||
using System.Threading; | |||
namespace HBLConsole.ViewModel | |||
{ | |||
@@ -65,6 +67,42 @@ namespace HBLConsole.ViewModel | |||
} | |||
public static void AlarmMonitoring() | |||
{ | |||
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); | |||
}), "报警检测监控"); | |||
} | |||
private void GetHistoryAlarm() | |||
{ | |||
var data = Sqlite<Alarm>.GetInstance.Base.ToList(); | |||
@@ -15,6 +15,8 @@ using HBLConsole.Model; | |||
using HBLConsole.Business; | |||
using HBLConsole.Factory; | |||
using HBLConsole.Attributes; | |||
using BPA.Message.IOT; | |||
using System.Collections.ObjectModel; | |||
namespace HBLConsole.ViewModel | |||
{ | |||
@@ -32,44 +34,66 @@ namespace HBLConsole.ViewModel | |||
OrderCount = orderStatusLists.Count; | |||
Thread.Sleep(1000); | |||
}), "界面状态监控"); | |||
AlarmMonitoring(); | |||
//AlarmMonitoring(); | |||
Init(); | |||
} | |||
private void AlarmMonitoring() | |||
private void Init() | |||
{ | |||
ThreadManage.GetInstance.StartLong(new Action(() => | |||
ActionManage.GetInstance.Register(new Action(() => | |||
{ | |||
if (SimpleFactory.GetInstance.Alarm != null) | |||
AlarmViewModel.AlarmMonitoring(); | |||
VariableMonitorViewModel.AddMonitorData(); | |||
VariableMonitorViewModel.UpdateValue(); | |||
ThreadManage.GetInstance.StartLong(new Action(() => | |||
{ | |||
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); | |||
}), "报警检测监控"); | |||
//节点状态上报 | |||
IotReport.GetInstance.SendNodeStatusMessage(Tools.JsonConvertTools(new IOTNode<ObservableCollection<VariableMonitor>> { data = VariableMonitorViewModel.VariableMonitors })); | |||
Thread.Sleep(1000); | |||
}), "IOT数据上报"); | |||
}), "监控数据初始化"); | |||
} | |||
//private void AlarmMonitoring() | |||
//{ | |||
// 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); | |||
// }), "报警检测监控"); | |||
//} | |||
public RelayCommand<object> NavChangedCommand { get; set; } | |||
private void DoNavChanged(object obj) | |||
@@ -22,13 +22,13 @@ namespace HBLConsole.ViewModel | |||
WindowName = "变量监控"; | |||
} | |||
static VariableMonitorViewModel() | |||
{ | |||
AddMonitorData(); | |||
UpdateValue(); | |||
} | |||
//static VariableMonitorViewModel() | |||
//{ | |||
// AddMonitorData(); | |||
// UpdateValue(); | |||
//} | |||
private static void AddMonitorData() | |||
public static void AddMonitorData() | |||
{ | |||
if (SimpleFactory.GetInstance.GVL == null) return; | |||
foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties()) | |||
@@ -129,7 +129,7 @@ namespace HBLConsole.ViewModel | |||
} | |||
} | |||
private static void UpdateValue() | |||
public static void UpdateValue() | |||
{ | |||
if (SimpleFactory.GetInstance.GVL == null) return; | |||
ThreadManage.GetInstance.StartLong(new Action(() => | |||
@@ -171,8 +171,8 @@ namespace HBLConsole.ViewModel | |||
} | |||
} | |||
IotReport.GetInstance.SendNodeStatusMessage(Tools.JsonConvertTools(new IOTNode { data = VariableMonitors })); | |||
//IotReport.GetInstance.SendNodeStatusMessage(Tools.JsonConvertTools(new IOTNode { data = VariableMonitors })); | |||
Thread.Sleep(1000); | |||
}), "变量监控"); | |||
} | |||
@@ -181,8 +181,8 @@ namespace HBLConsole.ViewModel | |||
public static ObservableCollection<VariableMonitor> VariableMonitors { get; set; } = new ObservableCollection<VariableMonitor>(); | |||
} | |||
public class IOTNode | |||
{ | |||
public ObservableCollection<VariableMonitor> data { get; set; } | |||
} | |||
//public class IOTNode | |||
//{ | |||
// public ObservableCollection<VariableMonitor> data { get; set; } | |||
//} | |||
} |