终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PatrameterSettiongViewModel.cs 6.9 KiB

2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using BPASmartClient.Helper;
  2. using BPASmartClient.Message;
  3. using BPASmartClient.Model;
  4. using BPASmartClient.MorkTM;
  5. using Microsoft.Toolkit.Mvvm.ComponentModel;
  6. using Microsoft.Toolkit.Mvvm.Input;
  7. using Newtonsoft.Json;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace BPASmartClient.MilkWithTea.ViewModel
  16. {
  17. public class PatrameterSettiongViewModel: ObservableObject
  18. {
  19. /// <summary>
  20. /// 物料通道口列表
  21. /// </summary>
  22. public ObservableCollection<MaterialPosion> materialPosions { get; set; } = new ObservableCollection<MaterialPosion>();
  23. /// <summary>
  24. /// 转盘位置列表
  25. /// </summary>
  26. public ObservableCollection<OutMaterialPosion> TurntablePosion { get; set; } = new ObservableCollection<OutMaterialPosion>();
  27. /// <summary>
  28. /// 出料位置ID
  29. /// </summary>
  30. public int MaterialID { get { return _materialID; } set { _materialID = value; OnPropertyChanged(); } }
  31. private int _materialID = 0;
  32. /// <summary>
  33. /// 出料重量
  34. /// </summary>
  35. public float OutMaterailWeight { get { return _outMaterilWeight; } set { _outMaterilWeight = value; OnPropertyChanged(); } }
  36. private float _outMaterilWeight;
  37. /// <summary>
  38. /// 装盘ID
  39. /// </summary>
  40. public int TurntableID { get { return _turntableID; } set { _turntableID = value; OnPropertyChanged(); } }
  41. private int _turntableID = 0;
  42. /// <summary>
  43. /// 矫正的通道号
  44. /// </summary>
  45. public int CorrectPassway { get { return _CorrectPassway; } set { _CorrectPassway = value; OnPropertyChanged(); } }
  46. private int _CorrectPassway = 0;
  47. /// <summary>
  48. /// 通道是否开启
  49. /// </summary>
  50. public bool PasswayIsOpen { get { return _passwayIsOpen; } set { _passwayIsOpen = value; OnPropertyChanged(); } }
  51. private bool _passwayIsOpen ;
  52. /// <summary>
  53. /// 矫正重量
  54. /// </summary>
  55. public float CorrectMatetailWeight { get { return _CorrectMatetailWeight; } set { _CorrectMatetailWeight = value; OnPropertyChanged(); } }
  56. private float _CorrectMatetailWeight = 0;
  57. /// <summary>
  58. /// 矫正时间
  59. /// </summary>
  60. public int OutTime { get { return _0utTime; } set { _0utTime = value; OnPropertyChanged(); } }
  61. private int _0utTime = 0;
  62. public bool IsEnable { get { return !GLobal.makeEnable; } set { GLobal.makeEnable = !value; OnPropertyChanged(); } }
  63. /// <summary>
  64. /// 出料动作
  65. /// </summary>
  66. public RelayCommand OutMaterailCommad { get; set; }
  67. /// <summary>
  68. /// 转动转盘
  69. /// </summary>
  70. public RelayCommand TurntableCommad { get; set; }
  71. /// <summary>
  72. /// 开始矫正
  73. /// </summary>
  74. public RelayCommand CheckPasswayCommad { get; set; }
  75. /// <summary>
  76. /// 开启通道
  77. /// </summary>
  78. public RelayCommand OpenPasswayCommand { get; set; }
  79. /// <summary>
  80. /// 确认重量
  81. /// </summary>
  82. public RelayCommand CheckMaterailWeightCommand { get; set; }
  83. #region 设备配置
  84. /// <summary>
  85. /// 店铺名称
  86. /// </summary>
  87. public string ShopName { get { return _shopName; } set { _shopName = value; OnPropertyChanged(); } }
  88. private string _shopName;
  89. /// <summary>
  90. /// 店铺ID
  91. /// </summary>
  92. public string ShopID { get { return _shopID; } set { _shopID = value; OnPropertyChanged(); } }
  93. private string _shopID;
  94. /// <summary>
  95. /// 设备ID
  96. /// </summary>
  97. public string DeviceID { get { return _deviceID; } set { _deviceID = value; OnPropertyChanged(); } }
  98. private string _deviceID;
  99. /// <summary>
  100. /// PLC地址
  101. /// </summary>
  102. public string PLCAdress { get { return _pLCAdress; } set { _pLCAdress = value; OnPropertyChanged(); } }
  103. private string _pLCAdress;
  104. public RelayCommand SaveDevicesCommand { get; set; }
  105. #endregion
  106. public PatrameterSettiongViewModel()
  107. {
  108. OutMaterailCommad = new RelayCommand(new Action(() =>
  109. {
  110. ActionManage.GetInstance.Send("通道口出料", new object[] { MaterialID +1, OutMaterailWeight });
  111. }));
  112. TurntableCommad = new RelayCommand(new Action(() =>
  113. {
  114. ActionManage.GetInstance.Send("转盘转动", new object[] { TurntableID });
  115. }));
  116. OpenPasswayCommand = new RelayCommand(new Action(() =>
  117. {
  118. if(PasswayIsOpen) ActionManage.GetInstance.Send("开启通道", new object[] { CorrectPassway + 1 });
  119. }));
  120. CheckPasswayCommad = new RelayCommand(new Action(() =>
  121. {
  122. ActionManage.GetInstance.Send("开始矫正", new object[] { CorrectPassway + 1,OutTime });
  123. }));
  124. CheckMaterailWeightCommand = new RelayCommand(new Action(() =>
  125. {
  126. ActionManage.GetInstance.Send("矫正重量", new object[] { CorrectPassway + 1, CorrectMatetailWeight });
  127. }));
  128. SaveDevicesCommand = new RelayCommand(SaveDeviceMessage);
  129. init();
  130. }
  131. private void init()
  132. {
  133. foreach (MaterialPosion materialPosion in Enum.GetValues(typeof(MaterialPosion)))
  134. {
  135. materialPosions.Add(materialPosion);
  136. }
  137. foreach (OutMaterialPosion outMaterialPosion in Enum.GetValues(typeof(OutMaterialPosion)))
  138. {
  139. TurntablePosion.Add(outMaterialPosion);
  140. }
  141. ShopName = GLobal.deviceConfig.ElementAt(0).ShopName;
  142. ShopID = GLobal.deviceConfig.ElementAt(0).ShopId;
  143. DeviceID = GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).DeviceId;
  144. PLCAdress = GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).communicationPar.IPAddress;
  145. }
  146. private void SaveDeviceMessage()
  147. {
  148. if (GLobal.deviceConfig.Count > 0)
  149. {
  150. GLobal.deviceConfig.ElementAt(0).ShopName = ShopName;
  151. GLobal.deviceConfig.ElementAt(0).ShopId = ShopID;
  152. GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).DeviceId = DeviceID;
  153. GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).Id = Guid.NewGuid().ToString();
  154. GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).communicationPar.IPAddress = PLCAdress;
  155. File.WriteAllText($"{LocaPath.GetInstance().GetDeviceConfigPath}奶茶味魔方.json", JsonConvert.SerializeObject(GLobal.deviceConfig));
  156. }
  157. }
  158. }
  159. }