diff --git a/SlnMesnac.Model/domain/DmsRecordShutDown.cs b/SlnMesnac.Model/domain/DmsRecordShutDown.cs
new file mode 100644
index 0000000..416806a
--- /dev/null
+++ b/SlnMesnac.Model/domain/DmsRecordShutDown.cs
@@ -0,0 +1,103 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+#region << 版 本 注 释 >>
+/*--------------------------------------------------------------------
+* 版权所有 (c) 2024 WenJY 保留所有权利。
+* CLR版本:4.0.30319.42000
+* 机器名称:LAPTOP-E0N2L34V
+* 命名空间:SlnMesnac.Model.domain
+* 唯一标识:a4dbd270-62c5-47db-a5f7-7e7cb895d15a
+*
+* 创建者:WenJY
+* 电子邮箱:wenjy@mesnac.com
+* 创建时间:2024-04-07 16:55:22
+* 版本:V1.0.0
+* 描述:
+*
+*--------------------------------------------------------------------
+* 修改人:
+* 时间:
+* 修改说明:
+*
+* 版本:V1.0.0
+*--------------------------------------------------------------------*/
+#endregion << 版 本 注 释 >>
+namespace SlnMesnac.Model.domain
+{
+ ///
+ /// 设备停机记录
+ ///
+ [SugarTable("dms_record_shut_down"), TenantAttribute("mes")]
+ public class DmsRecordShutDown
+ {
+ ///
+ /// 主键标识;scada上报的记录
+ ///
+ [SugarColumn(ColumnName = "record_shut_down_id", IsPrimaryKey = true, IsIdentity = true)]
+ public int RecordShutDownId { get; set; }
+ ///
+ /// 设备ID,关联dms_base_device_ledger的device_id
+ ///
+ [SugarColumn(ColumnName = "device_id")]
+ public int DeviceId { get; set; }
+ ///
+ /// 停机类型ID,关联dm_base_shut_type的shut_type_id
+ ///
+ [SugarColumn(ColumnName = "shut_type")]
+ public int? ShutType { get; set; }
+ ///
+ /// 停机原因
+ ///
+ [SugarColumn(ColumnName = "shut_reason")]
+ public string? ShutReason { get; set; }
+ ///
+ /// 停机开始时间
+ ///
+ [SugarColumn(ColumnName = "shut_begin_time")]
+ public DateTime? ShutBeginTime { get; set; }
+ ///
+ /// 停机结束时间
+ ///
+ [SugarColumn(ColumnName = "shut_end_time")]
+ public DateTime? ShutEndTime { get; set; }
+ ///
+ /// 停机时长
+ ///
+ [SugarColumn(ColumnName = "shut_time")]
+ public Decimal? ShutTime { get; set; }
+ ///
+ /// 是否标识:1-是;2-否
+ ///
+ [SugarColumn(ColumnName = "is_flag")]
+ public int IsFlag { get; set; }
+ ///
+ /// 备注
+ ///
+ [SugarColumn(ColumnName = "remark")]
+ public string? Remark { get; set; }
+ ///
+ /// 创建人
+ ///
+ [SugarColumn(ColumnName = "create_by")]
+ public string? CreateBy { get; set; }
+
+ ///
+ /// 创建时间
+ ///
+ [SugarColumn(ColumnName = "create_time")]
+ public DateTime? CreateTime { get; set; }
+ ///
+ /// 更新人
+ ///
+ [SugarColumn(ColumnName = "update_by")]
+ public string? UpdateBy { get; set; }
+ ///
+ /// 更新时间
+ ///
+ [SugarColumn(ColumnName = "update_time")]
+ public DateTime? UpdateTime { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/SlnMesnac.Model/enums/WarnStatusEnum.cs b/SlnMesnac.Model/enums/WarnStatusEnum.cs
new file mode 100644
index 0000000..a0d3340
--- /dev/null
+++ b/SlnMesnac.Model/enums/WarnStatusEnum.cs
@@ -0,0 +1,40 @@
+using System.ComponentModel;
+
+#region << 版 本 注 释 >>
+/*--------------------------------------------------------------------
+* 版权所有 (c) 2024 WenJY 保留所有权利。
+* CLR版本:4.0.30319.42000
+* 机器名称:LAPTOP-E0N2L34V
+* 命名空间:SlnMesnac.Model.enums
+* 唯一标识:dd489bb9-a90d-4552-82c6-289eb7dfe64e
+*
+* 创建者:WenJY
+* 电子邮箱:wenjy@mesnac.com
+* 创建时间:2024-04-08 13:30:10
+* 版本:V1.0.0
+* 描述:
+*
+*--------------------------------------------------------------------
+* 修改人:
+* 时间:
+* 修改说明:
+*
+* 版本:V1.0.0
+*--------------------------------------------------------------------*/
+#endregion << 版 本 注 释 >>
+namespace SlnMesnac.Model.enums
+{
+ public enum WarnStatusEnum
+ {
+ [Description("0")]
+ 无报警,
+
+ [Description("1")]
+ 磁选机设备故障,
+
+ [Description("2")]
+ 螺旋机螺旋速度低于预设值报警,
+
+
+ }
+}
diff --git a/SlnMesnac.Plc/Factory/InovanceFactory.cs b/SlnMesnac.Plc/Factory/InovanceFactory.cs
index 73ba46a..9fed6d0 100644
--- a/SlnMesnac.Plc/Factory/InovanceFactory.cs
+++ b/SlnMesnac.Plc/Factory/InovanceFactory.cs
@@ -357,5 +357,10 @@ namespace SlnMesnac.Plc.Factory
{
throw new NotImplementedException();
}
+
+ public override bool writeByteByAddress(string address, int value)
+ {
+ throw new NotImplementedException();
+ }
}
}
\ No newline at end of file
diff --git a/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs b/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs
index e29eae0..8062672 100644
--- a/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs
+++ b/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs
@@ -298,5 +298,10 @@ namespace SlnMesnac.Plc.Factory
{
throw new NotImplementedException();
}
+
+ public override bool writeByteByAddress(string address, int value)
+ {
+ throw new NotImplementedException();
+ }
}
}
\ No newline at end of file
diff --git a/SlnMesnac.Plc/Factory/OmronNJFactory.cs b/SlnMesnac.Plc/Factory/OmronNJFactory.cs
index 54900dc..c70c581 100644
--- a/SlnMesnac.Plc/Factory/OmronNJFactory.cs
+++ b/SlnMesnac.Plc/Factory/OmronNJFactory.cs
@@ -301,5 +301,10 @@ namespace SlnMesnac.Plc.Factory
{
throw new NotImplementedException();
}
+
+ public override bool writeByteByAddress(string address, int value)
+ {
+ throw new NotImplementedException();
+ }
}
}
\ No newline at end of file
diff --git a/SlnMesnac.Repository/service/IDmsRecordShutDownService.cs b/SlnMesnac.Repository/service/IDmsRecordShutDownService.cs
new file mode 100644
index 0000000..458a7bc
--- /dev/null
+++ b/SlnMesnac.Repository/service/IDmsRecordShutDownService.cs
@@ -0,0 +1,18 @@
+using SlnMesnac.Model.domain;
+using SlnMesnac.Repository.service.@base;
+using System.Collections.Generic;
+
+namespace SlnMesnac.Repository.service
+{
+ public interface IDmsRecordShutDownService : IBaseService
+ {
+ ///
+ /// 查询
+ ///
+ ///
+ ///
+ List GetAllMachineFirst();
+
+
+ }
+}
\ No newline at end of file
diff --git a/SlnMesnac.Repository/service/Impl/DmsRecordShutDownServiceImpl.cs b/SlnMesnac.Repository/service/Impl/DmsRecordShutDownServiceImpl.cs
new file mode 100644
index 0000000..e3bf3ff
--- /dev/null
+++ b/SlnMesnac.Repository/service/Impl/DmsRecordShutDownServiceImpl.cs
@@ -0,0 +1,63 @@
+using SlnMesnac.Model.domain;
+using SlnMesnac.Repository.service.@base;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+#region << 版 本 注 释 >>
+/*--------------------------------------------------------------------
+* 版权所有 (c) 2024 WenJY 保留所有权利。
+* CLR版本:4.0.30319.42000
+* 机器名称:LAPTOP-E0N2L34V
+* 命名空间:SlnMesnac.Repository.service.Impl
+* 唯一标识:2ef6cbc3-f5ce-4d6a-9750-06aac8227b6f
+*
+* 创建者:WenJY
+* 电子邮箱:wenjy@mesnac.com
+* 创建时间:2024-04-07 16:57:02
+* 版本:V1.0.0
+* 描述:
+*
+*--------------------------------------------------------------------
+* 修改人:
+* 时间:
+* 修改说明:
+*
+* 版本:V1.0.0
+*--------------------------------------------------------------------*/
+#endregion << 版 本 注 释 >>
+namespace SlnMesnac.Repository.service.Impl
+{
+ public class DmsRecordShutDownServiceImpl : BaseServiceImpl, IDmsRecordShutDownService
+ {
+
+ public DmsRecordShutDownServiceImpl(Repository rep):base(rep)
+ {
+
+ }
+
+ ///
+ /// 根据托盘编码获取托盘信息
+ ///
+ ///
+ ///
+ ///
+ public List GetAllMachineFirst()
+ {
+ List list = null;
+ try
+ {
+
+ string sql = "WITH RankedRecords AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY device_id ORDER BY create_time DESC) AS rn FROM dms_record_shut_down WHERE device_id IN (1016, 1017, 1018, 1019, 1020)) SELECT * FROM RankedRecords WHERE rn = 1;";
+ list = base._rep.Context.Ado.SqlQuery(sql);
+ return list;
+ }
+ catch (Exception e)
+ {
+ return list;
+ }
+ }
+
+
+ }
+}
\ No newline at end of file
diff --git a/SlnMesnac.WPF/Dto/MachineStatusDto.cs b/SlnMesnac.WPF/Dto/MachineStatusDto.cs
new file mode 100644
index 0000000..88697a8
--- /dev/null
+++ b/SlnMesnac.WPF/Dto/MachineStatusDto.cs
@@ -0,0 +1,29 @@
+using SlnMesnac.Model.enums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SlnMesnac.WPF.Dto
+{
+ ///
+ /// 存储数据采集状态及报警信息
+ ///
+ public class MachineStatusDto
+ {
+ //设备ID
+ public int deviceId { get; set; }
+
+ //设备运行状态
+ public bool status { get; set; }
+
+ //报警类型
+ // public WarnStatusEnum warnStatus { get; set; } = WarnStatusEnum.无报警;
+ }
+
+
+
+
+
+}
diff --git a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs
index 02722d8..4264a73 100644
--- a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs
+++ b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs
@@ -4,7 +4,10 @@ using Newtonsoft.Json.Linq;
using SlnMesnac.Business;
using SlnMesnac.Business.@base;
using SlnMesnac.Model.domain;
+using SlnMesnac.Model.enums;
using SlnMesnac.Plc;
+using SlnMesnac.Repository.service;
+using SlnMesnac.WPF.Dto;
using SlnMesnac.WPF.Model;
using SlnMesnac.WPF.ViewModel;
using System;
@@ -32,8 +35,13 @@ namespace SlnMesnac.WPF.Page
///
public partial class DevMonitorPage : UserControl
{
+ // 设备OEE采集缓存
+ private List DmsList = null;
+
+
private BaseBusiness baseBusiness = null;
private readonly ConfigInfoBusiness _configInfoBusiness;
+ private readonly IDmsRecordShutDownService dmsRecordShutDownService;
PlcAbsractFactory plc = null;
int MachineSleep = 1000;
private readonly ILogger _logger;
@@ -45,6 +53,7 @@ namespace SlnMesnac.WPF.Page
public DevMonitorPage()
{
+ dmsRecordShutDownService = App.ServiceProvider.GetService();
RecipeModeSetWindow.ManualChangeRecipeEvent += ManualChangeRecipe;
_logger = App.ServiceProvider.GetService>();
_configInfoBusiness = App.ServiceProvider.GetService();
@@ -120,13 +129,22 @@ namespace SlnMesnac.WPF.Page
{
try
{
+ DmsList = dmsRecordShutDownService.GetAllMachineFirst();
+ List machineStatusDtos = new List();
Thread.Sleep(2000);
if (plc != null)
{
- RefreshMagNet();
- RefreshSpiral();
- RefreshHot();
- RefreshUnPack();
+ lock (string.Empty)
+ {
+ RefreshMagNet(machineStatusDtos);
+ RefreshSpiral(machineStatusDtos);
+ RefreshHot(machineStatusDtos);
+ RefreshUnPack(machineStatusDtos);
+
+ //开关机时间采集
+ machineStatusDtos.ForEach(x => OeeCollection(x));
+
+ }
}
else
{
@@ -148,6 +166,52 @@ namespace SlnMesnac.WPF.Page
});
}
+ ///
+ /// OEE设备关机采集
+ ///
+ ///
+ private void OeeCollection(MachineStatusDto machineStatusDto)
+ {
+ try
+ {
+ #region 设备OEE关机采集
+ DmsRecordShutDown? record = DmsList.FirstOrDefault(x => x.DeviceId == machineStatusDto.deviceId);
+ if (!machineStatusDto.status) // 关机
+ {
+ if (record == null || record.ShutEndTime != null)
+ {
+ DmsRecordShutDown newRecord = new DmsRecordShutDown();
+ newRecord.DeviceId = machineStatusDto.deviceId;
+ newRecord.ShutType = 1;
+ newRecord.ShutReason = "正常停机";
+ newRecord.ShutBeginTime = DateTime.Now;
+ newRecord.CreateBy = "SlnMesnac";
+ newRecord.CreateTime = DateTime.Now;
+ dmsRecordShutDownService.Insert(newRecord);
+ //更新本地缓存
+ DmsList = dmsRecordShutDownService.GetAllMachineFirst();
+ }
+ }
+ else //开机
+ {
+ if (record != null && record.ShutEndTime == null) //有关机记录,且未结束
+ {
+ record.ShutEndTime = DateTime.Now;
+ record.ShutTime = record.ShutTime = (decimal)(record.ShutEndTime - record.ShutBeginTime).Value.TotalMilliseconds;
+ record.UpdateTime = DateTime.Now;
+ record.UpdateBy = "SlnMesnac";
+ dmsRecordShutDownService.Update(record);
+ //更新本地缓存
+ DmsList = dmsRecordShutDownService.GetAllMachineFirst();
+ }
+ }
+ #endregion
+ }catch(Exception ex)
+ {
+ _logger.LogError($"OEE设备关机采集异常:{ex.Message}");
+ }
+ }
+
#region 监测缓存区重量,动态调整配方频率
///
/// 开始启动监测缓存区重量,动态调整配方频率
@@ -1224,7 +1288,7 @@ namespace SlnMesnac.WPF.Page
///
/// 拆包机参数监控
///
- private async void RefreshUnPack()
+ private async void RefreshUnPack(List machineStatusDtos)
{
try
{
@@ -1266,6 +1330,11 @@ namespace SlnMesnac.WPF.Page
UnpackStatus13.Text = unPackStatus13.ToString("F2");
+ MachineStatusDto machineStatusDto = new MachineStatusDto();
+ machineStatusDto.deviceId = 1016;
+ machineStatusDto.status = unPackStatus1;
+ machineStatusDtos.Add(machineStatusDto);
+
}));
}
catch (Exception ex)
@@ -1280,7 +1349,7 @@ namespace SlnMesnac.WPF.Page
///
/// 磁选机参数监控
///
- private async void RefreshMagNet()
+ private async Task RefreshMagNet(List machineStatusDtos)
{
try
{
@@ -1288,6 +1357,7 @@ namespace SlnMesnac.WPF.Page
bool signal1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机磁选启动"));
bool signal2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机MES允许远程"));
bool signal3 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机设备故障反馈"));
+
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
MagNetStatus1.Fill = signal0 ? Brushes.Green : Brushes.Red;
@@ -1296,6 +1366,17 @@ namespace SlnMesnac.WPF.Page
MagNetStatus4.Fill = signal3 ? Brushes.Red : Brushes.Green;
}));
+
+
+ MachineStatusDto machineStatusDto = new MachineStatusDto();
+ machineStatusDto.deviceId = 1017;
+ machineStatusDto.status = signal0 && signal1;
+ //if (signal3)
+ //{
+ // machineStatusDto.warnStatus = WarnStatusEnum.磁选机设备故障;
+ //}
+ machineStatusDtos.Add(machineStatusDto);
+
}
catch (Exception ex)
{
@@ -1307,7 +1388,7 @@ namespace SlnMesnac.WPF.Page
///
/// 螺旋机参数监控
///
- private async void RefreshSpiral()
+ private async void RefreshSpiral(List machineStatusDtos)
{
try
{
@@ -1343,6 +1424,14 @@ namespace SlnMesnac.WPF.Page
SpiralSignal7_Value.Text = speed2.ToString();
}));
+
+
+ MachineStatusDto machineStatusDto = new MachineStatusDto();
+ machineStatusDto.deviceId = 1018;
+ machineStatusDto.status = signal2&& signal3;
+ machineStatusDtos.Add(machineStatusDto);
+
+
}
catch (Exception ex)
{
@@ -1357,7 +1446,7 @@ namespace SlnMesnac.WPF.Page
///
/// 烘干机参数监控
///
- private async void RefreshHot()
+ private async void RefreshHot(List machineStatusDtos)
{
try
{
@@ -1409,6 +1498,11 @@ namespace SlnMesnac.WPF.Page
HotSignal7_2_Value.Text = ChangeHotWarn(signal7_2);
+ MachineStatusDto machineStatusDto = new MachineStatusDto();
+ machineStatusDto.deviceId = 1019;
+ machineStatusDto.status = signal1_2 && signal2_2;
+ machineStatusDtos.Add(machineStatusDto);
+
}));
}
catch (Exception ex)