终端一体化运控平台
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.
 
 
 

206 lines
7.3 KiB

  1. using BPA.Helper;
  2. using BPASmartClient.Model;
  3. //using CommunityToolkit.Mvvm.Input;
  4. using Newtonsoft.Json;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace BPASmartClient.MilkWithTea.ViewModel
  13. {
  14. partial class PatrameterSettiongViewModel : NotifyBase
  15. {
  16. string FileName => GLobal.deviceConfig.Count > 0 ? GLobal.deviceConfig[0].ShopName : string.Empty;
  17. /// <summary>
  18. /// 物料通道口列表
  19. /// </summary>
  20. public ObservableCollection<int> materialPosions { get; set; } = new ObservableCollection<int>();
  21. public int MaterialID { get { return _materialID; } set { _materialID = value; OnPropertyChanged(); } }
  22. private int _materialID = 0;
  23. /// <summary>
  24. /// 出料重量
  25. /// </summary>
  26. public int OutMaterilWeight { get { return _outMaterilWeight; } set { _outMaterilWeight = value; OnPropertyChanged(); } }
  27. private int _outMaterilWeight = 0;
  28. /// <summary>
  29. /// 矫正的通道号
  30. /// </summary>
  31. public int CorrectPassway { get { return _CorrectPassway; } set { _CorrectPassway = value; OnPropertyChanged(); } }
  32. private int _CorrectPassway = 0;
  33. /// <summary>
  34. /// 通道是否开启
  35. /// </summary>
  36. public bool PasswayIsOpen { get { return _passwayIsOpen; } set { _passwayIsOpen = value; OnPropertyChanged(); } }
  37. private bool _passwayIsOpen;
  38. /// <summary>
  39. /// 矫正重量
  40. /// </summary>
  41. public int CorrectMatetailWeight { get { return _correctMatetailWeight; } set { _correctMatetailWeight = value; OnPropertyChanged(); } }
  42. private int _correctMatetailWeight;
  43. /// <summary>
  44. /// 矫正重量
  45. /// </summary>
  46. public int OutTime { get { return _outTime; } set { _outTime = value; OnPropertyChanged(); } }
  47. private int _outTime;
  48. public bool IsEnable { get { return !GLobal.makeEnable; } set { GLobal.makeEnable = !value; OnPropertyChanged(); } }
  49. /// <summary>
  50. /// 出料动作
  51. /// </summary>
  52. //[BPARelayCommand]
  53. private void OutMaterial()
  54. {
  55. ActionManage.GetInstance.Send("通道口出料", new object[] { MaterialID, OutMaterilWeight });
  56. }
  57. /// <summary>
  58. /// 开始矫正
  59. /// </summary>
  60. //[BPARelayCommand]
  61. private void CheckPassway()
  62. {
  63. }
  64. /// <summary>
  65. /// 开启通道
  66. /// </summary>
  67. //[BPARelayCommand]
  68. private void OpenPassway()
  69. {
  70. }
  71. /// <summary>
  72. /// 确认重量
  73. /// </summary>
  74. //[BPARelayCommand]
  75. private void CheckMaterailWeight()
  76. {
  77. }
  78. #region 设备配置
  79. /// <summary>
  80. /// 店铺名称
  81. /// </summary>
  82. public string ShopName { get { return _shopName; } set { _shopName = value; OnPropertyChanged(); } }
  83. private string _shopName;
  84. /// <summary>
  85. /// 店铺ID
  86. /// </summary>
  87. public string ShopID { get { return _shopID; } set { _shopID = value; OnPropertyChanged(); } }
  88. private string _shopID;
  89. /// <summary>
  90. /// 设备ID
  91. /// </summary>
  92. public string DeviceID { get { return _deviceID; } set { _deviceID = value; OnPropertyChanged(); } }
  93. private string _deviceID;
  94. /// <summary>
  95. /// PLC地址
  96. /// </summary>
  97. public string PLCAdress { get { return _pLCAdress; } set { _pLCAdress = value; OnPropertyChanged(); } }
  98. private string _pLCAdress;
  99. public bool IsPort { get { return _isPort; } set { _isPort = value; OnPropertyChanged(); } }
  100. private bool _isPort = true;
  101. public Visibility VsIP { get { return _vsIP; } set { _vsIP = value; OnPropertyChanged(); } }
  102. private Visibility _vsIP = Visibility.Hidden;
  103. public Visibility VsPort { get { return _vsPort; } set { _vsPort = value; OnPropertyChanged(); } }
  104. private Visibility _vsPort = Visibility.Visible;
  105. public string[] Ports { get { return _ports; } set { _ports = value; OnPropertyChanged(); } }
  106. private string[] _ports;
  107. public string Prot { get { return _prot; } set { _prot = value; OnPropertyChanged(); } }
  108. private string _prot;
  109. //[BPARelayCommand]
  110. private void SaveDevices()
  111. {
  112. SaveDeviceMessage();
  113. }
  114. //[BPARelayCommand]
  115. private void ChangeCommunation()
  116. {
  117. if (IsPort)
  118. {
  119. VsPort = Visibility.Visible;
  120. VsIP = Visibility.Hidden;
  121. }
  122. else
  123. {
  124. VsIP = Visibility.Visible;
  125. VsPort = Visibility.Hidden;
  126. }
  127. }
  128. #endregion
  129. public PatrameterSettiongViewModel()
  130. {
  131. Ports = System.IO.Ports.SerialPort.GetPortNames();
  132. init();
  133. }
  134. private void init()
  135. {
  136. for (int i = 1; i < 14; i++)
  137. {
  138. materialPosions.Add(i);
  139. }
  140. if (GLobal.deviceConfig.Count > 0)
  141. {
  142. ShopName = GLobal.deviceConfig.ElementAtOrDefault(0).ShopName;
  143. ShopID = GLobal.deviceConfig.ElementAtOrDefault(0).ShopId;
  144. DeviceID = GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAt(0).DeviceId;
  145. PLCAdress = GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).communicationPar.IPAddress;
  146. }
  147. }
  148. private void SaveDeviceMessage()
  149. {
  150. if (GLobal.deviceConfig.Count > 0)
  151. {
  152. GLobal.deviceConfig.ElementAtOrDefault(0).ShopName = ShopName;
  153. GLobal.deviceConfig.ElementAtOrDefault(0).ShopId = ShopID;
  154. GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).DeviceId = DeviceID;
  155. if (IsPort)
  156. {
  157. GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.IsSerialPort = true;
  158. GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.SerialPort = Prot;
  159. GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.BaudRate = 9600;
  160. }
  161. else
  162. {
  163. GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.IsSerialPort = false;
  164. GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.IsNetworkPort = true;
  165. GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.IPAddress = PLCAdress;
  166. }
  167. }
  168. File.WriteAllText($"{LocaPath.GetDeviceConfigPath}MOC.json", JsonConvert.SerializeObject(GLobal.deviceConfig));
  169. }
  170. }
  171. }