|
|
|
@ -3,13 +3,20 @@ using GalaSoft.MvvmLight.Command;
|
|
|
|
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using OracleInternal.Sharding;
|
|
|
|
|
using ServiceStack;
|
|
|
|
|
using SlnMesnac.Business;
|
|
|
|
|
using SlnMesnac.Business.@base;
|
|
|
|
|
using SlnMesnac.Config;
|
|
|
|
|
using SlnMesnac.Plc;
|
|
|
|
|
using SlnMesnac.TouchSocket;
|
|
|
|
|
using SlnMesnac.WPF.Page;
|
|
|
|
|
using SlnMesnac.WPF.Page.Generate;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Timers;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace SlnMesnac.WPF.ViewModel
|
|
|
|
@ -26,7 +33,9 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
private readonly BaseConfigInfoPage configInfoPage = new BaseConfigInfoPage();
|
|
|
|
|
private readonly RecipeManagePage recipeManagePage = new RecipeManagePage();
|
|
|
|
|
private readonly AgvAndTaskMonitorPage agvAndTaskMonitorPage = new AgvAndTaskMonitorPage();
|
|
|
|
|
|
|
|
|
|
private System.Timers.Timer timer = new System.Timers.Timer(1000*5);
|
|
|
|
|
PlcAbsractFactory? plc = null;
|
|
|
|
|
private BaseBusiness? baseBusiness = null;
|
|
|
|
|
#region 参数定义
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// PLC设备状态
|
|
|
|
@ -38,25 +47,26 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
set { _PlcStatus = value; RaisePropertyChanged(nameof(PlcStatus)); }
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 箱壳扫码器状态
|
|
|
|
|
/// 喷码机状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int _ShellScannerStatus = 0;
|
|
|
|
|
public int ShellScannerStatus
|
|
|
|
|
private int _PmStatus = 0;
|
|
|
|
|
public int PmStatus
|
|
|
|
|
{
|
|
|
|
|
get { return _ShellScannerStatus; }
|
|
|
|
|
set { _ShellScannerStatus = value; RaisePropertyChanged(nameof(ShellScannerStatus)); }
|
|
|
|
|
get { return _PmStatus; }
|
|
|
|
|
set { _PmStatus = value; RaisePropertyChanged(nameof(PmStatus)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 内胆扫码器状态
|
|
|
|
|
/// RFID1状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int _BoldScannerStatus = 0;
|
|
|
|
|
public int BoldScannerStatus
|
|
|
|
|
private int _Out2FRfidStatus = 0;
|
|
|
|
|
public int Out2FRfidStatus
|
|
|
|
|
{
|
|
|
|
|
get { return _BoldScannerStatus; }
|
|
|
|
|
set { _BoldScannerStatus = value; RaisePropertyChanged(nameof(BoldScannerStatus)); }
|
|
|
|
|
get { return _Out2FRfidStatus; }
|
|
|
|
|
set { _Out2FRfidStatus = value; RaisePropertyChanged(nameof(Out2FRfidStatus)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public System.Windows.Controls.UserControl _content;
|
|
|
|
|
|
|
|
|
|
public System.Windows.Controls.UserControl UserContent
|
|
|
|
@ -91,17 +101,96 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
public MainWindowViewModel()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger = App.ServiceProvider.GetService<ILogger<MainWindowViewModel>>();
|
|
|
|
|
|
|
|
|
|
UserContent = prodMgmtPage;
|
|
|
|
|
|
|
|
|
|
ControlOnClickCommand = new RelayCommand<object>(obj => ControlOnClick(obj));
|
|
|
|
|
FormControlCommand = new RelayCommand<object>(x => FormControl(x));
|
|
|
|
|
baseBusiness = App.ServiceProvider.GetService<BaseBusiness>();
|
|
|
|
|
plc = baseBusiness.GetPlcByKey("plc");
|
|
|
|
|
StartLiseningStatus();
|
|
|
|
|
checkStatus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 监听外部设备状态:PLC、喷码机、RFID
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void StartLiseningStatus()
|
|
|
|
|
{
|
|
|
|
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(LiseningStatus);
|
|
|
|
|
timer.AutoReset = true;
|
|
|
|
|
timer.Enabled = true;
|
|
|
|
|
timer.Start();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LiseningStatus(object?sender, ElapsedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
timer.Stop();
|
|
|
|
|
checkStatus();
|
|
|
|
|
timer.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkStatus()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#region PLC状态
|
|
|
|
|
if (plc != null && plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
plc.IsConnected = plc.readHeartByAddress("M100");
|
|
|
|
|
PlcStatus = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PlcStatus = 2;
|
|
|
|
|
|
|
|
|
|
PlcConfig? plcConfig = App.ServiceProvider.GetService<AppConfig>().plcConfig.FirstOrDefault(x => x.plcKey == "plc");
|
|
|
|
|
if (plcConfig != null)
|
|
|
|
|
{
|
|
|
|
|
bool result = plc.Connect(plcConfig.plcIp, plcConfig.plcPort);
|
|
|
|
|
plc.IsConnected = result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 喷码机状态
|
|
|
|
|
if (ProdCompletionBusiness.PmTryAmount == 0)
|
|
|
|
|
{
|
|
|
|
|
PmStatus = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PmStatus = 2;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region RFID状态
|
|
|
|
|
var rfidEquip = baseBusiness.GetRfidByKey("secondFloorOut");
|
|
|
|
|
if(rfidEquip != null)
|
|
|
|
|
{
|
|
|
|
|
Out2FRfidStatus = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Out2FRfidStatus = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"监听设备状态异常:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 窗体控制
|
|
|
|
|