终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

198 Zeilen
6.2 KiB

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