终端一体化运控平台
Não pode escolher mais do que 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.
 
 
 

114 linhas
3.6 KiB

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