LineManager.cs 3.8 KB
using log4net;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Text; 
using System.Windows.Forms;

namespace OnlineStore.DeviceLibrary
{
    public class LineManager
    {

        //public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public static DoubleLineBean Line = null;
        public static DoubleLineConfig Config = null;
        public static   PackageLine packageLine=null ;
        private static bool isInit = false;

        public static bool UseBuzzer = true;

        public LineManager()
        {
        }

        public static void CheckEnum(Type type)
        {
            if (type.IsEnum)
            {
                List<int> valueList = new List<int>();
                foreach (int item in Enum.GetValues(type))
                {
                    if (valueList.Contains(item))
                    {
                        LogUtil.error( type.Name + "枚举值:" + item + "重复存在,请检查代码!");
                        Application.Exit();
                        break;
                    }
                    valueList.Add(item);
                }
            }
        }
        public static DoubleLineBean InitStore()
        {
            try
            {
                RobotConfig.ProIOIpMap = new Dictionary<string, string>();
                if (!isInit)
                {
                  
                    CheckEnum(typeof(MoveStep));
                    CheckEnum(typeof(RunStatus));

                    isInit = true;

                    string appPath = Application.StartupPath;
                    string linefilePath = appPath + ConfigAppSettings.GetValue(Setting_Init.Line_Config);
                    LogUtil.info( " 开始加载双层流水线配置:" + linefilePath);
                    RobotConfig storeConfig = CSVConfigReader.LoadConfig(linefilePath);


                    Config = (DoubleLineConfig)storeConfig;
                    Line = new DoubleLineBean(Config);
                    packageLine = new PackageLine(LineManager.Config);
                    LogUtil.info( "加载双层流水线完成!");
                    return Line;
                }

            }
            catch (Exception ex)
            {
                LogUtil.error("出错:", ex);
                MessageBox.Show(ex.ToString(), "加载配置错误(请检查配置)");
                Application.Exit();
            }
            return Line;
        } 
   
        public static bool checkWatch(Stopwatch watch, int targetMs, bool isStop = true)
        {
            if (!watch.IsRunning)
            {
                watch.Restart();
                return false;
            }
            else if (watch.ElapsedMilliseconds >= targetMs)
            {
                if (isStop)
                {
                    watch.Stop();
                }
                return true;
            }
            return false;
        }
        public static string GetRunStr(RunStatus runs)
        {
            string sta = "运行中";
            switch (runs)
            {
                case RunStatus.Busy:
                    sta = "忙碌";
                    break;
                case RunStatus.HomeMoving:
                    sta = "原点返回";
                    break;
                case RunStatus.Reset:
                    sta = "重置";
                    break;
                case RunStatus.Runing:
                    sta = "运行中";
                    break;
                case RunStatus.Wait:
                    sta = "等待启动";
                    break;
            }
            return sta;
        }
       
    }
}