add-添加首页RFID设备、喷码机、PLC监控展示及断线重连机制

dev
liuwf 1 month ago
parent 3bef5e20c4
commit 75b44df7e9

@ -52,8 +52,8 @@ namespace SlnMesnac.Business
public class ProdCompletionBusiness : BaseBusiness
{
private FJ500Comm.FJ500SP fj500s = new FJ500Comm.FJ500SP();
//喷码机喷码失败或者设备状态检查重试次数
private int PmTryAmount = 0;
//喷码机喷码失败或者设备状态检查重试次数,0代表状态正常
public static int PmTryAmount = 0;
//喷码机心跳每次收到回复刷新时间如果超过1分钟则认为喷码机断开连接添加一条报警
private DateTime PmHeartTime = DateTime.Now;
private readonly IMesProductPlanService _mesProductPlanService;

@ -58,20 +58,23 @@ namespace SlnMesnac.Extensions
var connectResult = _plc.Connect(item.plcIp, item.plcPort);
if (connectResult)
{
Log.Information($"PLC{item.plcIp}:{item.plcPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
_plc.ConfigKey = item.plcKey;
if (absractFactories.Contains(_plc))
{
absractFactories.Remove(_plc);
}
Log.Information($"PLC{item.plcIp}:{item.plcPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
absractFactories.Add(_plc);
}
else
{
Log.Information($"PLC{item.plcIp}:{item.plcPort};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
Log.Information($"PLC{item.plcIp}:{item.plcPort};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
_plc.ConfigKey = item.plcKey;
if (absractFactories.Contains(_plc))
{
absractFactories.Remove(_plc);
}
absractFactories.Add(_plc);
}
}
}
@ -85,7 +88,7 @@ namespace SlnMesnac.Extensions
});
}
private static PlcAbsractFactory InitPlc(IServiceProvider serviceProvider, string plcType)
public static PlcAbsractFactory InitPlc(IServiceProvider serviceProvider, string plcType)
{
PlcAbsractFactory _plc = null;
var _inovance = serviceProvider.GetRequiredService<InovanceFactory>();

@ -367,5 +367,10 @@ namespace SlnMesnac.Plc.Factory
{
throw new NotImplementedException();
}
public override bool readHeartByAddress(string address)
{
throw new NotImplementedException();
}
}
}

@ -308,5 +308,10 @@ namespace SlnMesnac.Plc.Factory
{
throw new NotImplementedException();
}
public override bool readHeartByAddress(string address)
{
throw new NotImplementedException();
}
}
}

@ -311,5 +311,10 @@ namespace SlnMesnac.Plc.Factory
{
throw new NotImplementedException();
}
public override bool readHeartByAddress(string address)
{
throw new NotImplementedException();
}
}
}

@ -67,10 +67,33 @@ namespace SlnMesnac.Plc.Factory
}
catch (Exception ex)
{
throw new InvalidOperationException($"西门子S系列PLC连接异常{ex.Message}");
// throw new InvalidOperationException($"西门子S系列PLC连接异常{ex.Message}");
return false;
}
}
/// <summary>
/// 通过PLC地址读取心跳结果
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public override bool readHeartByAddress(string address)
{
try
{
OperateResult<bool> read = s7.ReadBool(address);
if (!read.IsSuccess)
{
return false;
}
return true;
}
catch (Exception ex)
{
return false;
}
}
/// <summary>
/// 断开连接
/// </summary>

@ -39,7 +39,15 @@ namespace SlnMesnac.Plc
/// <param name="port"></param>
/// <returns></returns>
public abstract bool Connect(string ip, int port);
/// <summary>
/// 通过PLC地址读取心跳结果
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public abstract bool readHeartByAddress(string address);
/// <summary>
/// 断开连接
/// </summary>

@ -88,7 +88,7 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1">
<StackPanel Grid.Column="0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
@ -118,6 +118,71 @@
</StackPanel>
</Grid>
</StackPanel>
<StackPanel Grid.Column="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<Ellipse Width="30" Height="30">
<Ellipse.Style>
<Style TargetType="Ellipse">
<Style.Triggers>
<DataTrigger Binding="{Binding PmStatus}" Value="0">
<Setter Property="Shape.Fill" Value="Orange"/>
</DataTrigger>
<DataTrigger Binding="{Binding PmStatus}" Value="1">
<Setter Property="Shape.Fill" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding PmStatus}" Value="2">
<Setter Property="Shape.Fill" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Ellipse.Style>
</Ellipse>
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<TextBlock Text="喷码机状态" FontSize="15" Foreground="#FFFFFF" Margin="2,0,10,0"/>
</StackPanel>
</Grid>
</StackPanel>
<StackPanel Grid.Column="2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<Ellipse Width="30" Height="30">
<Ellipse.Style>
<Style TargetType="Ellipse">
<Style.Triggers>
<DataTrigger Binding="{Binding Out2FRfidStatus}" Value="0">
<Setter Property="Shape.Fill" Value="Orange"/>
</DataTrigger>
<DataTrigger Binding="{Binding Out2FRfidStatus}" Value="1">
<Setter Property="Shape.Fill" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding Out2FRfidStatus}" Value="2">
<Setter Property="Shape.Fill" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Ellipse.Style>
</Ellipse>
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<TextBlock Text="小包出口RFID" FontSize="15" Foreground="#FFFFFF" Margin="2,0,10,0"/>
</StackPanel>
</Grid>
</StackPanel>
</Grid>
</StackPanel>

@ -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>
/// 窗体控制

@ -39,7 +39,7 @@
"configId": 1,
"plcType": "SiemensPlc",
"plcIp": "192.168.2.220",
// "plcIp": "127.0.0.1",
// "plcIp": "127.0.0.1",
"plcPort": 102,
"plcKey": "plc",
"isFlage": true

Loading…
Cancel
Save