using BPA.Helper; using BPASmartClient.S7Net; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace BPASmartClient.DosingSystem.ViewModel { public class TempManageControlViewModel : NotifyBase { public TempManageControlViewModel() { } /// /// 正转 /// public bool Foreward { get { return _mForeward; } set { _mForeward = value; BeltDirection = 0; IsRun = _mForeward; OnPropertyChanged(); Task.Factory.StartNew(() => { if (Reversal || !_mForeward) { SiemensTest.GetInstance.sh.Write("M1000.1", true); Thread.Sleep(2000); SiemensTest.GetInstance.sh.Write("M1000.1", false); } if (_mForeward) { SiemensTest.GetInstance.sh.Write("M1000.0", true); Thread.Sleep(2000); SiemensTest.GetInstance.sh.Write("M1000.0", false); } }); } } private bool _mForeward; /// /// 反转 /// public bool Reversal { get { return _mReversal; } set { _mReversal = value; BeltDirection = 1; IsRun = _mReversal; OnPropertyChanged(); Task.Factory.StartNew(() => { if (Foreward || !_mReversal) { SiemensTest.GetInstance.sh.Write("M1000.1", true); Thread.Sleep(2000); SiemensTest.GetInstance.sh.Write("M1000.1", false); } if (_mReversal) { SiemensTest.GetInstance.sh.Write("M1000.3", true); Thread.Sleep(2000); SiemensTest.GetInstance.sh.Write("M1000.3", false); } }); } } private bool _mReversal; public bool IsRun { get { return _mIsRun; } set { _mIsRun = value; OnPropertyChanged(); } } private bool _mIsRun; public int BeltDirection { get { return _mBeltDirection; } set { _mBeltDirection = value; OnPropertyChanged(); } } private int _mBeltDirection; } public class SiemensTest { private volatile static SiemensTest _Instance; public static SiemensTest GetInstance => _Instance ?? (_Instance = new SiemensTest()); private SiemensTest() { } public SiemensHelper sh { get; set; } = new SiemensHelper(); public void Init() { Task.Run(() => { //sh.Connect(S7.Net.CpuType.S71500, "192.168.1.12"); sh.Connect(S7.Net.CpuType.S71200, "192.168.0.15"); if (sh.IsConnected) MessageLog.GetInstance.Show("西门子PLC连接成功"); else MessageLog.GetInstance.Show("西门子PLC连接失败"); }); //sh.Connect(S7.Net.CpuType.S71500, "192.168.1.12"); //sh.Connect(S7.Net.CpuType.S71200, "192.168.0.15"); } } }