Browse Source

小配料调试

样式分支
pry 1 year ago
parent
commit
3c46ee24c8
8 changed files with 162 additions and 48 deletions
  1. +105
    -12
      BPASmartClient.SmallBatchingSystem/Services/Control.cs
  2. +20
    -20
      BPASmartClient.SmallBatchingSystem/Services/PlcServer.cs
  3. +8
    -2
      BPASmartClient.SmallBatchingSystem/ViewModels/GrindArenaceousViewModel.cs
  4. +6
    -2
      BPASmartClient.SmallBatchingSystem/ViewModels/OutletManagementViewModel.cs
  5. +8
    -5
      BPASmartClient.SmallBatchingSystem/ViewModels/RecipeControlViewModel.cs
  6. +7
    -3
      BPASmartClient.SmallBatchingSystem/ViewModels/RecipeViewModel.cs
  7. +7
    -3
      BPASmartClient.SmallBatchingSystem/ViewModels/SiloManagementViewModel.cs
  8. +1
    -1
      BPASmartClient.SmallBatchingSystem/Views/RecipeControlView.xaml

+ 105
- 12
BPASmartClient.SmallBatchingSystem/Services/Control.cs View File

@@ -1,4 +1,4 @@
#define test
//#define ModelSwitch

using BPA.Helper;
using BPASmartClient.SmallBatchingSystem;
@@ -38,8 +38,8 @@ namespace BPASmartClient.SmallBatchingSystem
{
if (MakeOrderQueue.TryDequeue(out RecipeInfo recipeInfo))
{
//ProcessOne(recipeInfo);
ProcessTwo(recipeInfo);
ProcessOne(recipeInfo);
//ProcessTwo(recipeInfo);
}
}
Thread.Sleep(10);
@@ -80,8 +80,8 @@ namespace BPASmartClient.SmallBatchingSystem
if (res != null)
{
StatusNotify(res.SiloName, Status.正在配料);
RunLog($"写重量地址:{GetWeightAdd(res.SiloLoc)},重量:{temp1.SiloWeight}");
PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)temp1.SiloWeight);
RunLog($"写重量地址:{GetWeightAdd(res.SiloLoc)},重量:{temp1.SiloWeight * 10}");
PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)(temp1.SiloWeight * 10));
RunLog($"写启动信号地址:{GetStartSingleAdd(res.SiloLoc)}");
PlcServer.GetInstance.WriteData(GetStartSingleAdd(res.SiloLoc), true);
while (!PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成
@@ -109,6 +109,97 @@ namespace BPASmartClient.SmallBatchingSystem
RunLog($"【{recipeInfo.RecipeName}】配方执行完成");
ActionManage.GetInstance.Send("GrindArenaceousCancel");
}


// IsCancel = false;
// Dictionary<int, List<int>> DeviceSoilInfo = new Dictionary<int, List<int>>();
// List<int> OutletInfo = new List<int>();
// recipeInfo.SiloInfoModels.ToList()?.ForEach(item =>
// {
// var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s == item.SiloName) != null);
// if (res != null)
// {
// var soliInfo = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == item.SiloName);
// if (soliInfo != null)
// {
// if (!DeviceSoilInfo.ContainsKey(res.OutletLoc))
// {
// DeviceSoilInfo.Add(res.OutletLoc, new List<int>());
// DeviceSoilInfo[res.OutletLoc].Add(soliInfo.SiloLoc);
// }
// else
// {
// DeviceSoilInfo[res.OutletLoc].Add(soliInfo.SiloLoc);
// }
// }

// }
// });

// foreach (var temp in DeviceSoilInfo)
// {
// PlcServer.GetInstance.WriteData("VW302", (ushort)temp.Key);//设置出料口位置
//#if ModelSwitch
// PlcServer.GetInstance.WriteData("M10.4", true);//定位启动
//#else
// PlcServer.GetInstance.WriteData("M10.0", true);//定位启动
//#endif

