add-添加AGV实时任务与状态监听

dev
liuwf 2 months ago
parent b3a63f8514
commit bb6c1e03e5

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace SlnMesnac.WPF.Converter.AgvAndTask
{
public class AgvNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is long nextPointId) // 检查是否为 long 类型
{
return nextPointId switch
{
8 => "3楼叉车",
9 => "2楼叉车",
_ => "未知AGV",
};
}
return "未知AGV"; // 如果值不是 long 类型返回未知AGV
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace SlnMesnac.WPF.Converter.AgvAndTask
{
public class TaskStatusConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is int status)
{
return status switch
{
0 => "未下发",
1 => "已下发",
> 1 and < 6 => "执行中",
>= 6 => "执行完成",
_ => "未知状态",
};
}
return "未知状态";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

@ -65,8 +65,8 @@
<Button Content="设备监控" x:Name="DevMonitor" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=DevMonitor}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#0099FF" BorderBrush="#0099FF" Margin="0,0,10,0"/>
<Button Content="生产管理" Visibility="Collapsed" x:Name="ProdMgmt" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=ProdMgmt}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#0099FF" BorderBrush="#0099FF" Margin="0,0,10,0"/>
<Button Content="手动叫料" x:Name="ManualDelivery" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=ManualDelivery}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#0099FF" BorderBrush="#0099FF" Margin="0,0,10,0"/>
<Button Content="AGV监听" x:Name="ManualDelivery1" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=ManualDelivery}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#0099FF" BorderBrush="#0099FF" Margin="0,0,10,0"/>
<Button Content="AGV监听" x:Name="AgvAndTaskPage" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=AgvAndTaskPage}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#0099FF" BorderBrush="#0099FF" Margin="0,0,10,0"/>
<Button Content="生产统计" x:Name="ProdStatistics" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=ProdStatistics}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#0099FF" BorderBrush="#0099FF" Margin="0,0,10,0"/>

