change - 条码绑定扫码器设备状态刷新

dev
liuwf 1 year ago
parent 223f7df1b3
commit e8a0b34299

@ -10,6 +10,8 @@ using NPOI.HSSF.Record;
using System.Threading.Tasks;
using Aucma.Core.PLc;
using System.Linq;
using Admin.Core.Common;
using Aucma.Core.Scanner;
namespace Aucma.Core.CodeBinding.ViewModels
{
@ -30,26 +32,40 @@ namespace Aucma.Core.CodeBinding.ViewModels
public MainWindowViewModel()
{
UserContent = firstPage;
PlcState(false);
PlcState(true);
Scanner1State(true);
Scanner2State(true);
init();
}
public void init()
{
// plc状态刷新定时器
// 设备状态刷新定时器
System.Timers.Timer timer = new System.Timers.Timer(1000 * 5);
timer.Elapsed += new System.Timers.ElapsedEventHandler(RefreshPlcStatus);
timer.Elapsed += new System.Timers.ElapsedEventHandler(RefreshStatus);
timer.AutoReset = true;
timer.Enabled = true;
timer.Start();
}
#region 设备状态刷新
/// <summary>
/// 设备状态刷新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void RefreshStatus(object sender, System.Timers.ElapsedEventArgs e)
{
RefreshPlc();
RefreshScanner();
}
/// <summary>
/// plc状态刷新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void RefreshPlcStatus(object sender, System.Timers.ElapsedEventArgs e)
public void RefreshPlc()
{
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc"));
if (obj != null)
@ -67,10 +83,23 @@ namespace Aucma.Core.CodeBinding.ViewModels
{
PlcState(false);
}
}
/// <summary>
/// 扫码器状态刷新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void RefreshScanner()
{
string ip1 = Appsettings.app("Middleware", "Scanner1", "Ip");
string ip2 = Appsettings.app("Middleware", "Scanner2", "Ip");
bool flag1 = MvCodeHelper.ConnectionStatus(ip1);
bool flag2 = MvCodeHelper.ConnectionStatus(ip2);
Scanner1State(flag1);
Scanner2State(flag2);
}
#endregion
#region 更换界面
public System.Windows.Controls.UserControl _content;
@ -80,9 +109,9 @@ namespace Aucma.Core.CodeBinding.ViewModels
get => _content;
set => SetProperty(ref _content, value);
}
#endregion
#region 窗口操作
/// <summary>
/// 窗口操作
@ -232,9 +261,125 @@ namespace Aucma.Core.CodeBinding.ViewModels
PlcUIIcon = "Assets/Images/Red.png";
}
});
}
#endregion
#region 扫码器1状态
/// <summary>
/// UI 展示状态-文字
/// </summary>
public string _scanner1UIStatusWb;
public string Scanner1UIStatusWb
{
//get { return plcUIStatusWb; }
//set { plcUIStatusWb = value; RaisePropertyChanged("PlcUIStatusWb"); }
get => _scanner1UIStatusWb;
set => SetProperty(ref _scanner1UIStatusWb, value);
}
/// <summary>
/// UI 展示状态-颜色
/// </summary>
public string _scanner1UIColor;
public string Scanner1UIColor
{
//get { return plcUIColor; }
//set { plcUIColor = value; RaisePropertyChanged("PlcUIColor"); }
get => _scanner1UIColor;
set => SetProperty(ref _scanner1UIColor, value);
}
/// <summary>
/// UI 展示状态-图标
/// </summary>
public string _scanner1UIIcon;
public string Scanner1UIIcon
{
//get { return plcUIIcon; }
//set { plcUIIcon = value; RaisePropertyChanged("plcUIIcon"); }
get => _scanner1UIIcon;
set => SetProperty(ref _scanner1UIIcon, value);
}
/// <summary>
/// 扫码器1连接状态-true:连接成功false:失败
/// </summary>
/// <param name="type"></param>
public void Scanner1State(bool type)
{
Application.Current.Dispatcher.Invoke(() =>
{
if (type)
{
Scanner1UIStatusWb = "扫码器1连接成功";
Scanner1UIColor = "Green";
Scanner1UIIcon = "Assets/Images/Green.png";
}
else
{
Scanner1UIStatusWb = "扫码器1状态异常";
Scanner1UIColor = "Red";
Scanner1UIIcon = "Assets/Images/Red.png";
}
});
}
#endregion
#region 扫码器2状态
/// <summary>
/// UI 展示状态-文字
/// </summary>
public string _scanner2UIStatusWb;
public string Scanner2UIStatusWb
{
//get { return plcUIStatusWb; }
//set { plcUIStatusWb = value; RaisePropertyChanged("PlcUIStatusWb"); }
get => _scanner2UIStatusWb;
set => SetProperty(ref _scanner2UIStatusWb, value);
}
/// <summary>
/// UI 展示状态-颜色
/// </summary>
public string _scanner2UIColor;
public string Scanner2UIColor
{
//get { return plcUIColor; }
//set { plcUIColor = value; RaisePropertyChanged("PlcUIColor"); }
get => _scanner2UIColor;
set => SetProperty(ref _scanner2UIColor, value);
}
/// <summary>
/// UI 展示状态-图标
/// </summary>
public string _scanner2UIIcon;
public string Scanner2UIIcon
{
//get { return plcUIIcon; }
//set { plcUIIcon = value; RaisePropertyChanged("plcUIIcon"); }
get => _scanner2UIIcon;
set => SetProperty(ref _scanner2UIIcon, value);
}
/// <summary>
/// 扫码器2连接状态-true:连接成功false:失败
/// </summary>
/// <param name="type"></param>
public void Scanner2State(bool type)
{
Application.Current.Dispatcher.Invoke(() =>
{
if (type)
{
Scanner2UIStatusWb = "扫码器2连接成功";
Scanner2UIColor = "Green";
Scanner2UIIcon = "Assets/Images/Green.png";
}
else
{
Scanner2UIStatusWb = "扫码器2状态异常";
Scanner2UIColor = "Red";
Scanner2UIIcon = "Assets/Images/Red.png";
}
});
}
#endregion
}
}

