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

ReactionKettle50LViewModel.cs 4.3 KiB

2 月之前
2 月之前
2 月之前
2 月之前
2 月之前
2 月之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. }