@ -4,8 +4,15 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SlnMesnac.WPF.Page"
mc:Ignorable="d"
mc:Ignorable="d" FontFamily="Microsoft YaHei"
xmlns:local1="clr-namespace:SlnMesnac.WPF.Converter.AgvAndTask"
d:DesignHeight="750" d:DesignWidth="1920" Background="Transparent">
<Control.Resources>
<local1:TaskStatusConverter x:Key="TaskStatusConverter"/>
<local1:AgvNameConverter x:Key="AgvNameConverter"/>
<!-- 确保类名大小写正确 -->
</Control.Resources>
<Grid Margin="5,5">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
@ -25,26 +32,26 @@
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="CadetBlue" BorderThickness="0,0,0,0" CornerRadius="0" Background="Transparent" Margin="1,6,5,5" >
<TextBlock Text="AGV实时状态" FontSize="20" FontWeight="Bold" Foreground="#0288d1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Text="AGV实时状态" FontSize="35" FontWeight="Bold" Foreground="#0288d1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<!--计划列表-->
<Border Grid.Row="1" Grid.Column="0" BorderBrush="Green" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="1,1,5,5">
<DataGrid Grid.Row="0" ItemsSource="{Binding PalletTaskDataGrid}" Background="Transparent"
FontSize="15" ColumnHeaderHeight="35"
RowHeight="31" AutoGenerateColumns="False" RowHeaderWidth="0"
<Border Grid.Row="1" Grid.Column="0" BorderBrush="Green" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="1,10,5,5">
<DataGrid Grid.Row="0" ItemsSource="{Binding WcsAgvStatusDataGrid}" Background="Transparent"
FontSize="20" ColumnHeaderHeight="75"
RowHeight="61" AutoGenerateColumns="False" RowHeaderWidth="0"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderThickness="0" CanUserAddRows="False" HorizontalAlignment="Center"
ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderThickness="2" CanUserAddRows="False" HorizontalAlignment="Center"
Foreground="#FFFFFF" >
<!--resourceStyle 399行修改选中字体颜色-->
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding AgvName}" Header="AGV名称" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Online}" Header="在线状态" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding AgvName}" Header="AGV名称信息" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Online}" Header="在线状态" Width="*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Battery}" Header="电量" Width="*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Speed}" Header="速度" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Speed}" Header="速度" Width="*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding PosX}" Header="X轴坐标" Width="*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding PosY}" Header="Y轴坐标" Width="*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Timestamp}" Header="更新时间" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Timestamp,StringFormat=\{0:yyyy-MM-dd HH:mm:ss \}}" Header="更新时间" Width="2*" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
@ -59,26 +66,28 @@
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="CadetBlue" BorderThickness="0,0,0,0" CornerRadius="0" Background="Transparent" Margin="1,6,5,5" >
<TextBlock Text="AGV任务列表" FontSize="20" FontWeight="Bold" Foreground="#0288d1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Text="AGV任务列表" FontSize="35" FontWeight="Bold" Foreground="#0288d1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<!--计划列表-->
<Border Grid.Row="1" Grid.Column="0" BorderBrush="Green" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="1,1,5,5">
<DataGrid Grid.Row="0" ItemsSource="{Binding BarCodeTaskDataGrid}" Background="Transparent"
FontSize="15" ColumnHeaderHeight="35"
RowHeight="31" AutoGenerateColumns="False" RowHeaderWidth="0"
<DataGrid Grid.Row="0" ItemsSource="{Binding WcsTaskDataGrid}" Background="Transparent"
FontSize="20" ColumnHeaderHeight="75"
RowHeight="61" AutoGenerateColumns="False" RowHeaderWidth="0"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderThickness="0" CanUserAddRows="False" HorizontalAlignment="Center"
ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderThickness="2" CanUserAddRows="False" HorizontalAlignment="Center"
Foreground="#FFFFFF" >
<!--resourceStyle 399行修改选中字体颜色-->
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ObjId}" Header="序号" Width="1*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding BarCode}" Header="条码" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding PlanCode}" Header="计划编号" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding MaterialCode}" Header="物料编号" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding RecordTime ,StringFormat=\{0:MM月dd日 HH:mm\}}" Header="记录时间" Width="2*" IsReadOnly="True"/>
<!--<DataGridTextColumn Binding="{Binding ObjId}" Header="序号" Width="1*" IsReadOnly="True"/>-->
<DataGridTextColumn Binding="{Binding NextPointId,Converter={StaticResource AgvNameConverter} }" Header="agv名称信息" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding TaskType}" Header="任务类型" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding TaskStatus, Converter={StaticResource TaskStatusConverter}}" Header="任务状态" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding CurrPointNo}" Header="起始站点" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding EndPointNo}" Header="目的站点" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding CreateTime ,StringFormat=\{0:yyyy-MM-dd HH:mm:ss \}}" Header="创建时间" Width="2*" IsReadOnly="True"/>
<!--<DataGridTextColumn Binding="{Binding RealEndTime ,StringFormat=\{0:MM月dd日 HH:mm\}}" Header="完成时间" Width="1*" IsReadOnly="True"/>-->
<DataGridTemplateColumn Header="操作" Width="2*">
<!--<DataGridTemplateColumn Header="操作" Width="2*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
@ -88,7 +97,7 @@ Foreground="#FFFFFF" >
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGridTemplateColumn>-->
</DataGrid.Columns>
</DataGrid>
</Border>

@ -25,7 +25,7 @@ namespace SlnMesnac.WPF.Page
{
InitializeComponent();
this.DataContext = new ProdStatisticsViewModel();
this.DataContext = new AgvAndTaskViewModel();
}
}
}

@ -2151,7 +2151,6 @@ namespace SlnMesnac.WPF.Page
}));
MachineStatusDto machineStatusDto = new MachineStatusDto();
machineStatusDto.deviceId = 1019;
machineStatusDto.status = signal1_2 && signal2_2;