@ -77,16 +77,16 @@
<TextBlock x:Name="PLCState" Text="{Binding PlcUIStatusWb}" VerticalAlignment="Center" Foreground="{Binding PlcUIColor}" FontSize="15" Margin="10,0"/>
<Border Width="30" Height="30" CornerRadius="15">
<Border.Background>
<ImageBrush x:Name="PlcStatusImage" ImageSource="/Assets/Images/Green.png"/>
<ImageBrush x:Name="Scanner1Status" ImageSource="{Binding Scanner1UIIcon}"/>
</Border.Background>
</Border>
<TextBlock x:Name="DB" Text="数据库连接成功" VerticalAlignment="Center" Foreground="Green" FontSize="15" Margin="10,0"/>
<TextBlock x:Name="DB" Text="{Binding Scanner1UIStatusWb}" VerticalAlignment="Center" Foreground="{Binding Scanner1UIColor}" FontSize="15" Margin="10,0"/>
<Border Width="30" Height="30" CornerRadius="15">
<Border.Background>
<ImageBrush x:Name="BarCodeStatus" ImageSource="/Assets/Images/Green.png"/>
<ImageBrush x:Name="BarCodeStatus" ImageSource="{Binding Scanner2UIIcon}"/>
</Border.Background>
</Border>
<TextBlock x:Name="BarCodeStatusTxt" Text="扫描器连接成功" VerticalAlignment="Center" Foreground="Green" FontSize="15" Margin="10,0"/>
<TextBlock x:Name="BarCodeStatusTxt" Text="{Binding Scanner2UIStatusWb}" VerticalAlignment="Center" Foreground="{Binding Scanner2UIColor}" FontSize="15" Margin="10,0"/>
</StackPanel>
</Grid>
</Border>

@ -80,6 +80,8 @@ namespace Aucma.Core.PLc
//melsecMcNet.GetPipeSocket().SetMultiPorts(new int[] { 6000, 6001 });
try
{
// 先关闭再重连,防止多次重连
melsecMcNet.ConnectClose();
OperateResult connect = melsecMcNet.ConnectServer();
if (connect.IsSuccess)
{
@ -444,7 +446,8 @@ namespace Aucma.Core.PLc
try
{
melsecMcNet.ReceiveTimeOut = 2000;
OperateResult<bool> read = await melsecMcNet.ReadBoolAsync(address);
// 2023-11-14变成同步方法异步心跳导致信号滞后会重复请求重连
OperateResult<bool> read = melsecMcNet.ReadBool(address);
if (read.IsSuccess)
{
IsConnected = true;

@ -81,7 +81,7 @@ namespace Aucma.Core.RunPlc
{
item.IsConnect = false;
//Console.WriteLine($"{item.EquipName}:PLC连接失败");
System.GC.Collect();
// System.GC.Collect();
bool r = item.plc.Connect(item.IP, item.Port);
if (r)
{

@ -56,7 +56,7 @@ namespace Aucma.Core.Scanner
/// 获取不到任务设备即连接失败
/// </summary>
/// <returns></returns>
public bool ConnectionStatus(string ip)
public static bool ConnectionStatus(string ip)
{
// 遍历所有已打开相机
foreach (KeyValuePair<MvCodeReader, string> hashmap in m_cMyDevices)
@ -66,11 +66,16 @@ namespace Aucma.Core.Scanner
return true;
}
}
// 没有连接上,重新获取并打开设备
Task.Run(() =>
{
DeviceListAcqAndOpen();
});
return false;
}
#endregion
#region 获取设备列表
#region 获取并打开设备列表
/// <summary>
/// 获取设备列表
/// </summary>

Loading…
Cancel
Save