// RunLog($"启动定位,出料口位置:{temp.Key}");
// int index = temp.Key - 1;
// if (index >= 0)
// {
// RunLog("等待定位完成");
// while (!PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1);//等待定位反馈
// if (IsCancel) break;
// RunLog("定位完成");
// PlcServer.GetInstance.WriteData("M20.0", false);
// while (PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1);
// if (IsCancel) break;
// RunLog("定位完成,复位成功");
// foreach (var temp1 in temp.Value)
// {
// //var rest = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(temp1.SiloName)) != null);
// //if (rest != null && rest.OutletLoc == temp)
// //{

// var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloLoc == temp1);
// if (res != null)
// {
// var tempRecipe = recipeInfo.SiloInfoModels.FirstOrDefault(p => p.SiloName == res.SiloName);
// if (tempRecipe != null)
// {
// StatusNotify(res.SiloName, Status.正在配料);
// RunLog($"写重量地址:{GetWeightAdd(res.SiloLoc)},重量:{tempRecipe.SiloWeight}");
// PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)(tempRecipe.SiloWeight * 10));
// RunLog($"写启动信号地址:{GetStartSingleAdd(res.SiloLoc)}");
// PlcServer.GetInstance.WriteData(GetStartSingleAdd(res.SiloLoc), true);
// while (!PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成
// if (IsCancel) break;
// RunLog("出料完成,复位出料完成状态");
//#if ModelSwitch
// PlcServer.GetInstance.WriteData("M10.0", false);//复位出料完成信号
//#else
// PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号
//#endif
// while (PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成信号复位成功
// if (IsCancel) break;
// RunLog("出料完成复位成功");
// StatusNotify(res.SiloName, Status.配料完成);
// }
// }
// //}
// }
// if (IsCancel) return;
// }
// }







}