@ -0,0 +1,153 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Business;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.WPF.ViewModel
* 14008fcc-0a31-4f1e-bc80-9f9ea84d3de5
*
* WenJY
* wenjy@mesnac.com
* 2024-04-10 16:18:57
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.WPF.ViewModel
{
/// <summary>
/// 生产统计ViewModel
/// </summary>
internal class AgvAndTaskViewModel : ViewModelBase
{
private readonly ISqlSugarClient? sqlSugarClient;
// private readonly ProdCompletionBusiness _prodCompletionBusiness;
private System.Timers.Timer refreshTimer = new System.Timers.Timer(5000);
public AgvAndTaskViewModel()
{
sqlSugarClient = App.ServiceProvider.GetService<ISqlSugarClient>();
// _prodCompletionBusiness = App.ServiceProvider.GetService<ProdCompletionBusiness>();
// DeletePalletCommand = new RelayCommand<string>(DeletePallet);
// DeleteBarCodeCommand = new RelayCommand<string> (DeleteBarCode);
// _palletStowBusiness.RefreshPalletTaskListEvent += RefreshPalletTaskDataGrid;
refreshTimer.Elapsed += OnTimedEvent;
refreshTimer.AutoReset = true; // 设置为自动重置
refreshTimer.Enabled = true; // 启用定时器
}
private async void OnTimedEvent(object sender, System.Timers.ElapsedEventArgs e)
{
await RefreshWcsAgvStatusDataGrid();
await RefreshWcsTaskDataGrid();
}
#region 参数定义
/// <summary>
/// AGV任务队列DataGrid
/// </summary>
private ObservableCollection<WcsTask> wcsTaskDataGrid = new ObservableCollection<WcsTask>();
public ObservableCollection<WcsTask> WcsTaskDataGrid
{
get { return wcsTaskDataGrid; }
set { wcsTaskDataGrid = value; RaisePropertyChanged(() => WcsTaskDataGrid); }
}
/// <summary>
/// AGV状态队列DataGrid
/// </summary>
private ObservableCollection<WcsAgvStatus> wcsAgvStatusDataGrid = new ObservableCollection<WcsAgvStatus>();
public ObservableCollection<WcsAgvStatus> WcsAgvStatusDataGrid
{
get { return wcsAgvStatusDataGrid; }
set { wcsAgvStatusDataGrid = value; RaisePropertyChanged(() => WcsAgvStatusDataGrid); }
}
#endregion
#region 事件定义
// public RelayCommand<string> DeletePalletCommand { get;set; }
// public RelayCommand<string> DeleteBarCodeCommand { get; set; }
#endregion
/// <summary>
/// 刷新AGV状态信息
/// </summary>
/// <param name="palletTasks"></param>
private async Task RefreshWcsAgvStatusDataGrid()
{
List<WcsAgvStatus> agvList = await sqlSugarClient.AsTenant().GetConnection("mes").Queryable<WcsAgvStatus>().ToListAsync();
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
WcsAgvStatusDataGrid.Clear();
foreach (var agv in agvList)
{
WcsAgvStatusDataGrid.Add(agv);
}
}));
}
/// <summary>
/// 刷新AGV状态信息
/// </summary>
/// <param name="palletTasks"></param>
private async Task RefreshWcsTaskDataGrid()
{
List<WcsTask> agvList = await sqlSugarClient.AsTenant().GetConnection("mes").Queryable<WcsTask>().Where(x => x.NextPointId == 8 || x.NextPointId==9).ToListAsync();
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
WcsTaskDataGrid.Clear();
foreach (var agv in agvList)
{
WcsTaskDataGrid.Add(agv);
}
}));
}
}
}

@ -25,6 +25,7 @@ namespace SlnMesnac.WPF.ViewModel
private readonly GenerateControl generateControl = new GenerateControl();
private readonly BaseConfigInfoPage configInfoPage = new BaseConfigInfoPage();
private readonly RecipeManagePage recipeManagePage = new RecipeManagePage();
private readonly AgvAndTaskMonitorPage agvAndTaskMonitorPage = new AgvAndTaskMonitorPage();
#region 参数定义
/// <summary>
@ -97,10 +98,10 @@ namespace SlnMesnac.WPF.ViewModel
ControlOnClickCommand = new RelayCommand<object>(obj => ControlOnClick(obj));
FormControlCommand = new RelayCommand<object>(x => FormControl(x));
}
/// <summary>
/// 窗体控制
@ -142,6 +143,9 @@ namespace SlnMesnac.WPF.ViewModel
case "RecipeManage":
UserContent = recipeManagePage;
break;
case "AgvAndTaskPage":
UserContent = agvAndTaskMonitorPage;
break;
// 还原 或者 最大化当前窗口
case "Normal":
if (Application.Current.MainWindow.WindowState == WindowState.Normal)

Loading…
Cancel
Save