AutoRun.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using BaseLibRWFile;
  2. using System;
  3. using System.Collections.Concurrent;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using System.Xml.Linq;
  12. namespace HRT_Measure
  13. {
  14. public class AutoRun
  15. {
  16. public static Thread thLeft1 = new Thread(new ThreadStart(ThLeft1));
  17. public static Thread thLeft2 = new Thread(new ThreadStart(ThLeft2));
  18. public static Thread thRight1 = new Thread(new ThreadStart(ThRight1));
  19. public static Thread thRight2 = new Thread(new ThreadStart(ThRight2));
  20. public static Stopwatch sw = new Stopwatch();
  21. //public static event Action<string,string> eventDisplayBC;
  22. //public static ConcurrentQueue<string> queuePrint2 = new ConcurrentQueue<string>();
  23. public static void ThreadStart()
  24. {
  25. if(!thLeft1.IsAlive)
  26. {
  27. thLeft1.IsBackground = true;
  28. thLeft1.Start();
  29. }
  30. if (!thLeft2.IsAlive)
  31. {
  32. thLeft2.IsBackground = true;
  33. thLeft2.Start();
  34. }
  35. if (!thRight1.IsAlive)
  36. {
  37. thRight1.IsBackground = true;
  38. thRight1.Start();
  39. }
  40. if (!thRight2.IsAlive)
  41. {
  42. thRight2.IsBackground = true;
  43. thRight2.Start();
  44. }
  45. }
  46. #region Th
  47. private static void ThLeft1()
  48. {
  49. while(true)
  50. {
  51. try
  52. {
  53. //if (GlobalPara.CurrentMachineState == MachineState.AutoRunning && ProgramHelp.Instance.commPLC.isPLCConnected)
  54. //{
  55. // Left1Run();
  56. //}
  57. }
  58. catch (Exception ex)
  59. {
  60. MessageBox.Show("Left1Run线程运行出错!" + ex.ToString());
  61. }
  62. Thread.Sleep(2);
  63. }
  64. }
  65. private static void ThLeft2()
  66. {
  67. while (true)
  68. {
  69. try
  70. {
  71. //if (GlobalPara.CurrentMachineState == MachineState.AutoRunning && ProgramHelp.Instance.commPLC.isPLCConnected)
  72. //{
  73. // Left2Run();
  74. //}
  75. }
  76. catch (Exception ex)
  77. {
  78. MessageBox.Show("Left2Run线程运行出错!" + ex.ToString());
  79. }
  80. Thread.Sleep(2);
  81. }
  82. }
  83. private static void ThRight1()
  84. {
  85. while (true)
  86. {
  87. try
  88. {
  89. //if (GlobalPara.CurrentMachineState == MachineState.AutoRunning && ProgramHelp.Instance.commPLC.isPLCConnected)
  90. //{
  91. // Right1Run();
  92. //}
  93. }
  94. catch (Exception ex)
  95. {
  96. MessageBox.Show("Right1Run线程运行出错!" + ex.ToString());
  97. }
  98. Thread.Sleep(2);
  99. }
  100. }
  101. private static void ThRight2()
  102. {
  103. while (true)
  104. {
  105. try
  106. {
  107. //if (GlobalPara.CurrentMachineState == MachineState.AutoRunning && ProgramHelp.Instance.commPLC.isPLCConnected)
  108. //{
  109. // Right2Run();
  110. //}
  111. }
  112. catch (Exception ex)
  113. {
  114. MessageBox.Show("Right2Run线程运行出错!" + ex.ToString());
  115. }
  116. Thread.Sleep(2);
  117. }
  118. }
  119. #endregion
  120. #region MyRegion
  121. private static void Left1Run()
  122. {
  123. //ProgramHelp.Instance.commPLC.ReadUshort(ProgramHelp.Instance.ProConfig.左一工位地址, out ushort result, out string strmsg);
  124. //if (result == 0)
  125. //{
  126. // return;
  127. //}
  128. //ProgramHelp.Instance.SaveMsg("Left1Run", $"Left1Run---收到PLC- {ProgramHelp.Instance.ProConfig.左一工位地址} 数据 {result}-------------------------", true);
  129. }
  130. private static void Left2Run()
  131. {
  132. //ProgramHelp.Instance.commPLC.ReadUshort(ProgramHelp.Instance.ProConfig.左二工位地址, out ushort result, out string strmsg);
  133. //if (result == 0)
  134. //{
  135. // return;
  136. //}
  137. //ProgramHelp.Instance.SaveMsg("Left2Run", $"Left2Run---收到PLC- {ProgramHelp.Instance.ProConfig.左二工位地址} 数据 {result}-------------------------", true);
  138. }
  139. private static void Right1Run()
  140. {
  141. //ProgramHelp.Instance.commPLC.ReadUshort(ProgramHelp.Instance.ProConfig.右一工位地址, out ushort result, out string strmsg);
  142. //if (result == 0)
  143. //{
  144. // return;
  145. //}
  146. //ProgramHelp.Instance.SaveMsg("Right1Run", $"Right1Run---收到PLC- {ProgramHelp.Instance.ProConfig.右一工位地址} 数据 {result}-------------------------", true);
  147. }
  148. private static void Right2Run()
  149. {
  150. //ProgramHelp.Instance.commPLC.ReadUshort(ProgramHelp.Instance.ProConfig.右二工位地址, out ushort result, out string strmsg);
  151. //if (result == 0)
  152. //{
  153. // return;
  154. //}
  155. //ProgramHelp.Instance.SaveMsg("Right2Run", $"Right2Run---收到PLC- {ProgramHelp.Instance.ProConfig.右二工位地址} 数据 {result}-------------------------", true);
  156. }
  157. #endregion
  158. }
  159. }