pry il y a 2 ans
Parent
révision
bb0e2517d1
10 fichiers modifiés avec 186 ajouts et 14 suppressions
  1. +1
    -1
      BPASmartClient.DRCoffee/CoffeeMachine.cs
  2. +47
    -3
      BPASmartClient.Device/BaseDevice.cs
  3. +29
    -1
      BPASmartClient.Device/DeviceStatus.cs
  4. +3
    -0
      BPASmartClient.Device/IDevice.cs
  5. +18
    -1
      BPASmartClient.Device/VariableMonitor.cs
  6. +64
    -3
      BPASmartClient.IoT/DataVClient.cs
  7. +8
    -0
      BPASmartClient.IoT/Model/AlarmTable.cs
  8. +4
    -0
      BPASmartClient.IoT/Model/BaseEntity.cs
  9. +4
    -4
      BPASmartClient/App.config
  10. +8
    -1
      BPASmartClient/DeviceInfo.xml

+ 1
- 1
BPASmartClient.DRCoffee/CoffeeMachine.cs Voir le fichier

@@ -164,7 +164,7 @@ namespace BPASmartClient.DRCoffee
{
status["Status"] = DrCoffeeStatus.Wait;
status["AppStatus"] = DrCoffeeAppStatus.应用无状态;
status["Warning"] = DrCoffeeWarning.无警告;
status["Warning"] = DrCoffeeWarning.冲泡器未安装到位;
status["Fault"] = DrCoffeeFault.无故障;
}



+ 47
- 3
BPASmartClient.Device/BaseDevice.cs Voir le fichier

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


+ 29
- 1
BPASmartClient.Device/DeviceStatus.cs Voir le fichier

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


+ 3
- 0
BPASmartClient.Device/IDevice.cs Voir le fichier

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

+ 18
- 1
BPASmartClient.Device/VariableMonitor.cs Voir le fichier

@@ -28,7 +28,24 @@ namespace BPASmartClient.Device
private string _mModbusTcpAddress;


public string CurrentValue { get { return _mCurrentValue; } set { _mCurrentValue = value; } }
public string CurrentValue
{
get { return _mCurrentValue; }
set
{
_mCurrentValue = value;
if (_mCurrentValue == "False" || _mCurrentValue == "True")
{
if (_mCurrentValue == "True")
StatusColor = new { r = 51, g = 232, b = 34, a = 1 };
else
StatusColor = new { r = 255, g = 0, b = 0, a = 1 };
}else
StatusColor = new { r = 51, g = 232, b = 34, a = 1 };
}
}
private string _mCurrentValue;

public object StatusColor { get; set; }
}
}

+ 64
- 3
BPASmartClient.IoT/DataVClient.cs Voir le fichier

@@ -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
@@ -49,6 +50,10 @@ namespace BPASmartClient.IoT
/// 广播
/// </summary>
public string PubTopic = "/broadcast/" + "grgpECHSL7q" + "/" + "Transit_SetDevice";
/// <summary>
/// key值
/// </summary>
public Dictionary<string,string> keyValues = new Dictionary<string, string>();
#endregion

#region API调用
@@ -59,7 +64,6 @@ namespace BPASmartClient.IoT
/// <returns>返回ID</returns>
public string HttpAddAlarm(AlarmTable alarmTable)
{
string id = string.Empty;
try
{
if (DeviceDataV != null && DeviceDataV.GetIsConnected())
@@ -73,7 +77,7 @@ namespace BPASmartClient.IoT
{
MessageLog.GetInstance.Show(ex.Message);
}
return id;
return alarmTable.KeyID;
}

/// <summary>
@@ -125,6 +129,11 @@ namespace BPASmartClient.IoT
{
MessageLog.GetInstance.ShowEx(message);
}
Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.ForEach(device =>
{
device.AddErrorAction+= AddErrorAction;
device.DeleteErrorAction += DeleteErrorAction;
});
}

/// <summary>
@@ -139,7 +148,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 +177,46 @@ namespace BPASmartClient.IoT
#endregion

#region 私有

