123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- 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<string,string> eventDisplayBC;
- //public static ConcurrentQueue<string> queuePrint2 = new ConcurrentQueue<string>();
- 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
- }
- }
|