using BaseLibRWFile; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml.Linq; namespace HRT_Measure { public class AutoRun { public static Thread thLeft1 = new Thread(new ThreadStart(ThLeft1)); public static Thread thLeft2 = new Thread(new ThreadStart(ThLeft2)); public static Thread thRight1 = new Thread(new ThreadStart(ThRight1)); public static Thread thRight2 = new Thread(new ThreadStart(ThRight2)); public static Stopwatch sw = new Stopwatch(); //public static event Action eventDisplayBC; //public static ConcurrentQueue queuePrint2 = new ConcurrentQueue(); public static void ThreadStart() { if(!thLeft1.IsAlive) { thLeft1.IsBackground = true; thLeft1.Start(); } if (!thLeft2.IsAlive) { thLeft2.IsBackground = true; thLeft2.Start(); } if (!thRight1.IsAlive) { thRight1.IsBackground = true; thRight1.Start(); } if (!thRight2.IsAlive) { thRight2.IsBackground = true; thRight2.Start(); } } #region Th private static void ThLeft1() { while(true) { try { //if (GlobalPara.CurrentMachineState == MachineState.AutoRunning && ProgramHelp.Instance.commPLC.isPLCConnected) //{ // Left1Run(); //} } catch (Exception ex) { MessageBox.Show("Left1Run线程运行出错!" + ex.ToString()); } Thread.Sleep(2); } } private static void ThLeft2() { while (true) { try { //if (GlobalPara.CurrentMachineState == MachineState.AutoRunning && ProgramHelp.Instance.commPLC.isPLCConnected) //{ // Left2Run(); //} } catch (Exception ex) { MessageBox.Show("Left2Run线程运行出错!" + ex.ToString()); } Thread.Sleep(2); } } private static void ThRight1() { while (true) { try { //if (GlobalPara.CurrentMachineState == MachineState.AutoRunning && ProgramHelp.Instance.commPLC.isPLCConnected) //{ // Right1Run(); //} } catch (Exception ex) { MessageBox.Show("Right1Run线程运行出错!" + ex.ToString()); } Thread.Sleep(2); } } private static void ThRight2() { while (true) { try { //if (GlobalPara.CurrentMachineState == MachineState.AutoRunning && ProgramHelp.Instance.commPLC.isPLCConnected) //{ // Right2Run(); //} } catch (Exception ex) { MessageBox.Show("Right2Run线程运行出错!" + ex.ToString()); } Thread.Sleep(2); } } #endregion #region MyRegion private static void Left1Run() { //ProgramHelp.Instance.commPLC.ReadUshort(ProgramHelp.Instance.ProConfig.左一工位地址, out ushort result, out string strmsg); //if (result == 0) //{ // return; //} //ProgramHelp.Instance.SaveMsg("Left1Run", $"Left1Run---收到PLC- {ProgramHelp.Instance.ProConfig.左一工位地址} 数据 {result}-------------------------", true); } private static void Left2Run() { //ProgramHelp.Instance.commPLC.ReadUshort(ProgramHelp.Instance.ProConfig.左二工位地址, out ushort result, out string strmsg); //if (result == 0) //{ // return; //} //ProgramHelp.Instance.SaveMsg("Left2Run", $"Left2Run---收到PLC- {ProgramHelp.Instance.ProConfig.左二工位地址} 数据 {result}-------------------------", true); } private static void Right1Run() { //ProgramHelp.Instance.commPLC.ReadUshort(ProgramHelp.Instance.ProConfig.右一工位地址, out ushort result, out string strmsg); //if (result == 0) //{ // return; //} //ProgramHelp.Instance.SaveMsg("Right1Run", $"Right1Run---收到PLC- {ProgramHelp.Instance.ProConfig.右一工位地址} 数据 {result}-------------------------", true); } private static void Right2Run() { //ProgramHelp.Instance.commPLC.ReadUshort(ProgramHelp.Instance.ProConfig.右二工位地址, out ushort result, out string strmsg); //if (result == 0) //{ // return; //} //ProgramHelp.Instance.SaveMsg("Right2Run", $"Right2Run---收到PLC- {ProgramHelp.Instance.ProConfig.右二工位地址} 数据 {result}-------------------------", true); } #endregion } }