/// <summary>
/// 增加告警
/// </summary>
/// <param name="obj"></param>
private void AddErrorAction(object obj)
{
string id = Guid.NewGuid().ToString();
HttpAddAlarm(new AlarmTable
{
AlarmTime = GetPropertyValue(obj, "Time").ToString(),
AlarmType = GetPropertyValue(obj, "Type").ToString(),
AlarmMessage = GetPropertyValue(obj, "Text").ToString(),
AlarmVla = "告警",
KeyID = id,
});
keyValues[GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString()] =id ;
}

/// <summary>
/// 删除告警
/// </summary>
/// <param name="obj"></param>
private void DeleteErrorAction(object obj)
{
string message = GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString();
if (keyValues.ContainsKey(message))
{
HttpAddAlarm(new AlarmTable
{
AlarmTime = GetPropertyValue(obj, "Time").ToString(),
AlarmType = GetPropertyValue(obj, "Type").ToString(),
AlarmMessage = GetPropertyValue(obj, "Text").ToString(),
AlarmVla = "告警",
KeyID = keyValues[message],
State="n"
});
}
}

/// <summary>
/// 接收云端消息
/// </summary>
@@ -183,6 +231,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




+ 8
- 0
BPASmartClient.IoT/Model/AlarmTable.cs Voir le fichier

@@ -31,5 +31,13 @@ namespace BPASmartClient.IoT
/// IP 地址
/// </summary>
public string IP { get; set; }
/// <summary>
/// 状态描述
/// </summary>
public string StatusMS { get; set; }
/// <summary>
/// 状态颜色
/// </summary>
public object StatusColor { get; set; }
}
}

+ 4
- 0
BPASmartClient.IoT/Model/BaseEntity.cs Voir le fichier

@@ -39,5 +39,9 @@ namespace BPASmartClient.IoT
/// 修改时间
/// </summary>
public DateTime UpdateTime { get; set; }
/// <summary>
/// key
/// </summary>
public string KeyID { get; set; }
}
}

+ 4
- 4
BPASmartClient/App.config Voir le fichier

@@ -19,16 +19,16 @@
<!--<add key="ApolloUri" value="https://bpa.black-pa.com:28080"/>-->

<!--开发环境-->
<!--<add key="ApolloUri" value="http://10.2.1.21:28080"/>
<add key="ApolloUri" value="http://10.2.1.21:28080"/>
<add key="OrderServiceUri" value="https://bpa.black-pa.com:21527/order/"/>
<add key="StockServiceUri" value="https://bpa.black-pa.com:21527/stock/"/>
<add key="DataVServiceUri" value="https://bpa.black-pa.com:21527/datav"/>-->
<add key="DataVServiceUri" value="https://bpa.black-pa.com:21527/datav"/>

<!--正式环境-->
<add key="ApolloUri" value="http://47.108.65.220:28080"/>
<!--<add key="ApolloUri" value="http://47.108.65.220:28080"/>
<add key="OrderServiceUri" value="https://witt.black-pa.com/order/"/>
<add key="StockServiceUri" value="https://witt.black-pa.com/stock/"/>
<add key="DataVServiceUri" value="https://witt.black-pa.com/datav"/>
<add key="DataVServiceUri" value="https://bpa.black-pa.com:21527/datav"/>-->


<add key="COM_Coffee" value="COM3"/>


+ 8
- 1
BPASmartClient/DeviceInfo.xml Voir le fichier

@@ -16,6 +16,13 @@
<BaudRate>9600</BaudRate>
</Parameters>
</Peripheral>

<Peripheral Module="BPASmartClient.DRCoffee.CoffeeMachine">
<Parameters>
<PortName>COM5</PortName>
<BaudRate>9600</BaudRate>
</Parameters>
</Peripheral>
</Peripherals>
</Device>-->

@@ -31,7 +38,7 @@
</Peripherals>
</Device>-->

<Device Name="Morks" Module="BPASmartClient.MorkS.Control" DeviceId="1">
<Device Name="Morks" Module="BPASmartClient.MorkS.Control" DeviceId="2">
<Peripherals>
<Peripheral Module="BPASmartClient.PLC.MorksMachine">
<Parameters>


Chargement…
Annuler
Enregistrer