/// <summary> /// 加载项目配置信息 /// </summary> /// <returns></returns> public static bool LoadSettings(string productName) { try { if (!System.IO.File.Exists(Global.ProductSettingPath)) { Log.GetInstance().ErrorWrite(string.Format("项目:'{0}'没有配置文件,路径:'{1}'", productName, Global.ProductSettingPath)); return(false); } //初始化时,添加轴信息 if (Global.ListAxis.Count == 0) { AxisInfo axisInfo = null; foreach (var kvp in Global.DictAxis) { axisInfo = new AxisInfo(); axisInfo.AxisName = kvp.Value; axisInfo.AxisNumber = (ushort)Convert.ToInt32(kvp.Key); axisInfo.Step = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "Step", Global.ProductSettingPath)); axisInfo.Lead = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "Lead", Global.ProductSettingPath)); axisInfo.MinVel = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "Speed", Global.ProductSettingPath)); axisInfo.MaxLimit = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "MaxLimitmm", Global.ProductSettingPath)); axisInfo.WorkPos1 = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "WorkPos1", Global.ProductSettingPath)); axisInfo.WorkPos2 = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "WorkPos2", Global.ProductSettingPath)); axisInfo.WorkPos3 = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "WorkPos3", Global.ProductSettingPath)); axisInfo.WorkPos4 = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "WorkPos4", Global.ProductSettingPath)); axisInfo.MaxVel = axisInfo.MinVel * 10; axisInfo.Dec = 10000; axisInfo.Acc = 10000; axisInfo.Vel = axisInfo.MaxVel; axisInfo.Outmode = 0; axisInfo.OrgLogic = 0; axisInfo.EzLogic = 0; axisInfo.EzMode = 1; axisInfo.HomeDir = 1; axisInfo.Vel = 0; axisInfo.HomeMode = 1; axisInfo.EZCount = 1; axisInfo.PosiMode = 0; Global.ListAxis.Add(axisInfo); } } //切换项目时,修改轴信息 else { foreach (var axisInfo in Global.ListAxis) { axisInfo.Step = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "Step", Global.ProductSettingPath)); axisInfo.Lead = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "Lead", Global.ProductSettingPath)); axisInfo.MinVel = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "Speed", Global.ProductSettingPath)); axisInfo.MaxLimit = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "MaxLimitmm", Global.ProductSettingPath)); axisInfo.WorkPos1 = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "WorkPos1", Global.ProductSettingPath)); axisInfo.WorkPos2 = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "WorkPos2", Global.ProductSettingPath)); axisInfo.WorkPos3 = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "WorkPos3", Global.ProductSettingPath)); axisInfo.WorkPos4 = Convert.ToInt32(IniFile.IniReadValue(axisInfo.AxisName, "WorkPos4", Global.ProductSettingPath)); axisInfo.MaxVel = axisInfo.MinVel * 10; axisInfo.Dec = 10000; axisInfo.Acc = 10000; axisInfo.Vel = axisInfo.MaxVel; axisInfo.Outmode = 0; axisInfo.OrgLogic = 0; axisInfo.EzLogic = 0; axisInfo.EzMode = 1; axisInfo.HomeDir = 1; axisInfo.Vel = 0; axisInfo.HomeMode = 1; axisInfo.EZCount = 1; axisInfo.PosiMode = 0; } } return(true); } catch (Exception ex) { Log.WriterExceptionLog(ex.ToString()); return(false); } }
/// <summary> /// 加载当前项目信息 /// </summary> private bool LoadProduct() { try { var productName = this.cbbProductName.SelectedItem.ToString(); if (MoveExecute.LoadSettings(productName)) { Log.GetInstance().NormalWrite("重新加载项目配置文件配置成功。"); } else { Log.GetInstance().ErrorWrite("重新加载项目配置文件配置失败。"); this.lastProductName = null; this.cbbProductName.SelectedIndex = -1; return(false); } var currentProductPath = Path.Combine(this.productPath, productName); var fileName = Global.IsExistFileBySuffixName(currentProductPath, ".bin"); if (fileName == "") { Log.GetInstance().ErrorWrite(string.Format("目录 '{0}' 下没有找到该项目的bin文件,切换项目失败。", currentProductPath)); this.lastProductName = null;; this.cbbProductName.SelectedIndex = -1; return(false); } /// ///设置Recipe /// var tasks = new List <Task>(); CmdResultCode cmdRes; bool f = false; foreach (var iixServer in Global.ListIIXSerevr) { if (iixServer.IsEnable == false) { continue; } tasks.Add(Task.Factory.StartNew(() => { cmdRes = IIXExecute.SetRecipe(iixServer, Path.Combine(currentProductPath, fileName)); if (cmdRes != CmdResultCode.Success) { f = false; } })); } Task.WaitAll(tasks.ToArray()); if (!f) { Log.GetInstance().ErrorWrite(string.Format("切换项目失败,原因:设置Recipe失败。")); this.lastProductName = null; this.cbbProductName.SelectedIndex = -1; return(false); } //修改配置文件中当前项目名 IniFile.IniWriteValue("Product", "ProductName", productName, Global.ConfigPath); this.lastProductName = productName; return(true); } catch (Exception ex) { Log.GetInstance().ErrorWrite("系统错误,请查询日志文件检查。"); Log.WriterExceptionLog(ex.ToString()); return(false); } }