change - plc,扫码器状态刷新

collectionStore
liuwf 1 year ago
parent d34e636509
commit 299b7eb6f4

1
.gitignore vendored

@ -10,3 +10,4 @@
*.vs
*.csproj.AssemblyReference.cache
*/obj/
/Aucma.Scada.UI/bin/Debug/Log/2023-12-08

@ -38,7 +38,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)

@ -250,6 +250,12 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Resource Include="templates\image\Red.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="templates\image\Green.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
@ -294,6 +300,10 @@
<Project>{deabc30c-ec6f-472e-bd67-d65702fdaf74}</Project>
<Name>HighWayIot.Log4net</Name>
</ProjectReference>
<ProjectReference Include="..\HighWayIot.Plc\HighWayIot.Plc.csproj">
<Project>{4EE4C3E2-AC45-4275-8017-E99D70FC1F52}</Project>
<Name>HighWayIot.Plc</Name>
</ProjectReference>
<ProjectReference Include="..\HighWayIot.Repository\HighWayIot.Repository.csproj">
<Project>{d0dc3cfb-6748-4d5e-b56a-76fdc72ab4b3}</Project>
<Name>HighWayIot.Repository</Name>

@ -59,11 +59,6 @@
<DropShadowEffect Color="#1254AB" Direction="270" BlurRadius="10" ShadowDepth="5" Opacity="0.5"/>
</Border.Effect>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Orientation="Horizontal">
<Button Content="入库监控" x:Name="instoreInfo" Command="{Binding ControlOnClickCommand}" CommandParameter="{Binding Name,ElementName=instoreInfo}" Style="{StaticResource BUTTON_AGREE}" Width="80" Height="40" Background="#4285DE" BorderBrush="#FF36B5C1" Margin="5 0" FontSize="17"/>
<Button Content="出库监控" x:Name="outstoreInfo" Command="{Binding ControlOnClickCommand}" CommandParameter="{Binding Name,ElementName=outstoreInfo}" Style="{StaticResource BUTTON_AGREE}" Width="80" Height="40" Background="#4285DE" BorderBrush="#FF36B5C1" Margin="5 0" FontSize="17"/>
@ -75,110 +70,38 @@
<Button Content="退 出" x:Name="Exit" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=Exit}" Style="{StaticResource BUTTON_AGREE}" Width="80" Height="40" Background="#FF0033" BorderBrush="#FF0033" Margin="5 0" FontSize="17"/>
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right" Orientation="Horizontal">
<!--单行状态显示-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<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 ShellScannerStatus}" Value="0">
<Setter Property="Shape.Fill" Value="Orange"/>
</DataTrigger>
<DataTrigger Binding="{Binding ShellScannerStatus}" Value="1">
<Setter Property="Shape.Fill" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding ShellScannerStatus}" 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="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 BoldScannerStatus}" Value="0">
<Setter Property="Shape.Fill" Value="Orange"/>
</DataTrigger>
<DataTrigger Binding="{Binding BoldScannerStatus}" Value="1">
<Setter Property="Shape.Fill" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding BoldScannerStatus}" 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 PlcStatus}" Value="0">
<Setter Property="Shape.Fill" Value="Orange"/>
</DataTrigger>
<DataTrigger Binding="{Binding PlcStatus}" Value="1">
<Setter Property="Shape.Fill" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding PlcStatus}" Value="2">
<Setter Property="Shape.Fill" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Ellipse.Style>
</Ellipse>
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<TextBlock Text="PLC状态" FontSize="15" Foreground="#FFFFFF" Margin="2,0,10,0"/>
</StackPanel>
</Grid>
</StackPanel>
</Grid>
<StackPanel Height="50" Orientation="Horizontal" HorizontalAlignment="Right">
<Border Width="30" Height="30" CornerRadius="15">
<Border.Background>
<ImageBrush x:Name="MesDbStatus" ImageSource="{Binding MesUIIcon}"/>
</Border.Background>
</Border>
<TextBlock x:Name="MesDbStateTxt" Text="{Binding MesDbUIStatusWb}" VerticalAlignment="Center" Foreground="{Binding MesDbUIColor}" FontSize="15" Margin="10,0"/>
<Border Width="30" Height="30" CornerRadius="15">
<Border.Background>
<ImageBrush x:Name="PlcStatus" ImageSource="{Binding PlcUIIcon}"/>
</Border.Background>
</Border>
<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="NdPlcStatus" ImageSource="{Binding NdPlcUIIcon}"/>
</Border.Background>
</Border>
<TextBlock x:Name="NdPLCState" Text="{Binding NdPlcUIStatusWb}" VerticalAlignment="Center" Foreground="{Binding NdPlcUIColor}" FontSize="15" Margin="10,0"/>
<Border Width="30" Height="30" CornerRadius="15">
<Border.Background>
<ImageBrush x:Name="Scanner1Status" ImageSource="{Binding Scanner1UIIcon}"/>
</Border.Background>
</Border>
<TextBlock x:Name="Scanner1" 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="Scanner2Status" ImageSource="{Binding Scanner2UIIcon}"/>
</Border.Background>
</Border>
<TextBlock x:Name="Scanner2" Text="{Binding Scanner2UIStatusWb}" VerticalAlignment="Center" Foreground="{Binding Scanner2UIColor}" FontSize="15" Margin="10,0"/>
</StackPanel>
</Grid>

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

