终端一体化运控平台
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

116 linhas
3.5 KiB

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