|
- using BPASmartClient.Academy._50L;
- using BPASmartClient.Academy.Model;
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.Academy.ViewModel
- {
- public class ReactionKettle50LViewModel : NotifyBase
- {
- private volatile static ReactionKettle50LViewModel _Instance;
- public static ReactionKettle50LViewModel GetInstance => _Instance ?? (_Instance = new ReactionKettle50LViewModel());
- private ReactionKettle50LViewModel()
- {
- Start = new BPARelayCommand(() =>
- {
- if (!string.IsNullOrEmpty(Name) && PlcControl.GetInstance.IsConnect)
- {
- switch (Content)
- {
- case "系统启动":
- var result = PlcControl.GetInstance.Write(BoolAddEnum.系统启动, true);
- if (result!= null && result.IsSuccess)
- {
- IsChecked = true;
- DataFeedBack_50 dataFeedback = new();
- dataFeedback.Name = Name;
- var snd = new SaveNameData(Name);
- dataFeedback.ProductNumberId = snd.Id;
- SqliteOperate.GetInstance.Add(snd);
- PlcControl.GetInstance.id = snd.Id;
- SqliteOperate.GetInstance.DataFeedBacks = dataFeedback;
- Content = "系统停止";
- }
- else
- {
- LogHelper.GetInstance.AddRun(result.Message);
- }
- break;
- case "系统停止":
- IsChecked = false;
- PlcControl.GetInstance.id = "";
- PlcControl.GetInstance.Write(BoolAddEnum.系统启动, false);
- Content = "系统启动";
- break;
- default:
- break;
- }
- }
- else
- {
- if (!PlcControl.GetInstance.IsConnect)
- {
- MessageNotify.GetInstance.ShowDialog("设备未连接成功,请稍后重试", DialogType.Information);
- }
- else
- {
- MessageNotify.GetInstance.ShowDialog("请输入名称后,再开始测试!!", DialogType.Information);
- }
- IsChecked = false;
- }
- });
-
- DataRecordCommand = new BPARelayCommand(() =>
- {
- ParameterSetView sv = new ParameterSetView();
- sv.Show();
- });
- Task.Factory.StartNew(async () =>
- {
- while (true)
- {
- this.PLCIsConnected = PlcControl.GetInstance.IsConnect;
- await Task.Delay(500);
- }
- });
- }
-
-
- public DeviceStatus DeviceStatus{get { return _mdeviceStatus; }set { _mdeviceStatus = value;OnPropertyChanged(); }}
- private DeviceStatus _mdeviceStatus = PlcControl.GetInstance.DeviceStatus;
-
- private string _name = "";
-
- public string Name
- {
- get { return _name; }
- set { _name = value; OnPropertyChanged(); }
- }
- private string _content = "系统启动";
-
- public string Content
- {
- get { return _content; }
- set { _content = value; OnPropertyChanged(); }
- }
-
- private bool _isChecked = false;
-
- public bool IsChecked
- {
- get { return _isChecked; }
- set { _isChecked = value; OnPropertyChanged(); }
- }
-
- private bool _plcIsConnected;
- public bool PLCIsConnected { get { return _plcIsConnected; } set { _plcIsConnected = value; OnPropertyChanged(); } }
-
- public BPARelayCommand Start { get; set; }
- public BPARelayCommand DataRecordCommand { get; set; }
- }
- }
|