RobotManager.cs
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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);
}
//else if (robotType.Equals(RobotType.RivetingRobot))
//{
// RivetingRobot = new RivetingRobotBean((RivetingRobotConfig)robotConfig);
//}
//else if (robotType.Equals(RobotType.ScrewRobot))
//{
// ScrewRobot = new ScrewRobotBean((ScrewRobotConfig)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);
}
}
}
}