@ -1,12 +1,16 @@
using Aucma.Scada.UI.Page.AssemblyPlan;
using Aucma.Core.Scanner;
using Aucma.Scada.UI.Page.AssemblyPlan;
using Aucma.Scada.UI.Page.InStoreInfo;
using Aucma.Scada.UI.Page.InventoryInfo;
using Aucma.Scada.UI.Page.OutStoreInfo;
using Aucma.Scada.UI.Page.TaskInfo;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HighWayIot.Config;
using HighWayIot.Log4net;
using HighWayIot.Plc;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows;
@ -15,6 +19,9 @@ namespace Aucma.Scada.UI.viewModel
{
public class MainViewModel : ViewModelBase
{
private AppConfig appConfig = AppConfig.Instance;
private PlcPool _pool = PlcPool.Instance;
private Dictionary<string, IPlc> _plcDictionary = new Dictionary<string, IPlc>();
private LogHelper logHelper = LogHelper.Instance;
private readonly LogInfoControl logInfoControl = new LogInfoControl();
private readonly InStoreInfoControl inStoreInfoControl = new InStoreInfoControl();
@ -25,6 +32,7 @@ namespace Aucma.Scada.UI.viewModel
public MainViewModel()
{
ControlOnClickCommand = new RelayCommand<object>(obj => ControlOnClick(obj));
OpenSystemKeyboardCommand = new RelayCommand(OpenSystemKeyboard);
@ -32,6 +40,7 @@ namespace Aucma.Scada.UI.viewModel
FormControlCommand = new RelayCommand<object>(obj => FormControl(obj));
UserContent = inStoreInfoControl;
init();
}
#region 参数定义
@ -213,5 +222,371 @@ namespace Aucma.Scada.UI.viewModel
}
}
public void init()
{
// 设备状态刷新定时器
System.Timers.Timer timer = new System.Timers.Timer(1000 * 5);
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)
{
RefreshMesDb();
RefreshPlc();
RefreshScanner();
}
/// <summary>
/// 数据库状态刷新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void RefreshMesDb()
{
MesDbState(true);
}
/// <summary>
/// plc状态刷新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void RefreshPlc()
{
_plcDictionary = _pool.GetAll();
// 箱壳状态
_plcDictionary.TryGetValue(appConfig.shellStoreCode, out IPlc _plc);
if (_plc != null)
{
PlcState(true);
}
else
{
PlcState(false);
}
// 内胆状态
_plcDictionary.TryGetValue(appConfig.linerStoreCode, out IPlc _ndPlc);
if (_ndPlc != null)
{
NdPlcState(true);
}
else
{
NdPlcState(false);
}
}
/// <summary>
/// 扫码器状态刷新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void RefreshScanner()
{
string ip1 = appConfig.shellHikRobotIp;
string ip2 = appConfig.linerHikRobotIp;
bool flag1 = MvCodeHelper.ConnectionStatus(ip1);
bool flag2 = MvCodeHelper.ConnectionStatus(ip2);
Scanner1State(flag1);
Scanner2State(flag2);
}
#endregion
#region MES数据库状态
/// <summary>
/// MES数据库-文字
/// </summary>
public string _mesDbUIStatusWb;
public string MesDbUIStatusWb
{
get => _mesDbUIStatusWb;
set { _mesDbUIStatusWb = value; RaisePropertyChanged(nameof(MesDbUIStatusWb)); }
}
/// <summary>
/// MES数据库-颜色
/// </summary>
public string _mesDbUIColor;
public string MesDbUIColor
{
get => _mesDbUIColor;
set { _mesDbUIColor = value; RaisePropertyChanged(nameof(MesDbUIColor)); }
}
/// <summary>
/// MES数据库-图标
/// </summary>
public string _mesUIIcon;
public string MesUIIcon
{
get => _mesUIIcon;
set { _mesUIIcon = value; RaisePropertyChanged(nameof(MesUIIcon)); }
}
/// <summary>
/// MES数据库连接状态
/// </summary>
/// <param name="type"></param>
public void MesDbState(bool type)
{
Application.Current.Dispatcher.Invoke(() =>
{
if (type)
{
MesDbUIStatusWb = "MES数据库连接成功";
MesDbUIColor = "Green";
MesUIIcon = "templates/image/Green.png";
}
else
{
MesDbUIStatusWb = "MES数据库异常";
MesDbUIColor = "Red";
MesUIIcon = "templates/image/Red.png";
}
});
}
#endregion
#region 箱壳plc 状态
/// <summary>
/// UI plc 展示状态-文字
/// </summary>
public string _plcUIStatusWb;
public string PlcUIStatusWb
{
get => _plcUIStatusWb;
set { _plcUIStatusWb = value; RaisePropertyChanged(nameof(PlcUIStatusWb)); }
}
/// <summary>
/// UI plc 展示状态-颜色
/// </summary>
public string _plcUIColor;
public string PlcUIColor
{
get => _plcUIColor;
set { _plcUIColor = value; RaisePropertyChanged(nameof(PlcUIColor)); }
}
/// <summary>
/// UI plc 展示状态-图标
/// </summary>
public string _plcUIIcon;
public string PlcUIIcon
{
get => _plcUIIcon;
set { _plcUIIcon = value; RaisePropertyChanged(nameof(PlcUIIcon)); }
}
/// <summary>
/// PLC连接状态-true:连接成功false:失败
/// </summary>
/// <param name="type"></param>
public void PlcState(bool type)
{
Application.Current.Dispatcher.Invoke(() =>
{
if (type)
{
PlcUIStatusWb = "箱壳PLC连接成功";
PlcUIColor = "Green";
PlcUIIcon = "templates/image/Green.png";
}
else
{
PlcUIStatusWb = "箱壳PLC状态异常";
PlcUIColor = "Red";
PlcUIIcon = "templates/image/Red.png";
}
});
}
#endregion
#region 内胆plc 状态
/// <summary>
/// UI plc 展示状态-文字
/// </summary>
public string _ndPlcUIStatusWb;
public string NdPlcUIStatusWb
{
get => _ndPlcUIStatusWb;
set { _ndPlcUIStatusWb = value; RaisePropertyChanged(nameof(NdPlcUIStatusWb)); }
}
/// <summary>
/// UI plc 展示状态-颜色
/// </summary>
public string _ndPlcUIColor;
public string NdPlcUIColor
{
get => _ndPlcUIColor;
set { _ndPlcUIColor = value; RaisePropertyChanged(nameof(NdPlcUIColor)); }
}
/// <summary>
/// UI plc 展示状态-图标
/// </summary>
public string _ndPlcUIIcon;
public string NdPlcUIIcon
{
get => _ndPlcUIIcon;
set { _ndPlcUIIcon = value; RaisePropertyChanged(nameof(NdPlcUIIcon)); }
}
/// <summary>
/// PLC连接状态-true:连接成功false:失败
/// </summary>
/// <param name="type"></param>
public void NdPlcState(bool type)
{
Application.Current.Dispatcher.Invoke(() =>
{
if (type)
{
NdPlcUIStatusWb = "内胆PLC连接成功";
NdPlcUIColor = "Green";
NdPlcUIIcon = "templates/image/Green.png";
}
else
{
NdPlcUIStatusWb = "内胆PLC状态异常";
NdPlcUIColor = "Red";
NdPlcUIIcon = "templates/image/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 { _scanner1UIStatusWb = value; RaisePropertyChanged(nameof(Scanner1UIStatusWb)); }
}
/// <summary>
/// UI 展示状态-颜色
/// </summary>
public string _scanner1UIColor;
public string Scanner1UIColor
{
//get { return plcUIColor; }
//set { plcUIColor = value; RaisePropertyChanged("PlcUIColor"); }
get => _scanner1UIColor;
set { _scanner1UIColor = value; RaisePropertyChanged(nameof(Scanner1UIColor)); }
}
/// <summary>
/// UI 展示状态-图标
/// </summary>
public string _scanner1UIIcon;
public string Scanner1UIIcon
{
//get { return plcUIIcon; }
//set { plcUIIcon = value; RaisePropertyChanged("plcUIIcon"); }
get => _scanner1UIIcon;
set { _scanner1UIIcon = value; RaisePropertyChanged(nameof(Scanner1UIIcon)); }
}
/// <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 = "templates/image/Green.png";
}
else
{
Scanner1UIStatusWb = "扫码器1状态异常";
Scanner1UIColor = "Red";
Scanner1UIIcon = "templates/image/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 { _scanner2UIStatusWb = value; RaisePropertyChanged(nameof(Scanner2UIStatusWb)); }
}
/// <summary>
/// UI 展示状态-颜色
/// </summary>
public string _scanner2UIColor;
public string Scanner2UIColor
{
//get { return plcUIColor; }
//set { plcUIColor = value; RaisePropertyChanged("PlcUIColor"); }
get => _scanner2UIColor;
set { _scanner2UIColor = value; RaisePropertyChanged(nameof(Scanner2UIColor)); }
}
/// <summary>
/// UI 展示状态-图标
/// </summary>
public string _scanner2UIIcon;
public string Scanner2UIIcon
{
//get { return plcUIIcon; }
//set { plcUIIcon = value; RaisePropertyChanged("plcUIIcon"); }
get => _scanner2UIIcon;
set { _scanner2UIIcon = value; RaisePropertyChanged(nameof(Scanner2UIIcon)); }
}
/// <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 = "templates/image/Green.png";
}
else
{
Scanner2UIStatusWb = "扫码器2状态异常";
Scanner2UIColor = "Red";
Scanner2UIIcon = "templates/image/Red.png";
}
});
}
#endregion
}
}

Loading…
Cancel
Save