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.

1020 lines
37 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 Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using SlnMesnac.Business;
using SlnMesnac.Business.@base;
using SlnMesnac.Plc;
using SlnMesnac.WPF.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TouchSocket.Core;
namespace SlnMesnac.WPF.Page
{
/// <summary>
/// DevMonitorPage.xaml 的交互逻辑
/// </summary>
public partial class DevMonitorPage : UserControl
{
private BaseBusiness baseBusiness = null;
PlcAbsractFactory plc = null;
int MachineSleep = 1000;
private readonly ILogger<DevMonitorPage> _logger;
public DevMonitorPage()
{
_logger = App.ServiceProvider.GetService<ILogger<DevMonitorPage>>();
baseBusiness = App.ServiceProvider.GetService<BaseBusiness>();
MachineSleep = Convert.ToInt32(baseBusiness.GetPlcAddressByConfigKey("设备启动间隔"));
plc = baseBusiness.GetPlcByKey("plc");
InitializeComponent();
this.DataContext = new DevMonitorViewModel();
//Task.Run(async() =>
//{
// await App.Current.Dispatcher.BeginInvoke((Action)(() =>
// {
// Thread.Sleep(5000);
// StatusLight1.Fill = Brushes.Green;
// }));
//});
StartMachineLisening();
}
/// <summary>
/// 设备参数监听
/// </summary>
private void StartMachineLisening()
{
Task.Run(() =>
{
while (true)
{
try
{
Thread.Sleep(2000);
RefreshMagNet();
RefreshSpiral();
RefreshHot();
}
catch(Exception ex)
{
_logger.LogError($"设备参数监听StartMachineLisening()异常:{ex.Message}");
}
}
});
}
#region 设备启动、停止
/// <summary>
/// 发送脉冲信号方法封装
/// </summary>
/// <param name="addressKey">plc地址对应的key</param>
private void SendPulseSignal(string addressKey)
{
int PulseSleep = Convert.ToInt32(baseBusiness.GetPlcAddressByConfigKey("脉冲间隔"));
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey($"{addressKey}"), true);
Thread.Sleep(PulseSleep);
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey($"{addressKey}"), false);
}
/// <summary>
/// 一键启动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StartButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机MES允许远程")) == false)
{
MessageBox.Show("拆包机MES允许远程未切换远程");
return;
}
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机MES允许远程")) == false)
{
MessageBox.Show("磁选机MES允许远程未切换远程");
return;
}
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1MES允许远程")) == false)
{
MessageBox.Show("螺旋1MES允许远程未切换远程");
return;
}
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2MES允许远程")) == false)
{
MessageBox.Show("螺旋2MES允许远程未切换远程");
return;
}
//StartButton.IsEnabled = false;
//StopButton.IsEnabled = true;
//StopUrgentButton.IsEnabled = true;
Task.Run(() =>
{
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程急停"), false);
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程停止"), false);
#region 按顺序依次启动设备
//1.螺旋2
bool Spiral2Status = StartSpiral2();
if (!Spiral2Status) return;
//2.磁选机
bool MagNetStatus = StartMagNet();
if (!MagNetStatus) return;
//3.螺旋1
bool Spiral1Status = StartSpiral1();
if (!MagNetStatus) return;
//4.烘干机:烘干螺旋、烘干风机、烘干燃烧
bool DryerStatus1 = StartDryerMagNet();
if (!DryerStatus1) return;
bool DryerStatus2 = StartDryerFan();
if (!DryerStatus2) return;
bool DryerStatus3 = StartDryerHot();
if (!DryerStatus3) return;
//5.拆包机
bool unpackStatus = StartUnPack();
#endregion
if (unpackStatus)
{
MessageBoxAndLog("一键启动所有机器成功!");
}
});
}
catch (Exception ex)
{
_logger.LogError($"一键启动:{ex.Message}");
}
}
/// <summary>
/// 一键停止
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StopButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机MES允许远程")) == false)
{
MessageBox.Show("拆包机MES允许远程未切换远程");
return;
}
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机MES允许远程")) == false)
{
MessageBox.Show("磁选机MES允许远程未切换远程");
return;
}
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1MES允许远程")) == false)
{
MessageBox.Show("螺旋1MES允许远程未切换远程");
return;
}
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2MES允许远程")) == false)
{
MessageBox.Show("螺旋2MES允许远程未切换远程");
return;
}
#region 依次按序停止
Task.Run(() =>
{
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程启动"), false);
SendPulseSignal("拆包机远程停止");
Thread.Sleep(MachineSleep);
#region 烘干机
SendPulseSignal("烘干机螺旋停止");
Thread.Sleep(MachineSleep);
SendPulseSignal("烘干机燃烧停止");
Thread.Sleep(MachineSleep);
SendPulseSignal("烘干机风机停止");
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1启动"), false);
Thread.Sleep(MachineSleep);
SendPulseSignal("磁选机一键停止");
Thread.Sleep(MachineSleep);
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"), false);
#endregion
MessageBoxAndLog("一键停止所有机器成功!");
});
#endregion
//StopButton.IsEnabled = false;
//StopUrgentButton.IsEnabled = false;
//StartButton.IsEnabled = true;
}
catch (Exception ex)
{
_logger.LogError($"一键停止:{ex.Message}");
}
}
/// <summary>
/// 急停
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StopUrgentButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (StopUrgentButton.Content.ToString() == "急停")
{
//StopButton.IsEnabled = false;
//StopUrgentButton.Content = "复位";
SendPulseSignal("拆包机远程急停");
}
else if (StopUrgentButton.Content.ToString() == "复位")
{
//StopButton.IsEnabled = true;
//StopUrgentButton.Content = "急停";
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程急停"), false);
}
}
catch (Exception ex)
{
_logger.LogError($"拆包机远程急停:{ex.Message}");
}
}
#region 拆包机
/// <summary>
/// 拆包机启动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StartUnPackButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机MES允许远程")) == false)
{
MessageBox.Show("拆包机MES允许远程未切换远程");
return;
}
Task.Run(() =>
{
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程急停"), false);
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程停止"), false);
SendPulseSignal("拆包机远程启动");
});
//StartUnPackButton.IsEnabled = false;
//StopUnPackButton.IsEnabled = true;
}
catch (Exception ex)
{
_logger.LogError($"拆包机远程启动:{ex.Message}");
}
}
/// <summary>
/// 拆包机停止
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StopUnPackButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机MES允许远程")) == false)
{
MessageBox.Show("拆包机MES允许远程未切换远程");
return;
}
Task.Run(() =>
{
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程启动"), false);
SendPulseSignal("拆包机远程停止");
});
//StartUnPackButton.IsEnabled = true;
//StopUnPackButton.IsEnabled = false;
}
catch (Exception ex)
{
_logger.LogError($"拆包机停止:{ex.Message}");
}
}
#endregion
#region 磁选机
/// <summary>
/// 磁选启动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StartMagNetButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机MES允许远程")) == false)
{
MessageBox.Show("磁选机MES允许远程未切换远程");
return;
}
Task.Run(() =>
{
SendPulseSignal("磁选机一键启动");
});
}
catch (Exception ex)
{
_logger.LogError($"磁选启动:{ex.Message}");
}
}
/// <summary>
/// 磁选停止
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StopMagNetButton_Click(object sender, RoutedEventArgs e)
{
StartMagNet();
}
#endregion
#region 螺旋机
/// <summary>
/// 螺旋1启动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StartSpiral1Button_Click(object sender, RoutedEventArgs e)
{
StartSpiral1();
}
/// <summary>
/// 螺旋2启动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StartSpiral2Button_Click(object sender, RoutedEventArgs e)
{
StartSpiral2();
}
/// <summary>
/// 螺旋1停止
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StopSpiral1Button_Click(object sender, RoutedEventArgs e)
{
try
{
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1MES允许远程")) == false)
{
MessageBox.Show("螺旋1MES允许远程未切换远程");
return;
}
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1启动"), false);
}
catch (Exception ex)
{
_logger.LogError($"螺旋1停止:{ex.Message}");
}
}
/// <summary>
/// 螺旋2停止
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StopSpiral2Button_Click(object sender, RoutedEventArgs e)
{
try
{
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2MES允许远程")) == false)
{
MessageBox.Show("螺旋2MES允许远程未切换远程");
return;
}
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"), false);
}
catch (Exception ex)
{
_logger.LogError($"螺旋2停止:{ex.Message}");
}
}
#endregion
/// <summary>
/// 启动烘干机螺旋1
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StartDryerSpiralButton_Click(object sender, RoutedEventArgs e)
{
try
{
StartDryerMagNet();
}
catch (Exception ex)
{
_logger.LogError($"烘干机螺旋启动异常:{ex.Message}");
}
}
/// <summary>
/// 启动烘干机风机2
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StartDryerFanButton_Click(object sender, RoutedEventArgs e)
{
try
{
Task.Run(() =>
{
SendPulseSignal("烘干机风机启动");
});
}
catch (Exception ex)
{
_logger.LogError($"烘干机风机启动:{ex.Message}");
}
}
/// <summary>
/// 启动烘干机燃烧3
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StartDryerHotButton_Click(object sender, RoutedEventArgs e)
{
StartDryerHot();
}
/// <summary>
/// 停止烘干机螺旋
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StopDryerSpiralButton_Click(object sender, RoutedEventArgs e)
{
try
{
Task.Run(() =>
{
SendPulseSignal("烘干机螺旋停止");
});
}
catch (Exception ex)
{
_logger.LogError($"烘干机螺旋停止:{ex.Message}");
}
}
/// <summary>
/// 停止烘干机燃烧
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StopDryerHotButton_Click(object sender, RoutedEventArgs e)
{
try
{
Task.Run(() =>
{
SendPulseSignal("烘干机燃烧停止");
});
}
catch (Exception ex)
{
_logger.LogError($"烘干机燃烧停止:{ex.Message}");
}
}
/// <summary>
/// 停止烘干机风机
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StopDryerFanButton_Click(object sender, RoutedEventArgs e)
{
try
{
Task.Run(() =>
{
SendPulseSignal("烘干机风机停止");
});
}
catch (Exception ex)
{
_logger.LogError($"烘干机风机停止:{ex.Message}");
}
}
/// <summary>
/// 启动螺旋2
/// </summary>
private bool StartSpiral2()
{
bool result = false;
try
{
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2MES允许远程")) == false)
{
MessageBox.Show("螺旋2MES允许远程未切换远程");
result = false;
}
else
{
int value2 = int.Parse(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度值")) * 100;
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"), true);
plc.writeInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度设置"), value2);
Thread.Sleep(MachineSleep);
result = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"));
}
}
catch (Exception ex)
{
MessageBoxAndLog($"螺旋2启动异常:{ex.Message}", true);
result = false;
}
return result;
}
/// <summary>
/// 启动磁选
/// </summary>
private bool StartMagNet()
{
try
{
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机MES允许远程")) == false)
{
MessageBox.Show("磁选机MES允许远程未切换远程");
return false;
}
#region 启动磁选机 / 前提:check螺旋2启动及速度是否达标
int value2 = int.Parse(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度值")) * 100;
bool startFlag = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"));
int speed2 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度反馈"));
if (!startFlag)
{
MessageBox.Show($"前提条件螺旋2未成功启动,请检查后重新启动");
return false;
}
if (speed2 < value2 * 0.8)
{
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"), false);
MessageBox.Show($"前提条件螺旋2速度{speed2}未达到设定值{value2}的下限阈值80%,请检查后重新启动");
return false;
}
SendPulseSignal("磁选机一键启动");
Thread.Sleep(MachineSleep);
#endregion
bool flag1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机磁选启动"));
bool flag2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机震动启动"));
if (flag1 && flag2)
{
return true;
}
else
{
MessageBoxAndLog("磁选机启动失败,请检查后设备状态后重新尝试", true);
return false;
}
}
catch (Exception ex)
{
MessageBoxAndLog($"磁选机启动异常:{ex.Message}", true);
return false;
}
}
/// <summary>
/// 启动螺旋1
/// </summary>
private bool StartSpiral1()
{
bool result = false;
try
{
if (plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1MES允许远程")) == false)
{
MessageBox.Show("螺旋1MES允许远程未切换远程");
return false;
}
bool flag1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机磁选启动"));
bool flag2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机震动启动"));
if (!flag1 || !flag2)
{
MessageBoxAndLog("前提条件磁选机未启动,请先检查设备状态再启动", true);
return false;
}
int value1 = int.Parse(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度值"));
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1启动"), true);
plc.writeInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度设置"), value1 * 100);
Thread.Sleep(MachineSleep);
result = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1启动"));
}
catch (Exception ex)
{
MessageBoxAndLog($"螺旋1启动异常:{ex.Message}", true);
result = false;
}
return result;
}
#region 烘干机
/// <summary>
/// 烘干机螺旋启动/前提check:螺旋1启动且速度达到值
/// </summary>
private bool StartDryerMagNet()
{
bool result = false;
try
{
int value1 = int.Parse(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度值")) * 100;
bool startFlag = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1启动"));
int speed1 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度反馈"));
if (!startFlag)
{
MessageBox.Show($"烘干机螺旋启动失败:前提条件螺旋1未成功启动,请检查后重新启动");
return false;
}
if (speed1 < value1 * 0.8)
{
// plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"), false);
MessageBox.Show($"烘干机螺旋启动失败:前提条件螺旋1速度{speed1}未达到设定值{value1}的下限阈值80%,请检查后重新启动");
return false;
}
int value = int.Parse(baseBusiness.GetPlcAddressByConfigKey("烘干机螺旋频率设定值"));
SendPulseSignal("烘干机螺旋启动");
plc.writeInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机螺旋频率设定"), value1 * 100);
Thread.Sleep(MachineSleep / 2);
return true;
}
catch (Exception ex)
{
MessageBoxAndLog($"烘干机螺旋启动异常:{ex.Message}", true);
result = false;
}
return result;
}
/// <summary>
/// 烘干机风机启动/前提check:烘干机螺旋启动
/// </summary>
private bool StartDryerFan()
{
bool result = false;
try
{
bool startFlag = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机反馈传动启动"));
if (!startFlag)
{
MessageBox.Show($"烘干机风机启动失败:前提条件烘干机螺旋未成功启动,请检查后重新启动");
return false;
}
SendPulseSignal("烘干机风机启动");
Thread.Sleep(MachineSleep);
return true;
}
catch (Exception ex)
{
MessageBoxAndLog($"烘干机风机启动异常:{ex.Message}", true);
result = false;
}
return result;
}
/// <summary>
/// 烘干机燃烧启动/前提check:烘干机风机启动
/// </summary>
private bool StartDryerHot()
{
bool result = false;
try
{
bool startFlag = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机反馈风机启动"));
if (!startFlag)
{
MessageBox.Show($"烘干机燃烧启动失败:前提条件烘干机风机未成功启动,请检查后重新启动");
return false;
}
int value = int.Parse(baseBusiness.GetPlcAddressByConfigKey("烘干机温度设定值"));
SendPulseSignal("烘干机燃烧启动");
plc.writeInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机温度设定"), value * 100);
Thread.Sleep(MachineSleep);
return true;
}
catch (Exception ex)
{
MessageBoxAndLog($"烘干机燃烧启动异常:{ex.Message}", true);
result = false;
}
return result;
}
#endregion
/// <summary>
/// 拆包机启动/前提check:燃烧机启动
/// </summary>
private bool StartUnPack()
{
bool result = false;
try
{
bool startFlag = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机反馈燃烧启动"));
if (!startFlag)
{
MessageBox.Show($"拆包机启动失败:前提条件烘干机燃烧未成功启动,请检查后重新启动");
return false;
}
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程急停"), false);
plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程停止"), false);
SendPulseSignal("拆包机远程启动");
Thread.Sleep(MachineSleep);
return plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机运行状态系统"));
}
catch (Exception ex)
{
MessageBoxAndLog($"拆包机启动异常:{ex.Message}", true);
result = false;
}
return result;
}
#endregion
#region 设备参数监控
/// <summary>
/// 磁选机参数监控
/// </summary>
private async void RefreshMagNet()
{
try
{
bool signal0 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机震动启动"));
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;
MagNetStatus2.Fill = signal1 ? Brushes.Green : Brushes.Red;
MagNetStatus3.Fill = signal2 ? Brushes.Green : Brushes.Red;
MagNetStatus4.Fill = signal3 ? Brushes.Red : Brushes.Green;
}));
}
catch (Exception ex)
{
_logger.LogError(ex.Message);
}
}
/// <summary>
/// 磁选机参数监控
/// </summary>
private async void RefreshSpiral()
{
try
{
bool signal0 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1MES允许远程"));
bool signal1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2MES允许远程"));
bool signal2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1状态"));
bool signal3 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2状态"));
bool signal4 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1变频器状态"));
bool signal5 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2变频器状态"));
double speed1 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度反馈"))/100;
double speed2 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度反馈"))/100;
// 螺旋速度预设值
int speed1Set = int.Parse(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度值"));
int speed2Set = int.Parse(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度值"));
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
SpiralSignal0.Fill = signal0 ? Brushes.Green : Brushes.Red;
SpiralSignal1.Fill = signal1 ? Brushes.Green : Brushes.Red;
SpiralSignal2.Fill = signal2 ? Brushes.Green : Brushes.Red;
SpiralSignal3.Fill = signal3 ? Brushes.Green : Brushes.Red;
//变频器状态 0正常1故障
SpiralSignal4.Fill = signal4 ? Brushes.Red : Brushes.Green;
SpiralSignal5.Fill = signal5 ? Brushes.Red : Brushes.Green;
//螺旋1 速度低于80%预警
SpiralSignal6.Fill = speed1 < speed1Set * 0.8 ? Brushes.Red : Brushes.Green;
SpiralSignal6_Value.Text = speed1.ToString();
//螺旋2 速度低于80%预警
SpiralSignal7.Fill = speed2 < speed2Set * 0.8 ? Brushes.Red : Brushes.Green;
SpiralSignal7_Value.Text = speed2.ToString();
}));
}
catch (Exception ex)
{
_logger.LogError(ex.Message);
}
}
/// <summary>
/// 烘干机参数监控
/// </summary>
private async void RefreshHot()
{
try
{
int signal1_1 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机螺旋状态"));
int signal2_1= plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机风机状态"));
int signal3_1 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机燃烧机状态"));
bool signal1_2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机反馈传动启动"));
bool signal2_2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机反馈风机启动"));
bool signal3_2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机反馈燃烧启动"));
bool signal4_1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机燃烧机运行"));
bool signal14_2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机存在报警"));
int signal8 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机烘干温度"));
int signal9 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机加热温度"));
int signal10 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机出气温度"));
int signal11 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机输出百分比"));
bool signal7_1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机堵料报警"));
int signal7_2 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机报警"));
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
HotSignal1_1.Fill = signal1_1==2 ? Brushes.Green : Brushes.Red;
HotSignal1_1_Value.Text = ChangeHotStatus(signal1_1);
HotSignal2_1.Fill = signal2_1 == 2 ? Brushes.Green : Brushes.Red;
HotSignal2_1_Value.Text = ChangeHotStatus(signal2_1);
HotSignal3_1.Fill = signal3_1 == 2 ? Brushes.Green : Brushes.Red;
HotSignal3_1_Value.Text = ChangeHotStatus(signal3_1);
HotSignal1_2.Fill = signal1_2 ? Brushes.Green : Brushes.Red;
HotSignal2_2.Fill = signal2_2 ? Brushes.Green : Brushes.Red;
HotSignal3_2.Fill = signal3_2 ? Brushes.Green : Brushes.Red;
HotSignal4_1.Fill = signal4_1 ? Brushes.Green : Brushes.Red;
HotSignal4_2.Fill = signal14_2 ? Brushes.Red : Brushes.Green;
HotSignal5_1_Value.Text = ((double)signal8 / 10).ToString();
HotSignal5_2_Value.Text = ((double)signal9 / 10).ToString();
HotSignal6_1_Value.Text = ((double)signal10 / 10).ToString();
HotSignal6_2_Value.Text = signal11.ToString();
HotSignal7_1.Fill = signal7_1 ? Brushes.Red : Brushes.Green;
HotSignal7_2.Fill = signal7_2 == 0 ? Brushes.Green : Brushes.Red;
HotSignal7_2_Value.Text = ChangeHotWarn(signal7_2);
}));
}
catch (Exception ex)
{
_logger.LogError(ex.Message);
}
}
private string ChangeHotStatus(int status)
{
switch (status)
{
case 1: return "未知"; break;
case 2: return "运行"; break;
case 4: return "停止"; break;
default: return "未知"; break;
}
}
private string ChangeHotWarn(int status)
{
switch (status)
{
case 0: return "正常"; break;
case 1: return "风机故障"; break;
case 2: return "燃烧机故障"; break;
case 4: return "传动故障"; break;
case 8: return "超温保护"; break;
case 16: return "烘干温度超温"; break;
case 32: return "温控模块通讯超时"; break;
default: return "未知"; break;
}
}
#endregion
private void MessageBoxAndLog(string message, bool isError = false)
{
if (isError)
{
_logger.LogError(message);
}
else
{
_logger.LogInformation(message);
}
MessageBox.Show(message);
}
}
}