You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
12 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Business;
using SlnMesnac.Business.@base;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto;
using SlnMesnac.Plc;
using SlnMesnac.WPF.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* 版权所有 (c) 2024 WenJY 保留所有权利。
* CLR版本4.0.30319.42000
* 机器名称LAPTOP-E0N2L34V
* 命名空间SlnMesnac.WPF.ViewModel
* 唯一标识14008fcc-0a31-4f1e-bc80-9f9ea84d3de5
*
* 创建者WenJY
* 电子邮箱wenjy@mesnac.com
* 创建时间2024-04-10 16:18:57
* 版本V1.0.0
* 描述:
*
*--------------------------------------------------------------------
* 修改人:
* 时间:
* 修改说明:
*
* 版本V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.WPF.ViewModel
{
/// <summary>
/// 设备参数监控
/// </summary>
internal class DevMonitorViewModel : ViewModelBase
{
private BaseBusiness baseBusiness = null;
private PlcAbsractFactory plc = null;
// private readonly PalletStowBusiness _palletStowBusiness;
// private readonly ProdCompletionBusiness _prodCompletionBusiness;
public DevMonitorViewModel()
{
baseBusiness = App.ServiceProvider.GetService<BaseBusiness>();
plc = baseBusiness.GetPlcByKey("plc");
// _palletStowBusiness = App.ServiceProvider.GetService<PalletStowBusiness>();
// _prodCompletionBusiness = App.ServiceProvider.GetService<ProdCompletionBusiness>();
Task.Run(() =>
{
while (true)
{
RefreshHotDataGrid();
RefreshUnPackDataGrid();
RefreshMagNetDataGrid();
Thread.Sleep(50);
}
});
//var palletTask = App.ServiceProvider.GetService<List<RealPalletTask>>();
//RefreshPalletTaskDataGrid(palletTask);
// _palletStowBusiness.RefreshPalletTaskListEvent += RefreshPalletTaskDataGrid;
//var barCodeTasks = App.ServiceProvider.GetService<List<RealBarCodeTask>>();
//RefreshBarCodeTaskDataGrid(barCodeTasks);
// _prodCompletionBusiness.RefreshBarCodeTaskListEvent += RefreshBarCodeTaskDataGrid;
}
#region 参数定义
/// <summary>
/// 烘干机DataGrid
/// </summary>
private ObservableCollection<PLCMachineModel> hotDataGrid;
public ObservableCollection<PLCMachineModel> HotDataGrid
{
get { return hotDataGrid; }
set { hotDataGrid = value; RaisePropertyChanged(() => HotDataGrid); }
}
/// <summary>
/// 拆包机DataGrid
/// </summary>
private ObservableCollection<PLCMachineModel> unPackDataGrid;
public ObservableCollection<PLCMachineModel> UnPackDataGrid
{
get { return unPackDataGrid; }
set { unPackDataGrid = value; RaisePropertyChanged(() => UnPackDataGrid); }
}
/// <summary>
/// 磁选机DataGrid
/// </summary>
private ObservableCollection<PLCMachineModel> magNetDataGrid;
public ObservableCollection<PLCMachineModel> MagNetDataGrid
{
get { return magNetDataGrid; }
set { magNetDataGrid = value; RaisePropertyChanged(() => MagNetDataGrid); }
}
///// <summary>
///// 条码队列DataGrid
///// </summary>
//private ObservableCollection<RealBarCodeTask> barCodeTaskDataGrid;
//public ObservableCollection<RealBarCodeTask> BarCodeTaskDataGrid
//{
// get { return barCodeTaskDataGrid; }
// set { barCodeTaskDataGrid = value; RaisePropertyChanged(() => BarCodeTaskDataGrid); }
//}
#endregion
///// <summary>
///// 刷新托盘队列信息
///// </summary>
///// <param name="palletTasks"></param>
//private void RefreshPalletTaskDataGrid(List<PLCMachineModel> palletTasks)
//{
// hotDataGrid = new ObservableCollection<PLCMachineModel>();
// foreach (var task in palletTasks)
// {
// hotDataGrid.Add(task);
// }
//}
///// <summary>
///// 刷新条码队列信息
///// </summary>
///// <param name="barCodeTasks"></param>
//private void RefreshBarCodeTaskDataGrid(List<RealBarCodeTask> barCodeTasks)
//{
// BarCodeTaskDataGrid = new ObservableCollection<RealBarCodeTask>();
// foreach (var task in barCodeTasks)
// {
// BarCodeTaskDataGrid.Add(task);
// }
//}
#region 烘干机参数监控
private async void RefreshHotDataGrid()
{
try
{
HotDataGrid = new ObservableCollection<PLCMachineModel>();
int hotStatus = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机风机状态"));
int hotStatus1 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机风机状态"));
int hotStatus2 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机风机状态"));
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
HotDataGrid.Add(new PLCMachineModel()
{
Name = "烘干机风机状态",
Value = ChangeHotStatus(hotStatus)
});
}));
}catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private string ChangeHotStatus(int status)
{
switch (status) {
case 0: return "未知";break;
case 1: return "运行";break;
case 2: return "停止";break;
case 3: return "故障";break;
default: return "未知";break;
}
}
#endregion
#region 拆包机参数监控
private async void RefreshUnPackDataGrid()
{
try
{
UnPackDataGrid = new ObservableCollection<PLCMachineModel>();
int unPackStatus = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机运行状态系统"));
bool signal0 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机MES屏蔽"));
bool signal1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程启动"));
bool signal2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程停止"));
bool signal3 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程急停"));
bool signal4 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("设备叫料"));
bool signal5 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("物料到位"));
bool signal6 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("设备投料"));
bool signal7 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机请求移走空托盘"));
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
UnPackDataGrid.Add(new PLCMachineModel()
{
Name = "拆包机运行状态系统",
Value = ChangeUnPackStatus(unPackStatus)
});
UnPackDataGrid.Add(new PLCMachineModel()
{
Name = "拆包机MES屏蔽",
Value = signal0.ToString()
}) ;
UnPackDataGrid.Add(new PLCMachineModel()
{
Name = "拆包机远程启动",
Value = signal1.ToString()
});
UnPackDataGrid.Add(new PLCMachineModel()
{
Name = "拆包机远程停止",
Value = signal2.ToString()
});
UnPackDataGrid.Add(new PLCMachineModel()
{
Name = "拆包机远程急停",
Value = signal3.ToString()
});
UnPackDataGrid.Add(new PLCMachineModel()
{
Name = "设备叫料",
Value = signal4.ToString()
});
UnPackDataGrid.Add(new PLCMachineModel()
{
Name = "物料到位",
Value = signal5.ToString()
});
UnPackDataGrid.Add(new PLCMachineModel()
{
Name = "设备投料",
Value = signal6.ToString()
});
UnPackDataGrid.Add(new PLCMachineModel()
{
Name = "拆包机请求移走空托盘",
Value = signal7.ToString()
});
}));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private string ChangeUnPackStatus(int status)
{
switch (status)
{
case 0: return "停止中"; break;
case 1: return "正在进料"; break;
case 2: return "正在提升"; break;
case 3: return "正在出料"; break;
case 4: return "正在复位"; break;
default: return "未知"; break;
}
}
#endregion
#region 磁选机参数监控
private async void RefreshMagNetDataGrid()
{
try
{
MagNetDataGrid = new ObservableCollection<PLCMachineModel>();
bool signal0 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机MES屏蔽"));
bool signal1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机设备故障反馈"));
bool signal2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机震动启动"));
bool signal3 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机磁选启动"));
bool signal4 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机心跳包"));
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
MagNetDataGrid.Add(new PLCMachineModel()
{
Name = "磁选机MES屏蔽",
Value = signal0.ToString()
}) ;
MagNetDataGrid.Add(new PLCMachineModel()
{
Name = "磁选机设备故障反馈",
Value = signal1.ToString()
});
MagNetDataGrid.Add(new PLCMachineModel()
{
Name = "磁选机震动启动",
Value = signal2.ToString()
});
MagNetDataGrid.Add(new PLCMachineModel()
{
Name = "磁选机磁选启动",
Value = signal3.ToString()
});
MagNetDataGrid.Add(new PLCMachineModel()
{
Name = "磁选机心跳包",
Value = signal4.ToString()
});
}));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
}
}