Explorar el Código

IOT上报修改

master
pry hace 2 años
padre
commit
aafaeabb0e
Se han modificado 10 ficheros con 230 adiciones y 57 borrados
  1. +28
    -0
      HBLConsole.Attribute/HardwareStatusAttribute.cs
  2. +30
    -10
      HBLConsole.Business/IotReport.cs
  3. +6
    -1
      HBLConsole.Factory/SimpleFactory.cs
  4. +15
    -0
      HBLConsole.Interface/IHardwareStatus.cs
  5. +22
    -0
      HBLConsole.MORKS/Alarm.cs
  6. +4
    -2
      HBLConsole.MORKS/Control_MORKS.cs
  7. +19
    -0
      HBLConsole.MORKS/HardwareStatus.cs
  8. +38
    -0
      HBLConsole/ViewModel/AlarmViewModel.cs
  9. +55
    -31
      HBLConsole/ViewModel/MainViewModel.cs
  10. +13
    -13
      HBLConsole/ViewModel/VariableMonitorViewModel.cs

+ 28
- 0
HBLConsole.Attribute/HardwareStatusAttribute.cs Ver fichero

@@ -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; }
}
}

+ 30
- 10
HBLConsole.Business/IotReport.cs
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 6
- 1
HBLConsole.Factory/SimpleFactory.cs Ver fichero

@@ -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;
}
}
}
}


+ 15
- 0
HBLConsole.Interface/IHardwareStatus.cs Ver fichero

@@ -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
{
}
}

+ 22
- 0
HBLConsole.MORKS/Alarm.cs Ver fichero

@@ -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; }
}
}

+ 4
- 2
HBLConsole.MORKS/Control_MORKS.cs Ver fichero

@@ -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");


+ 19
- 0
HBLConsole.MORKS/HardwareStatus.cs Ver fichero

@@ -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; }
}
}

+ 38
- 0
HBLConsole/ViewModel/AlarmViewModel.cs Ver fichero

@@ -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();


+ 55
- 31
HBLConsole/ViewModel/MainViewModel.cs Ver fichero

@@ -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)


+ 13
- 13
HBLConsole/ViewModel/VariableMonitorViewModel.cs Ver fichero

@@ -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; }
//}
}

Cargando…
Cancelar
Guardar