RobotManager.cs 2.8 KB
using URSoldering.Common;
using URSoldering.LoadCSVLibrary;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace URSoldering.DeviceLibrary
{
    public class RobotManager
    {
        public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        private static bool isInit = false;
        public RobotManager()
        {
        }
        public static URSolderingRobot SolderingRobot = null;
        public static RobotConfig robotConfig = null;
        public static RobotConfig InitRobotConfig()
        {
            try
            {
                if (!isInit)
                { 
                    isInit = true;
                    string appPath = Application.StartupPath;
                    string robotType = ConfigAppSettings.GetValue(Setting_Init.Robot_Type);
                    LogUtil.info(LOGGER, "  类型=" + robotType + ",开始加载机器人");
                    string CID = ConfigAppSettings.GetValue(Setting_Init.Robot_CID);
                    string linefilePath = appPath + ConfigAppSettings.GetValue(Setting_Init.Robot_ConfigPath);

                    robotConfig = CSVConfigReader.LoadConfig(1, CID, robotType, linefilePath);
                    if (robotType.Equals(RobotType.SolderingRobot))
                    {
                        SolderingRobot = new URSolderingRobot((SolderingRobotConfig)robotConfig);
                       
                    }

                    LogUtil.info(LOGGER, "加载配置完成!");
                    return robotConfig;
                } 
            }
            catch (Exception ex)
            {
                LOGGER.Error("出错:", ex);
                MessageBox.Show(ex.ToString(), "加载配置错误(请检查配置)");
                Application.Exit();
            } return null;
        }
        /// <summary>
        /// 修改了料仓配置,更新缓存,更新配置文件(只能更新PRO的配置)
        /// </summary>
        /// <param name="kTK_LA_Store_Config"></param>
        public static void UpdateConfig(RobotConfig config)
        {
            try
            {
                //位置配置到文件中
                string appPath = Application.StartupPath;
                string configFile = appPath + ConfigAppSettings.GetValue(Setting_Init.Robot_ConfigPath);
                bool result = CSVConfigReader.SaveConfig(configFile, config);
                if (!result)
                {
                    LOGGER.Error("保存配置文件失败:" + configFile);
                }
            }
            catch (Exception ex)
            {
                LOGGER.Error("出错:", ex);
            }
        }       
    }

}