@ -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
/// </summary>
public partial class DevMonitorPage : UserControl
{
// 设备OEE采集缓存
private List < DmsRecordShutDown > DmsList = null ;
private BaseBusiness baseBusiness = null ;
private readonly ConfigInfoBusiness _configInfoBusiness ;
private readonly IDmsRecordShutDownService dmsRecordShutDownService ;
PlcAbsractFactory plc = null ;
int MachineSleep = 1000 ;
private readonly ILogger < DevMonitorPage > _logger ;
@ -45,6 +53,7 @@ namespace SlnMesnac.WPF.Page
public DevMonitorPage ( )
{
dmsRecordShutDownService = App . ServiceProvider . GetService < IDmsRecordShutDownService > ( ) ;
RecipeModeSetWindow . ManualChangeRecipeEvent + = ManualChangeRecipe ;
_logger = App . ServiceProvider . GetService < ILogger < DevMonitorPage > > ( ) ;
_configInfoBusiness = App . ServiceProvider . GetService < ConfigInfoBusiness > ( ) ;
@ -120,13 +129,22 @@ namespace SlnMesnac.WPF.Page
{
try
{
DmsList = dmsRecordShutDownService . GetAllMachineFirst ( ) ;
List < MachineStatusDto > machineStatusDtos = new List < MachineStatusDto > ( ) ;
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
} ) ;
}
/// <summary>
/// OEE设备关机采集
/// </summary>
/// <param name="machineStatusDto"></param>
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 监测缓存区重量,动态调整配方频率
/// <summary>
/// 开始启动监测缓存区重量,动态调整配方频率
@ -1224,7 +1288,7 @@ namespace SlnMesnac.WPF.Page
/// <summary>
/// 拆包机参数监控
/// </summary>
private async void RefreshUnPack ( )
private async void RefreshUnPack ( List < MachineStatusDto > 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
/// <summary>
/// 磁选机参数监控
/// </summary>
private async void RefreshMagNet ( )
private async Task RefreshMagNet ( List < MachineStatusDto > 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
/// <summary>
/// 螺旋机参数监控
/// </summary>
private async void RefreshSpiral ( )
private async void RefreshSpiral ( List < MachineStatusDto > 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
/// <summary>
/// 烘干机参数监控
/// </summary>
private async void RefreshHot ( )
private async void RefreshHot ( List < MachineStatusDto > 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 )