终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

93 lines
3.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using System.Collections.Concurrent;
  8. using System.Collections.ObjectModel;
  9. using System.Windows;
  10. using BPASmartClient.Helper;
  11. using Microsoft.Toolkit.Mvvm.Input;
  12. using BPASmartClient.DosingSystem.Model;
  13. using System.Threading;
  14. using BPASmartClient.CustomResource.Pages.Model;
  15. namespace BPASmartClient.DosingSystem.ViewModel
  16. {
  17. public class RecipeControlViewModel : ObservableObject
  18. {
  19. ConcurrentQueue<string> devices = new ConcurrentQueue<string>();
  20. public RecipeControlViewModel()
  21. {
  22. Recipes = Json<LocaPar>.Data.Recipes;
  23. StartCommand = new RelayCommand<object>((o) =>
  24. {
  25. //if (o != null && o is string deviceName)
  26. //{
  27. // int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == deviceName);
  28. // if (index >= 0 && index < Recipes.Count)
  29. // {
  30. // Recipes.ElementAt(index).IsEnable = false;
  31. // }
  32. // MessageLog.GetInstance.ShowUserLog($"下发工单 { Recipes.ElementAt(index).RecipeName}");
  33. // devices.Enqueue(deviceName);
  34. //}
  35. MessageLog.GetInstance.ShowUserLog($"下发工单 { Guid.NewGuid().ToString()}");
  36. });
  37. ThreadManage.GetInstance().StartLong(new Action(() =>
  38. {
  39. if (devices.Count > 0)
  40. {
  41. int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == devices.ElementAt(0));
  42. if (index >= 0 && index < Recipes.Count)
  43. {
  44. Recipes.ElementAt(index).Are.Reset();
  45. Recipes.ElementAt(index).IsEnable = false;
  46. foreach (var item in Recipes.ElementAt(index).RawMaterials)
  47. {
  48. DeviceInquire.GetInstance.GetDevice(item.DeviceIp)?.Start(item.RawMaterialWeight);//启动写入
  49. }
  50. Recipes.ElementAt(index).Are.WaitOne();
  51. devices.TryDequeue(out string deviceName);
  52. }
  53. }
  54. Thread.Sleep(100);
  55. }), "启动配发下发");
  56. ThreadManage.GetInstance().StartLong(new Action(() =>
  57. {
  58. for (int i = 0; i < Recipes.Count; i++)
  59. {
  60. for (int m = 0; m < Recipes.ElementAt(i).RawMaterials.Count; m++)
  61. {
  62. var RunStatus = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).deviceStatus.RunStatus;
  63. Recipes.ElementAt(i).RawMaterials.ElementAt(m).RecipeStatus = RunStatus;
  64. var res = Recipes.ElementAt(i).RawMaterials.Where(p => p.RecipeStatus == 3).ToList();
  65. if (res != null && res.Count == Recipes.ElementAt(i).RawMaterials.Count)
  66. {
  67. for (int r = 0; r < Recipes.ElementAt(i).RawMaterials.Count; r++)
  68. {
  69. DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(r).DeviceIp).StatusReset();
  70. }
  71. Recipes.ElementAt(i).IsEnable = true;
  72. Recipes.ElementAt(i).Are.Set();
  73. }
  74. }
  75. }
  76. Thread.Sleep(100);
  77. }), "RecipeControlViewModelStatusInquire");
  78. }
  79. public RelayCommand<object> StartCommand { get; set; }
  80. public ObservableCollection<RecipeModel> Recipes { get; set; }
  81. }
  82. }