diff --git a/SamplePre.Communication/Communication/CommunicationBase.cs b/SamplePre.Communication/Communication/CommunicationBase.cs
new file mode 100644
index 0000000..a43a907
--- /dev/null
+++ b/SamplePre.Communication/Communication/CommunicationBase.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SamplePre.Communication
+{
+ public abstract class CommunicationBase
+ {
+
+ ///
+ /// 是否连接
+ ///
+ private bool _isConnected = false;
+
+
+ ///
+ /// 连接状态变化事件
+ ///
+ public event Action ConnectionStatusChanged;
+
+ ///
+ /// 是否连接
+ ///
+ public bool IsConnected
+ {
+ get => _isConnected;
+ set
+ {
+ if (_isConnected != value)
+ {
+ _isConnected = value;
+ ConnectionStatusChanged?.Invoke(value);
+ }
+ }
+ }
+
+
+
+ ///
+ /// 下发下位机指令
+ ///
+ ///
+ ///
+ ///
+ ///
+ public abstract bool WriteArraysBtye(int Dbno, int start, T[] bytes);
+
+
+
+ ///
+ /// 读取监控数据,读取数组
+ ///
+ ///
+ public abstract ushort[] ReadArraysShort(int Dbno, int start, int lenth);
+
+
+ ///
+ /// 写入数据
+ ///
+ /// 地址(如"M0.0", "DB1.DBW2")
+ /// 要写入的值
+ /// 是否写入成功
+ public abstract bool WriteSingleData(string address, object value);
+
+
+ }
+}
diff --git a/SamplePre.Communication/Communication/ICommunication.cs b/SamplePre.Communication/Communication/ICommunication.cs
deleted file mode 100644
index cb0fcef..0000000
--- a/SamplePre.Communication/Communication/ICommunication.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SamplePre.Communication
-{
- public interface ICommunication
- {
-
- ///
- /// 下发下位机指令
- ///
- ///
- ///
- ///
- ///
- bool WriteArraysBtye(int Dbno, int start, T[] bytes);
-
-
-
- ///
- /// 读取监控数据,读取数组
- ///
- ///
- ushort[] ReadArraysShort(int Dbno, int start, int lenth);
-
-
- ///
- /// 写入数据
- ///
- /// 地址(如"M0.0", "DB1.DBW2")
- /// 要写入的值
- /// 是否写入成功
- public bool WriteSingleData(string address, object value);
-
-
- }
-}
diff --git a/SamplePre.Communication/Communication/ModbusTcpCommunicator.cs b/SamplePre.Communication/Communication/ModbusTcpCommunicator.cs
index 7fd61cb..4501817 100644
--- a/SamplePre.Communication/Communication/ModbusTcpCommunicator.cs
+++ b/SamplePre.Communication/Communication/ModbusTcpCommunicator.cs
@@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace SamplePre.Communication.Communication
{
- public class ModbusTcpCommunicator : ICommunication, IDisposable
+ public class ModbusTcpCommunicator : CommunicationBase, IDisposable
{
IModbusMaster _modbusMaster = null;
TcpClient _tcpClient = null;
@@ -19,31 +19,7 @@ namespace SamplePre.Communication.Communication
private readonly int _port;
- ///
- /// 是否连接
- ///
- private bool _isConnected = false;
-
- ///
- /// 是否连接
- ///
- public bool IsConnected
- {
- get => _isConnected;
- set
- {
- if (_isConnected != value)
- {
- _isConnected = value;
- ConnectionStatusChanged?.Invoke(value);
- }
- }
- }
-
- ///
- /// 连接状态变化事件
- ///
- public event Action ConnectionStatusChanged;
+
///
/// 构造函数
@@ -150,7 +126,7 @@ namespace SamplePre.Communication.Communication
///
///
///
- public bool WriteArraysBtye(int Dbno, int start, T[] data)
+ public override bool WriteArraysBtye(int Dbno, int start, T[] data)
{
@@ -184,7 +160,7 @@ namespace SamplePre.Communication.Communication
/// 读取数组
///
///
- public ushort[] ReadArraysShort(int Dbno, int start, int lenth)
+ public override ushort[] ReadArraysShort(int Dbno, int start, int lenth)
{
//try
@@ -221,7 +197,7 @@ namespace SamplePre.Communication.Communication
}
- public bool WriteSingleData(string address, object value)
+ public override bool WriteSingleData(string address, object value)
{
throw new NotImplementedException();
}
diff --git a/SamplePre.Communication/Communication/S7PlcCommunicator.cs b/SamplePre.Communication/Communication/S7PlcCommunicator.cs
index 0831148..19a8418 100644
--- a/SamplePre.Communication/Communication/S7PlcCommunicator.cs
+++ b/SamplePre.Communication/Communication/S7PlcCommunicator.cs
@@ -12,7 +12,7 @@ using System.Text;
using System.Threading.Tasks;
namespace SamplePre.Communication
{
- public class S7PlcCommunicator : ICommunication, IDisposable
+ public class S7PlcCommunicator : CommunicationBase, IDisposable
{
public Plc _plc;
private readonly string _ipAddress;
@@ -20,31 +20,31 @@ namespace SamplePre.Communication
private readonly int _slot;
private readonly CpuType _cpuType;
- ///
- /// 是否连接
- ///
- private bool _isConnected = false;
+ /////
+ ///// 是否连接
+ /////
+ //private bool _isConnected = false;
- ///
- /// 是否连接
- ///
- public bool IsConnected
- {
- get => _isConnected;
- set
- {
- if (_isConnected != value)
- {
- _isConnected = value;
- ConnectionStatusChanged?.Invoke(value);
- }
- }
- }
+ /////
+ ///// 是否连接
+ /////
+ //public bool IsConnected
+ //{
+ // get => _isConnected;
+ // set
+ // {
+ // if (_isConnected != value)
+ // {
+ // _isConnected = value;
+ // ConnectionStatusChanged?.Invoke(value);
+ // }
+ // }
+ //}
- ///
- /// 连接状态变化事件
- ///
- public event Action ConnectionStatusChanged;
+ /////
+ ///// 连接状态变化事件
+ /////
+ //public event Action ConnectionStatusChanged;
///
/// 构造函数
@@ -127,7 +127,7 @@ namespace SamplePre.Communication
///
///
///
- public bool WriteArraysBtye(int Dbno, int start, T[] bytes)
+ public override bool WriteArraysBtye(int Dbno, int start, T[] bytes)
{
try
@@ -160,7 +160,7 @@ namespace SamplePre.Communication
/// 读取数组
///
///
- public ushort[] ReadArraysShort(int Dbno,int start,int lenth)
+ public override ushort[] ReadArraysShort(int Dbno,int start,int lenth)
{
try
@@ -193,7 +193,7 @@ namespace SamplePre.Communication
/// 地址(如"M0.0", "DB1.DBW2")
/// 要写入的值
/// 是否写入成功
- public bool WriteSingleData(string address, object value)
+ public override bool WriteSingleData(string address, object value)
{
try
{
diff --git a/SamplePre.Communication/CommunicationFactory.cs b/SamplePre.Communication/CommunicationFactory.cs
index e3dceda..ab59374 100644
--- a/SamplePre.Communication/CommunicationFactory.cs
+++ b/SamplePre.Communication/CommunicationFactory.cs
@@ -18,9 +18,9 @@ namespace SamplePre.Communication
/// 连接参数
///
///
- public static ICommunication CreateCommunication(CommProtocolType protocolType, string connectionParams)
+ public static CommunicationBase CreateCommunication(CommProtocolType protocolType, string connectionParams)
{
- ICommunication comm = null;
+ CommunicationBase comm = null;
switch (protocolType)
{
@@ -41,21 +41,21 @@ namespace SamplePre.Communication
}
- public static ICommunication CreateS7(string connectionParams)
+ public static CommunicationBase CreateS7(string connectionParams)
{
string[] params1 = connectionParams.Split(':');
if(params1 == null || params1.Length < 3) return null;
//ICommunication comm = new S7PlcCommunicator(CpuType.S71500, "192.168.10.2", 0, 1);
- ICommunication comm = new S7PlcCommunicator(CpuType.S71500, params1[0], int.Parse( params1[1]), int.Parse( params1[2]));
+ CommunicationBase comm = new S7PlcCommunicator(CpuType.S71500, params1[0], int.Parse( params1[1]), int.Parse( params1[2]));
return comm;
}
- public static ICommunication CreateModbusTcp(string connectionParams)
+ public static CommunicationBase CreateModbusTcp(string connectionParams)
{
string[] params1 = connectionParams.Split(':');
if (params1 == null || params1.Length < 2) return null;
- ICommunication comm = new ModbusTcpCommunicator(params1[0], int.Parse(params1[1]));
+ CommunicationBase comm = new ModbusTcpCommunicator(params1[0], int.Parse(params1[1]));
return comm;
}
diff --git a/SamplePre.Models/Const/SystemConst.cs b/SamplePre.Models/Const/SystemConst.cs
index 62eac60..7a66eda 100644
--- a/SamplePre.Models/Const/SystemConst.cs
+++ b/SamplePre.Models/Const/SystemConst.cs
@@ -44,7 +44,7 @@ namespace Models.Const
///
/// 主PLC对象
///
- public static ICommunication MasterPLC;
+ public static CommunicationBase MasterPLC;
///
/// 字典数据
diff --git a/SamplePre.Models/Models/CurrentSopProgress.cs b/SamplePre.Models/Models/CurrentSopProgress.cs
new file mode 100644
index 0000000..7190779
--- /dev/null
+++ b/SamplePre.Models/Models/CurrentSopProgress.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SamplePre.Models.Models
+{
+ public class CurrentSopProgress
+ {
+ public string sopName { get; set; }
+
+ public string sampleName { get; set; }
+
+ public string actionName { get; set; }
+
+ public float CurrentPercent { get; set; }
+ }
+}
diff --git a/SamplePre.Models/Tables/sample_record.cs b/SamplePre.Models/Tables/sample_record.cs
deleted file mode 100644
index a1f7e49..0000000
--- a/SamplePre.Models/Tables/sample_record.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Models.Models
-{
- ///
- /// 样本记录
- ///
- public class sample_record
- {
-
- public int id { get; set; }
- public string qrcode { get; set; }
- public string check_item { get; set; }
- public string jizhi { get; set; }
- public string xuhao { get; set; }
- public string standard_id { get; set; }
- public string input_user { get; set; }
- public DateTime inpu_date { get; set; }
- public string weight { get; set; }
-
- }
-}
diff --git a/SamplePre.ProcessBll/BLL/CommunicationBll.cs b/SamplePre.ProcessBll/BLL/CommunicationBll.cs
index 4ca69e4..ae00d2e 100644
--- a/SamplePre.ProcessBll/BLL/CommunicationBll.cs
+++ b/SamplePre.ProcessBll/BLL/CommunicationBll.cs
@@ -26,6 +26,8 @@ namespace SamplePre.ProcessBll.BLL
//读取下位机状态
ushort[] data1 = SystemConst.MasterPLC.ReadArraysShort(Dbno, start, lenth);
+
+
return data1;
}
diff --git a/SamplePreSystem.UI/Converters/CommunicationColorConverter.cs b/SamplePreSystem.UI/Converters/CommunicationColorConverter.cs
new file mode 100644
index 0000000..3a610df
--- /dev/null
+++ b/SamplePreSystem.UI/Converters/CommunicationColorConverter.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+using System.Windows.Media;
+
+namespace SamplePreSystem.UI.Converters
+{
+ public class CommunicationColorConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ string str = value.ToString();
+
+ if (str.Contains("PLC通信异常"))
+ {
+ return new SolidColorBrush(Colors.Red);
+ }
+ else
+ {
+ return new SolidColorBrush(Colors.Green);
+ }
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return value;
+ }
+ }
+}
diff --git a/SamplePreSystem.UI/ViewModel/Monitor/FaultInfo.cs b/SamplePreSystem.UI/ViewModel/Monitor/FaultInfo.cs
index a2bde3d..74251a3 100644
--- a/SamplePreSystem.UI/ViewModel/Monitor/FaultInfo.cs
+++ b/SamplePreSystem.UI/ViewModel/Monitor/FaultInfo.cs
@@ -22,8 +22,12 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
public string FaultDesc { get; set; } // 故障描述
public FaultType FaultType { get; set; } // 故障类型
+ public DateTime FaultDate { get; set; }
+
private Brush runColor = Brushes.Orange;
+
+
public Brush RunColor
diff --git a/SamplePreSystem.UI/ViewModel/Monitor/MonitorViewModel.cs b/SamplePreSystem.UI/ViewModel/Monitor/MonitorViewModel.cs
index c47fff3..d369897 100644
--- a/SamplePreSystem.UI/ViewModel/Monitor/MonitorViewModel.cs
+++ b/SamplePreSystem.UI/ViewModel/Monitor/MonitorViewModel.cs
@@ -7,14 +7,12 @@ using SamplePre.Common;
using SamplePre.Communication.Communication;
using SamplePre.Models;
using SamplePre.Models.Ext;
+using SamplePre.Models.Models;
using SamplePre.ProcessBll.BLL;
using SamplePre.ProcessBll.SampleSequence;
using SamplePre.UIWpf.MonitorManager.chirld;
using SamplePre.UIWpf.SampleManager.chirld;
using SamplePreSystem.UI.Views.MonitorManager;
-
-
-//using SamplePre.UIWpf.Properties;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -45,7 +43,13 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
CommunicationBll communicationBll = new CommunicationBll();
SOPManagerBll sopManagerBll = new SOPManagerBll();
-
+
+
+ ///
+ /// u错误队列
+ ///
+ ConcurrentQueueExt errQueue = new SamplePre.Common.ConcurrentQueueExt();
+
///
/// 所有动作
@@ -58,144 +62,39 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
//所有动作
sys_Actions = actionMangerBll.QuerySysAction();
- GetSampleData();
+ //获取所有样本信息
+ GetSampleData();
+
+ //获取当前SOP所有动作列表
+ GetCurrentSopByID(CurrentSop.id);
+
+ //计算进度百分比
+ CalculationProgress(CurrentSop.id);
//初始化功能单元
- InitWorkUnits();
+ InitWorkUnits();
///启动数据监控线程
UpdateMonitorData();
- Test();
+ //错误信息处理
+ ErrInfoDo();
-
- //获取当前SOP所有动作列表
- GetCurrentSopByID(this.CurrentSopID);
-
- }
-
- ///
- /// 获取当前SOP所有动作列表
- ///
- ///
- public void GetCurrentSopByID(string sopID)
- {
- CurrentstandardActionList = sopManagerBll.QueryStandardActionByStandardId(sopID)?.OrderBy(p => p.process_no).ToList(); ;
}
- ///
- /// 计算进度百分比
- ///
- ///
- public void CalculationProgress(string actionID)
- {
- if (CurrentstandardActionList.Count <= 0) return;
+ #region PLC 通信状态监控
- //var item = CurrentstandardActionList.Where(p => p.process_id == actionID && p.ExecFinishFlag == false).FirstOrDefault();
- //if (item != null)
- //{
- // item.ExecFinishFlag = true;
-
- // int finishcount = CurrentstandardActionList.Count(p => p.ExecFinishFlag == true);
- // int totalcount = CurrentstandardActionList.Count;
-
- // double percent = (float)finishcount / totalcount;
-
- // CurrentPercent = Math.Round(percent * 100,0);
- //}
-
-
- }
-
- ///
- /// 当前SOP_ID
- ///
[ObservableProperty]
- public string currentSopID = "";
+ public string txtState = "PLC通信异常!";
+
+ #endregion
+
+
+ #region 样品列表
- ///
- /// 当前百分比
- ///
[ObservableProperty]
- public double currentPercent = 40;
-
- ///
- /// 当前SOP动作
- ///
- public List CurrentstandardActionList = new List();
-
- public void Test()
- {
- SopExecInfo.Add(new SopExecInfo()
- {
- sapmleName = "DCM固相萃取",
- actionName = "加液",
- starDate = DateTime.Now,
- endDate = DateTime.Now,
- state = "完成",
- doIngShow = false
-
- });
- SopExecInfo.Add(new SopExecInfo()
- {
- sapmleName = "DCM固相萃取",
- actionName = "加液",
- starDate = DateTime.Now,
- endDate = DateTime.Now,
- state = "完成",
- doIngShow = false
- });
- SopExecInfo.Add(new SopExecInfo()
- {
- sapmleName = "DCM固相萃取",
- actionName = "加液",
- starDate = DateTime.Now,
- endDate = DateTime.Now,
- state = "完成",
- doIngShow = false
-
- });
- SopExecInfo.Add(new SopExecInfo()
- {
- sapmleName = "DCM固相萃取",
- actionName = "离心",
- starDate = DateTime.Now,
- endDate = DateTime.Now,
- state = "执行",
- doIngShow = true
-
- });
- }
-
-
-
- private List _sampleExecList = new List();
-
-
- public List SampleExecList
- {
- get { return _sampleExecList; }
- set {
-
- SetProperty(ref _sampleExecList, value);
-
-
- }
- }
-
- private string _sopExecData;
-
- public string SopExecData
- {
- get { return _sopExecData; }
- set {
-
- SetProperty(ref _sopExecData, value);
-
- }
- }
-
+ public List sampleExecList = new List();
///
/// 获取样本信息
@@ -209,31 +108,138 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
//设置当前SOP——ID
string standrad_id = samples.FirstOrDefault()?.standrad_id;
+ string standrad_name = samples.FirstOrDefault()?.standrad;
if (!string.IsNullOrEmpty(standrad_id))
{
- if(standrad_id.Contains(","))
+ if (standrad_id.Contains(","))
{
- CurrentSopID = standrad_id.Split(",")[0];
+ CurrentSop.id = standrad_id.Split(",")[0];
+ CurrentSop.standard_name = standrad_name.Split(",")[0];
}
else
{
- CurrentSopID = standrad_id;
+ CurrentSop.id = standrad_id;
+ CurrentSop.standard_name = standrad_name;
}
-
+
}
-
+
}
+ #endregion
+
+
+ #region 当前sop的动作列表
+
+ ///
+ /// sop动作执行信息
+ ///
+ private List sopExecInfo = new List();
+
+ public List SopExecInfo
+ {
+ get { return sopExecInfo; }
+ set { sopExecInfo = value; }
+ }
+
+
+ ///
+ /// 当前SOP动作
+ ///
+ public List CurrentstandardActionList = new List();
+
+ ///
+ /// 获取当前SOP所有动作列表
+ ///
+ ///
+ public void GetCurrentSopByID(string sopID)
+ {
+ CurrentstandardActionList = sopManagerBll.QueryStandardActionByStandardId(sopID)?.OrderBy(p => p.process_no).ToList(); ;
+
+ SopExecInfo.Clear();
+ int index = 1;
+ foreach (var item in CurrentstandardActionList)
+ {
+ if (index == CurrentstandardActionList.Count)
+ {
+ SopExecInfo.Add(new SopExecInfo()
+ {
+ sapmleName = this.currentSop.standard_name,
+ actionName = item.action_name,
+ starDate = DateTime.Now,
+ endDate = DateTime.Now,
+ state = "进行中",
+ doIngShow = true
+
+ });
+ }
+ else
+ {
+ SopExecInfo.Add(new SopExecInfo()
+ {
+ sapmleName = this.currentSop.standard_name,
+ actionName = item.action_name,
+ starDate = DateTime.Now,
+ endDate = DateTime.Now,
+ state = "完成",
+ doIngShow = false
+
+ });
+ }
+
+ index++;
+ }
+ }
+
+ #endregion
+
+
+ #region sop执行进度
+
+ ///
+ /// 当前SOP
+ ///
+ [ObservableProperty]
+ public sys_standard currentSop = new sys_standard();
+
+ ///
+ /// 当前SOP进度
+ ///
+
+ [ObservableProperty]
+ public CurrentSopProgress sopProgress = new CurrentSopProgress();
+
+ ///
+ /// 计算SOP进度百分比
+ ///
+ ///
+ public void CalculationProgress(string SopId)
+ {
+ SopProgress.sopName = this.CurrentSop.standard_name;
+ SopProgress.sampleName = "xxxxx";
+ SopProgress.actionName = CurrentstandardActionList.FirstOrDefault()?.action_name;
+ SopProgress.CurrentPercent = 40;
+
+ }
+
+
+ #endregion
+
+
+ #region 功能单元
+
+
private List _workUnits = new List();
public List WorkUnits
{
get { return _workUnits; }
- set {
-
+ set
+ {
+
SetProperty(ref _workUnits, value);
-
+
}
}
@@ -242,7 +248,7 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
///
public void InitWorkUnits()
{
-
+
var list = SystemConst.dictDatas.Where(p => p.class_id == 2).ToList();
foreach (var item in list)
{
@@ -250,27 +256,61 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
var icon = GetIconKind(item.id);
- WorkUnits.Add(new WorkUnit() { actionName= "无", state = 0, StateName = "未连通", unitCode = item.id, unitName = item.data_type ,imgPath = imgPath,packIconKind = icon });
+ WorkUnits.Add(new WorkUnit() { actionName = "无", state = 0, StateName = "未连通", unitCode = item.id, unitName = item.data_type, imgPath = imgPath, packIconKind = icon });
}
}
- ///
- /// 故障信息
- ///
- private ObservableCollection faultInfos = new ObservableCollection();
-
- public ObservableCollection FaultInfos
+ public PackIconKind GetIconKind(string code)
{
- get { return faultInfos; }
- set {
+ switch (code)
+ {
+ case "300":
+ return PackIconKind.RobotIndustrialOutline;//Resources.机器人1;
- SetProperty(ref faultInfos, value);
-
+ case "301":
+ return PackIconKind.TestTube;//Resources.分液1;
+
+ case "302":
+ return PackIconKind.GoogleCirclesCommunities;//Resources.离心机1;
+
+ case "303":
+ return PackIconKind.GoogleCirclesGroup;
+
+ case "304":
+ return PackIconKind.InboxMultiple;//Resources.固相萃取1;
+
+ default:
+ return PackIconKind.ThermometerWater; //Resources.机器人1;
+ }
+ }
+
+ public string GetIcon(string code)
+ {
+ switch (code)
+ {
+ case "300":
+ return "/Assets/机器人1.png";//Resources.机器人1;
+
+ case "301":
+ return "/Assets/分液1.png";//Resources.分液1;
+
+ case "302":
+ return "/Assets/离心机1.png";//Resources.离心机1;
+
+ case "303":
+ return "/Assets/氮吹1.png";
+
+ case "304":
+ return "/Assets/固相萃取1.png";//Resources.固相萃取1;
+
+ default:
+ return "/Assets/机器人1.png";//Resources.机器人1;
}
}
+
///
/// 更新监控数据
///
@@ -296,10 +336,22 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
//刷新功能岛
UpdateWorkUnit(data1);
-
+
//刷新样品列表
GetSampleData();
+ //跟新plc通信状态
+ if(SystemConst.MasterPLC.IsConnected)
+ {
+ TxtState = "PLC通信正常";
+ }
+ else
+ {
+ TxtState = "PLC通信异常!";
+ this.errQueue.Enqueue(new FaultInfo() { FaultName = "PLC通信异常!", FaultDesc = "请检查PLC是否正常!", FaultDate = DateTime.Now });
+ }
+
+
await Task.Delay(3000);
}
@@ -325,7 +377,7 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
if (data1 != null && data1.Length > 0)
{
- foreach(var workUnit in WorkUnits)
+ foreach (var workUnit in WorkUnits)
{
var unit_actions = sys_Actions.Where(p => p.action_unit == workUnit.unitCode).ToList();
foreach (var action in unit_actions)
@@ -333,13 +385,7 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
int plcCode = int.Parse(action.plc_type);
ushort state = data1[plcCode];//动作的状态码
- //UCFunUnit uCFunUnit = this.dictUnits[unitCode];
- if(state >= 2)
- {
- //处理sop执行状态,计算执行百分比
- CalculationProgress(action.id);
-
- }
+
if (state >= workUnit.state || state == 2)
{ //发生改变再修改
@@ -349,7 +395,7 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
workUnit.StateName = SetStateData(state);
workUnit.RunColor = WorkUnit.GetStateColor(state);
workUnit.actionName = state < 2 ? "无" : action.action_name;
-
+
}
}
@@ -360,77 +406,30 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
workUnit.StateName = SetStateData(state);
workUnit.RunColor = WorkUnit.GetStateColor(state);
workUnit.actionName = state < 2 ? "无" : action.action_name;
-
+
}
}
//添加故障信息
if (workUnit.state == 0)
{
- Application.Current?.Dispatcher.BeginInvoke(new Action(() => {
- FaultInfos.Add(new FaultInfo { FaultName = workUnit.unitName + " - 未连通", FaultType = FaultType.Warning });
- }), DispatcherPriority.Normal);
+ //Application.Current?.Dispatcher.BeginInvoke(new Action(() => {
+ // FaultInfos.Add(new FaultInfo { FaultName = workUnit.unitName + " - 未连通", FaultType = FaultType.Warning });
+ //}), DispatcherPriority.Normal);
+
+
+ errQueue.Enqueue(new FaultInfo { FaultName = workUnit.unitName + " - 未连通", FaultDate = DateTime.Now, FaultType = FaultType.Warning });
+
-
-
}
}
-
+
}
}
- public string GetIcon(string code)
- {
- switch (code)
- {
- case "300":
- return "/Assets/机器人1.png";//Resources.机器人1;
-
- case "301":
- return "/Assets/分液1.png";//Resources.分液1;
-
- case "302":
- return "/Assets/离心机1.png";//Resources.离心机1;
-
- case "303":
- return "/Assets/氮吹1.png";
-
- case "304":
- return "/Assets/固相萃取1.png";//Resources.固相萃取1;
-
- default:
- return "/Assets/机器人1.png";//Resources.机器人1;
- }
- }
-
- public PackIconKind GetIconKind(string code)
- {
- switch (code)
- {
- case "300":
- return PackIconKind.RobotIndustrialOutline;//Resources.机器人1;
-
- case "301":
- return PackIconKind.TestTube;//Resources.分液1;
-
- case "302":
- return PackIconKind.GoogleCirclesCommunities;//Resources.离心机1;
-
- case "303":
- return PackIconKind.GoogleCirclesGroup;
-
- case "304":
- return PackIconKind.InboxMultiple;//Resources.固相萃取1;
-
- default:
- return PackIconKind.ThermometerWater; //Resources.机器人1;
- }
- }
-
-
public string SetStateData(int state)
{
@@ -467,52 +466,58 @@ namespace SamplePreSystem.UI.ViewModel.Monitor
return "未连接";
}
-
+
}
+ #endregion
- SocketClient client;
- ///
- /// 启动socket
- ///
- ///
- public async Task StarClientAsync()
- {
- client = new SocketClient();
-
- //回调函数
- client.ReceiveMsgAction = UpdateSopExecInfo;
-
- await client.StartClientAsync();
- }
-
- public void SendSocketTest(string msg)
- {
- client.SendMsgAsync(msg);
- }
+ #region 处理故障信息
///
- /// 更新sop执行信息
+ /// 故障信息
///
- ///
- public void UpdateSopExecInfo(string receiveData)
+ private ObservableCollection faultInfos = new ObservableCollection();
+
+ public ObservableCollection FaultInfos
{
- SopExecData += receiveData + "\r\n";
+ get { return faultInfos; }
+ set
+ {
+
+ SetProperty(ref faultInfos, value);
+
+ }
}
- ///
- /// sop执行信息
- ///
- private List sopExecInfo = new List();
-
- public List SopExecInfo
+ public void ErrInfoDo()
{
- get { return sopExecInfo; }
- set { sopExecInfo = value; }
+ Task.Run(() => {
+
+ while (true)
+ {
+ var errInfo = this.errQueue.GetOne();
+ if(errInfo != null)
+ {
+ Application.Current?.Dispatcher.Invoke(() =>
+ {
+ FaultInfos.Add(errInfo);
+ });
+ }
+
+ Task.Delay(1000).Wait();
+ }
+
+ });
}
+
+ #endregion
+
+
+
+
///
/// 打开详情窗口
///
diff --git a/SamplePreSystem.UI/Views/MonitorManager/MonitorView.xaml b/SamplePreSystem.UI/Views/MonitorManager/MonitorView.xaml
index b2ac085..b6ac2b0 100644
--- a/SamplePreSystem.UI/Views/MonitorManager/MonitorView.xaml
+++ b/SamplePreSystem.UI/Views/MonitorManager/MonitorView.xaml
@@ -6,6 +6,7 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:SamplePre.UIWpf.SampleManager"
+ xmlns:cnt="clr-namespace:SamplePreSystem.UI.Converters"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pro="clr-namespace:SamplePreSystem.UI.BaseControls"
@@ -13,6 +14,11 @@
d:DesignWidth="800"
Background="#E6E6E6"
mc:Ignorable="d">
+
+
+
+
+
@@ -58,6 +64,9 @@
VerticalAlignment="Center"
Orientation="Horizontal">
+
+
+
-
-
-
+
+
+
+ Progress="{Binding SopProgress.CurrentPercent}" />
-
+
+
+
+
+