/// <summary>
@@ -179,10 +270,10 @@ namespace BPASmartClient.SmallBatchingSystem
while (!PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成
if (IsCancel) break;
RunLog("出料完成,复位出料完成状态");
#if test
#if ModelSwitch
PlcServer.GetInstance.WriteData("M10.0", false);//复位出料完成信号
#else
PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号
PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号
#endif

while (PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成信号复位成功
@@ -275,7 +366,7 @@ PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号
/// <returns></returns>
private string GetWeightAdd(int num)
{
#if test
#if ModelSwitch
if (num > 0)
{
int add = 0;
@@ -287,10 +378,10 @@ PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号
}
return default;
#else
if (num > 0)
if (num > 0)
{
int add = 0;
if (num >= 1 && num <= 18)
if (num >= 1 && num <= 8)
{
add = 100 + (num - 1) * 2;
}
@@ -312,12 +403,14 @@ PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号

public void RunLog(string info)
{
BPA.Helper.MessageLog.GetInstance.Show(info);
BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.ShowRunLog(info);
Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
}

public void OperationLog(string info)
{
BPA.Helper.MessageLog.GetInstance.Show(info);
BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.ShowUserLog(info);
Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
}
@@ -342,7 +435,7 @@ PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号
/// <returns></returns>
private string GetStartSingleAdd(int num)
{
#if test
#if ModelSwitch
if (num > 0)
{
string Add = string.Empty;
@@ -359,7 +452,7 @@ PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号
}
return default;
#else
if (num > 0)
if (num > 0)
{
string Add = string.Empty;
var t = num / 8;


+ 20
- 20
BPASmartClient.SmallBatchingSystem/Services/PlcServer.cs View File

@@ -28,32 +28,13 @@ namespace BPASmartClient.SmallBatchingSystem
ThreadManage.GetInstance().StartLong(new Action(() =>
{
//带称程序
//var res = ReadData("M20.0", 1);//到达目标位置信号
//if (res != null && res is bool[] bools && bools.Length == 1)
//{
// PlcDataModel.TargetLocComplete = bools[0];
//}

//var res1 = ReadData("M4.0", 1);//通道出料完成
//if (res1 != null && res1 is bool[] bools1 && bools1.Length == 1)
//{
// PlcDataModel.BatchingCompleted = bools1[0];
//}

//var res2 = ReadData("M13.3", 1);//配方配料完成,托盘在放碗或取碗位置
//if (res2 != null && res2 is bool[] bools2 && bools2.Length == 1)
//{
// PlcDataModel.RecipeBatchingComplete = bools2[0];
//}

//定时程序
var res = ReadData("M20.0", 1);//到达目标位置信号
if (res != null && res is bool[] bools && bools.Length == 1)
{
PlcDataModel.TargetLocComplete = bools[0];
}

var res1 = ReadData("M10.0", 1);//通道出料完成
var res1 = ReadData("M4.0", 1);//通道出料完成
if (res1 != null && res1 is bool[] bools1 && bools1.Length == 1)
{
PlcDataModel.BatchingCompleted = bools1[0];
@@ -65,6 +46,25 @@ namespace BPASmartClient.SmallBatchingSystem
PlcDataModel.RecipeBatchingComplete = bools2[0];
}

//定时程序
//var res = ReadData("M20.0", 1);//到达目标位置信号
//if (res != null && res is bool[] bools && bools.Length == 1)
//{
// PlcDataModel.TargetLocComplete = bools[0];
//}

//var res1 = ReadData("M10.0", 1);//通道出料完成
//if (res1 != null && res1 is bool[] bools1 && bools1.Length == 1)
//{
// PlcDataModel.BatchingCompleted = bools1[0];
//}

//var res2 = ReadData("M13.3", 1);//配方配料完成,托盘在放碗或取碗位置
//if (res2 != null && res2 is bool[] bools2 && bools2.Length == 1)
//{
// PlcDataModel.RecipeBatchingComplete = bools2[0];
//}

Thread.Sleep(10);
}), "PLC 数据监听");
});


+ 8
- 2
BPASmartClient.SmallBatchingSystem/ViewModels/GrindArenaceousViewModel.cs View File

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.Toolkit.Mvvm.Input;
using BPA.Helper;
using System.Collections.ObjectModel;
using BPASmartClient.CustomResource.Pages.Model;

namespace BPASmartClient.SmallBatchingSystem.ViewModels
{
@@ -36,13 +37,18 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels
});
}
}), "OpenRecipeStatusMotion", true);
CancelCommand = new RelayCommand(() => { Control.GetInstance.IsCancel = true; ActionManage.GetInstance.Send("GrindArenaceousCancel"); });
CancelCommand = new RelayCommand(() =>
{
if (MessageNotify.GetInstance.ShowDialog($"是否取消配方制作,取消后设备将终止配料过程!", DialogType.Warning))
{
Control.GetInstance.IsCancel = true; ActionManage.GetInstance.Send("GrindArenaceousCancel");
}
});
}

public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } }
private string _mRecipeName;


public ObservableCollection<RecipeStatus> Recipes { get; set; } = new ObservableCollection<RecipeStatus>();
}
}

+ 6
- 2
BPASmartClient.SmallBatchingSystem/ViewModels/OutletManagementViewModel.cs View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BPA.Helper;
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.SmallBatchingSystem.Views;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
@@ -29,8 +30,11 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels
var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.OutletName == o.ToString());
if (res != null)
{
Json<ConfigInfoModel>.Data.OutletInfoModels.Remove(res);
Control.GetInstance.OperationLog($"{res.OutletName} 删除成功");
if (MessageNotify.GetInstance.ShowDialog($"是否删除【{res.OutletName}】出料口,删除后数据将永久丢失!无法找回", DialogType.Warning))
{
Json<ConfigInfoModel>.Data.OutletInfoModels.Remove(res);
Control.GetInstance.OperationLog($"{res.OutletName} 删除成功");
}
}
}
});


+ 8
- 5
BPASmartClient.SmallBatchingSystem/ViewModels/RecipeControlViewModel.cs View File

