终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

118 wiersze
3.6 KiB

  1. using BPA.Communication;
  2. using BPA.Helper;
  3. //using BPASmartClient.S7Net;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace BPASmartClient.DosingSystem.ViewModel
  11. {
  12. public class TempManageControlViewModel : NotifyBase
  13. {
  14. public TempManageControlViewModel()
  15. {
  16. }
  17. /// <summary>
  18. /// 正转
  19. /// </summary>
  20. public bool Foreward
  21. {
  22. get { return _mForeward; }
  23. set
  24. {
  25. _mForeward = value;
  26. BeltDirection = 0;
  27. IsRun = _mForeward;
  28. OnPropertyChanged();
  29. Task.Factory.StartNew(() =>
  30. {
  31. if (Reversal || !_mForeward)
  32. {
  33. SiemensTest.GetInstance.sh.Write("M1000.1", true);
  34. Thread.Sleep(2000);
  35. SiemensTest.GetInstance.sh.Write("M1000.1", false);
  36. }
  37. if (_mForeward)
  38. {
  39. SiemensTest.GetInstance.sh.Write("M1000.0", true);
  40. Thread.Sleep(2000);
  41. SiemensTest.GetInstance.sh.Write("M1000.0", false);
  42. }
  43. });
  44. }
  45. }
  46. private bool _mForeward;
  47. /// <summary>
  48. /// 反转
  49. /// </summary>
  50. public bool Reversal
  51. {
  52. get { return _mReversal; }
  53. set
  54. {
  55. _mReversal = value;
  56. BeltDirection = 1;
  57. IsRun = _mReversal;
  58. OnPropertyChanged();
  59. Task.Factory.StartNew(() =>
  60. {
  61. if (Foreward || !_mReversal)
  62. {
  63. SiemensTest.GetInstance.sh.Write("M1000.1", true);
  64. Thread.Sleep(2000);
  65. SiemensTest.GetInstance.sh.Write("M1000.1", false);
  66. }
  67. if (_mReversal)
  68. {
  69. SiemensTest.GetInstance.sh.Write("M1000.3", true);
  70. Thread.Sleep(2000);
  71. SiemensTest.GetInstance.sh.Write("M1000.3", false);
  72. }
  73. });
  74. }
  75. }
  76. private bool _mReversal;
  77. public bool IsRun { get { return _mIsRun; } set { _mIsRun = value; OnPropertyChanged(); } }
  78. private bool _mIsRun;
  79. public int BeltDirection { get { return _mBeltDirection; } set { _mBeltDirection = value; OnPropertyChanged(); } }
  80. private int _mBeltDirection;
  81. }
  82. public class SiemensTest
  83. {
  84. private volatile static SiemensTest _Instance;
  85. public static SiemensTest GetInstance => _Instance ?? (_Instance = new SiemensTest());
  86. private SiemensTest() { }
  87. public Siemens sh { get; set; } = new Siemens();
  88. public void Init()
  89. {
  90. Task.Run(() =>
  91. {
  92. //sh.Connect(S7.Net.CpuType.S71500, "192.168.1.12");
  93. //S7.Net.CpuType.S71200, "192.168.0.15"
  94. sh.Connect(new BPA.Communication.Base.ConfigurationOptions() { cpuType = CpuType.S71200, IpAddress = "192.168.0.15" });
  95. if (sh.IsConnected())
  96. MessageLog.GetInstance.Show("西门子PLC连接成功");
  97. else
  98. MessageLog.GetInstance.Show("西门子PLC连接失败");
  99. });
  100. //sh.Connect(S7.Net.CpuType.S71500, "192.168.1.12");
  101. //sh.Connect(S7.Net.CpuType.S71200, "192.168.0.15");
  102. }
  103. }
  104. }