@@ -164,7 +164,7 @@ namespace BPASmartClient.DRCoffee | |||
{ | |||
status["Status"] = DrCoffeeStatus.Wait; | |||
status["AppStatus"] = DrCoffeeAppStatus.应用无状态; | |||
status["Warning"] = DrCoffeeWarning.无警告; | |||
status["Warning"] = DrCoffeeWarning.冲泡器未安装到位; | |||
status["Fault"] = DrCoffeeFault.无故障; | |||
} | |||
@@ -98,6 +98,10 @@ namespace BPASmartClient.Device | |||
/// 外设设备集合 | |||
/// </summary> | |||
private List<IPeripheral> peripherals; | |||
public Action<object> AddErrorAction { get; set; } | |||
public Action<object> DeleteErrorAction { get; set; } | |||
#endregion | |||
/// <summary> | |||
@@ -144,8 +148,43 @@ namespace BPASmartClient.Device | |||
foreach (var key in peripheral.GetAllStatus().Keys) | |||
{ | |||
peripheralStatus[key] = peripheral.GetAllStatus()[key]; | |||
if(TypeName!= "PLC.MorksMachine") | |||
if (TypeName != "PLC.MorksMachine") | |||
{ | |||
Status.Update($"{TypeName}.{key}", peripheral.GetAllStatus()[key]); | |||
} | |||
} | |||
} | |||
foreach (var item in Status.GetStatusT()) | |||
{ | |||
if (item.Name == "Warning" || item.Name == "Fault") | |||
{ | |||
if (item.Status != "无故障" && item.Status != "无警告" && item.Status != "未发生故障") | |||
{ | |||
var res = Error?.FirstOrDefault(p => p.GetType().GetProperty("Text").GetValue(p).ToString() == item.Ms); | |||
if (res == null) | |||
{ | |||
object obj = new | |||
{ | |||
Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), | |||
Type = item.Name == "Warning" ? "警告" : "故障", | |||
Text = item.Ms | |||
}; | |||
Error.Add(obj); | |||
AddErrorAction?.Invoke(obj); | |||
} | |||
} | |||
else | |||
{ | |||
var res = Error?.FirstOrDefault(p => p.GetType().GetProperty("Text").GetValue(p).ToString().Contains(item.id)); | |||
if (res != null) | |||
{ | |||
Error.Remove(res); | |||
DeleteErrorAction?.Invoke(res); | |||
} | |||
} | |||
} | |||
} | |||
Thread.Sleep(100); | |||
@@ -186,12 +225,16 @@ namespace BPASmartClient.Device | |||
{ | |||
var res = alarmHelper.Alarms.FirstOrDefault(p => p.Info == s); | |||
if (res != null) | |||
Error.Add(new | |||
{ | |||
object obj = new | |||
{ | |||
Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), | |||
Type = res.Grade, | |||
Text = res.Info | |||
}); | |||
}; | |||
Error.Add(obj); | |||
AddErrorAction?.Invoke(obj); | |||
} | |||
}); | |||
alarmHelper.RemoveAction = new Action<string>((s) => | |||
{ | |||
@@ -199,6 +242,7 @@ namespace BPASmartClient.Device | |||
if (res != null && Error.Contains(res)) | |||
{ | |||
Error.Remove(res); | |||
DeleteErrorAction?.Invoke(res); | |||
} | |||
}); | |||
ThreadManage.GetInstance().StartLong(new Action(() => | |||
@@ -62,6 +62,7 @@ namespace BPASmartClient.Device | |||
{ | |||
string name = item.Key; | |||
string Ms = string.Empty; | |||
string id = string.Empty; | |||
if (item.Key.Contains(".")) | |||
{ | |||
string sta = item.Key.Split('.')[0]; | |||
@@ -72,15 +73,42 @@ namespace BPASmartClient.Device | |||
if (keyValues.ContainsKey(value)) value = keyValues[value]; | |||
Ms = $"[{sta}]-[{sop}]-[{value}]"; | |||
id = $"[{sta}]-[{sop}]"; | |||
} | |||
StatusALL.Add(new DevStatus { Name = name, Status = item.Value.ToString(), Ms = Ms }); | |||
StatusALL.Add(new DevStatus { id = id, Name = name, Status = item.Value.ToString(), Ms = Ms }); | |||
} | |||
return new { data = StatusALL }; | |||
} | |||
public List<DevStatus> GetStatusT() | |||
{ | |||
List<DevStatus> StatusALL = new List<DevStatus>(); | |||
foreach (var item in status) | |||
{ | |||
string name = item.Key; | |||
string Ms = string.Empty; | |||
string id=string.Empty; | |||
if (item.Key.Contains(".")) | |||
{ | |||
string sta = item.Key.Split('.')[0]; | |||
string sop = item.Key.Split('.')[item.Key.Split('.').Length - 1]; name = sop; | |||
string value = item.Value.ToString(); | |||
if (keyValues.ContainsKey(sta)) sta = keyValues[sta]; | |||
if (keyValues.ContainsKey(sop)) sop = keyValues[sop]; | |||
if (keyValues.ContainsKey(value)) value = keyValues[value]; | |||
Ms = $"[{sta}]-[{sop}]-[{value}]"; | |||
id= $"[{sta}]-[{sop}]"; | |||
} | |||
StatusALL.Add(new DevStatus {id= id, Name = name, Status = item.Value.ToString(), Ms = Ms }); | |||
} | |||
return StatusALL; | |||
} | |||
} | |||
public class DevStatus | |||
{ | |||
public string id { get; set; } | |||
public string Name { get; set; } | |||
private string _status { get; set; } | |||
public string Status | |||
@@ -81,5 +81,8 @@ namespace BPASmartClient.Device | |||
/// <param name="info"></param> | |||
/// <param name="field"></param> | |||
object GetPropertyValue(object info, string field); | |||
Action<object> AddErrorAction { get; set; } | |||
Action<object> DeleteErrorAction { get; set; } | |||
} | |||
} |
@@ -8,6 +8,7 @@ using BPASmartClient.Message; | |||
using BPASmartDatavDeviceClient.IoT; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading; | |||
namespace BPASmartClient.IoT | |||
@@ -125,6 +126,11 @@ namespace BPASmartClient.IoT | |||
{ | |||
MessageLog.GetInstance.ShowEx(message); | |||
} | |||
Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.ForEach(device => | |||
{ | |||
device.AddErrorAction+= AddErrorAction; | |||
device.DeleteErrorAction += DeleteErrorAction; | |||
}); | |||
} | |||
/// <summary> | |||
@@ -139,7 +145,6 @@ namespace BPASmartClient.IoT | |||
List<object> dataVNode = new List<object>(); | |||
Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.ForEach(device => | |||
{ | |||
//List<object> GJXX | |||
var obj = new | |||
{ | |||
DeviceId = device.DeviceId.ToString(), | |||
@@ -169,6 +174,34 @@ namespace BPASmartClient.IoT | |||
#endregion | |||
#region 私有 | |||
/// <summary> | |||
/// 增加告警 | |||
/// </summary> | |||
/// <param name="obj"></param> | |||
private void AddErrorAction(object obj) | |||
{ | |||
HttpAddAlarm(new AlarmTable | |||
{ | |||
AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), | |||
AlarmType = GetPropertyValue(obj, "Type").ToString(), | |||
AlarmMessage = GetPropertyValue(obj, "Text").ToString(), | |||
AlarmVla = "告警", | |||
}); | |||
} | |||
/// <summary> | |||
/// 删除告警 | |||
/// </summary> | |||
/// <param name="obj"></param> | |||
private void DeleteErrorAction(object obj) | |||
{ | |||
HttpAddAlarm(new AlarmTable | |||
{ | |||
}); | |||
} | |||
/// <summary> | |||
/// 接收云端消息 | |||
/// </summary> | |||
@@ -183,6 +216,19 @@ namespace BPASmartClient.IoT | |||
ActionManage.GetInstance.Send("IotBroadcast", iOTCommand); | |||
} | |||
} | |||
/// <summary> | |||
/// 获取某个对象中的属性值 | |||
/// </summary> | |||
/// <param name="info"></param> | |||
/// <param name="field"></param> | |||
public object GetPropertyValue(object info, string field) | |||
{ | |||
if (info == null) return null; | |||
Type t = info.GetType(); | |||
IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi; | |||
return property.First().GetValue(info, null); | |||
} | |||
#endregion | |||