@@ -10,6 +10,7 @@ using Microsoft.Toolkit.Mvvm.Input;
using BPASmartClient.SmallBatchingSystem.Views;
using BPASmartClient.CustomResource.UserControls.MessageShow;
using BPASmartClient.CustomResource.UserControls;
using BPASmartClient.CustomResource.Pages.Model;

namespace BPASmartClient.SmallBatchingSystem.ViewModels
{
@@ -44,16 +45,18 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels
}
else
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", "配方下发失败,硬件设备状态未装备就绪!");
});
//App.Current.Dispatcher.Invoke(() =>
//{
// NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", "配方下发失败,硬件设备状态未装备就绪!");
//});
MessageNotify.GetInstance.ShowDialog($"配方下发失败,硬件设备状态未装备就绪!", DialogType.Error);

Control.GetInstance.RunLog("配方下发失败,硬件设备状态未装备就绪!");
}
});
});

DeviceInitCommand = new RelayCommand(() => { PlcServer.GetInstance.WriteData("M10.3", true); });
DeviceInitCommand = new RelayCommand(() => { PlcServer.GetInstance.WriteData("M10.4", true); });
}

public RelayCommand DeviceInitCommand { get; set; }


+ 7
- 3
BPASmartClient.SmallBatchingSystem/ViewModels/RecipeViewModel.cs View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BPA.Helper;
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.CustomResource.UserControls;
using BPASmartClient.CustomResource.UserControls.MessageShow;
using BPASmartClient.SmallBatchingSystem.Views;
@@ -31,9 +32,12 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels
var res = Json<ConfigInfoModel>.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString());
if (res != null)
{
Json<ConfigInfoModel>.Data.Recipes.Remove(res);
Control.GetInstance.NotifyPrompt($"{res.RecipeName} 删除成功");
Control.GetInstance.OperationLog($"{res.RecipeName} 删除成功");
if (MessageNotify.GetInstance.ShowDialog($"是否删除【{res.RecipeName}】配方,删除后数据将永久丢失!无法找回", DialogType.Warning))
{
Json<ConfigInfoModel>.Data.Recipes.Remove(res);
Control.GetInstance.NotifyPrompt($"{res.RecipeName} 删除成功");
Control.GetInstance.OperationLog($"{res.RecipeName} 删除成功");
}
}
}
});


+ 7
- 3
BPASmartClient.SmallBatchingSystem/ViewModels/SiloManagementViewModel.cs View File

@@ -8,6 +8,7 @@ using Microsoft.Toolkit.Mvvm.Input;
using BPASmartClient.SmallBatchingSystem.Views;
using System.Collections.ObjectModel;
using BPA.Helper;
using BPASmartClient.CustomResource.Pages.Model;

namespace BPASmartClient.SmallBatchingSystem.ViewModels
{
@@ -29,9 +30,12 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels
var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == o.ToString());
if (res != null)
{
Json<ConfigInfoModel>.Data.SiloInfoModels.Remove(res);
Control.GetInstance.NotifyPrompt($"{res.SiloName} 删除成功");
Control.GetInstance.OperationLog($"{res.SiloName} 删除成功");
if (MessageNotify.GetInstance.ShowDialog($"是否删除【{res.SiloName}】原料,删除后数据将永久丢失!无法找回", DialogType.Warning))
{
Json<ConfigInfoModel>.Data.SiloInfoModels.Remove(res);
Control.GetInstance.NotifyPrompt($"{res.SiloName} 删除成功");
Control.GetInstance.OperationLog($"{res.SiloName} 删除成功");
}
}
}
});


+ 1
- 1
BPASmartClient.SmallBatchingSystem/Views/RecipeControlView.xaml View File

@@ -28,7 +28,7 @@
Height="30"
Margin="10,0,10,0"
HorizontalAlignment="Right"
Command="{Binding AddCommand}"
Command="{Binding DeviceInitCommand}"
Content="初始化"
FontSize="20"
Style="{StaticResource ImageButtonStyle}" />


Loading…
Cancel
Save