终端一体化运控平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

116 rindas
4.3 KiB

  1. using BPASmartClient.Academy._50L;
  2. using BPASmartClient.Academy.Model;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace BPASmartClient.Academy.ViewModel
  9. {
  10. public class ReactionKettle50LViewModel : NotifyBase
  11. {
  12. private volatile static ReactionKettle50LViewModel _Instance;
  13. public static ReactionKettle50LViewModel GetInstance => _Instance ?? (_Instance = new ReactionKettle50LViewModel());
  14. private ReactionKettle50LViewModel()
  15. {
  16. Start = new BPARelayCommand(() =>
  17. {
  18. if (!string.IsNullOrEmpty(Name) && PlcControl.GetInstance.IsConnect)
  19. {
  20. switch (Content)
  21. {
  22. case "系统启动":
  23. var result = PlcControl.GetInstance.Write(BoolAddEnum.系统启动, true);
  24. if (result!= null && result.IsSuccess)
  25. {
  26. IsChecked = true;
  27. DataFeedBack_50 dataFeedback = new();
  28. dataFeedback.Name = Name;
  29. var snd = new SaveNameData(Name);
  30. dataFeedback.ProductNumberId = snd.Id;
  31. SqliteOperate.GetInstance.Add(snd);
  32. PlcControl.GetInstance.id = snd.Id;
  33. SqliteOperate.GetInstance.DataFeedBacks = dataFeedback;
  34. Content = "系统停止";
  35. }
  36. else
  37. {
  38. LogHelper.GetInstance.AddRun(result.Message);
  39. }
  40. break;
  41. case "系统停止":
  42. IsChecked = false;
  43. PlcControl.GetInstance.id = "";
  44. PlcControl.GetInstance.Write(BoolAddEnum.系统启动, false);
  45. Content = "系统启动";
  46. break;
  47. default:
  48. break;
  49. }
  50. }
  51. else
  52. {
  53. if (!PlcControl.GetInstance.IsConnect)
  54. {
  55. MessageNotify.GetInstance.ShowDialog("设备未连接成功,请稍后重试", DialogType.Information);
  56. }
  57. else
  58. {
  59. MessageNotify.GetInstance.ShowDialog("请输入名称后,再开始测试!!", DialogType.Information);
  60. }
  61. IsChecked = false;
  62. }
  63. });
  64. DataRecordCommand = new BPARelayCommand(() =>
  65. {
  66. ParameterSetView sv = new ParameterSetView();
  67. sv.Show();
  68. });
  69. Task.Factory.StartNew(async () =>
  70. {
  71. while (true)
  72. {
  73. this.PLCIsConnected = PlcControl.GetInstance.IsConnect;
  74. await Task.Delay(500);
  75. }
  76. });
  77. }
  78. public DeviceStatus DeviceStatus{get { return _mdeviceStatus; }set { _mdeviceStatus = value;OnPropertyChanged(); }}
  79. private DeviceStatus _mdeviceStatus = PlcControl.GetInstance.DeviceStatus;
  80. private string _name = "";
  81. public string Name
  82. {
  83. get { return _name; }
  84. set { _name = value; OnPropertyChanged(); }
  85. }
  86. private string _content = "系统启动";
  87. public string Content
  88. {
  89. get { return _content; }
  90. set { _content = value; OnPropertyChanged(); }
  91. }
  92. private bool _isChecked = false;
  93. public bool IsChecked
  94. {
  95. get { return _isChecked; }
  96. set { _isChecked = value; OnPropertyChanged(); }
  97. }
  98. private bool _plcIsConnected;
  99. public bool PLCIsConnected { get { return _plcIsConnected; } set { _plcIsConnected = value; OnPropertyChanged(); } }
  100. public BPARelayCommand Start { get; set; }
  101. public BPARelayCommand DataRecordCommand { get; set; }
  102. }
  103. }