protected virtual void CheckAxisNo(CompInfoTemp c) { if (int.Parse(c.content[KeyWordDef.AN]) >= c.axisOccupied) { throw new Exception($"{c.rname}轴号{c.content[KeyWordDef.AN]}超限"); } }
//Scan macro and store string[] ScanMacro(string[] input) { string temp = string.Join("\r\n", input); Dictionary <string, string> tcontent = new Dictionary <string, string>() { { KeyWordDef.AT, "MACRO" }, }; Dictionary <string, List <string> > macroDict = RegFunctions.GetMacroDictAndRemove(temp, out string output); foreach (var kv in macroDict) { CompInfoTemp ct = new CompInfoTemp() { gname = "MACRO", rname = kv.Key, content = tcontent }; ct.contents = (from mkv in macroDict from value in kv.Value let key = "#ITEM#" select new { key, value }) .Select(dict => new Dictionary <string, string> { { dict.key, dict.value } }) .ToList(); gTopoList.Add(ct); } return(output.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)); }
protected virtual void FillContent(Dictionary <string, string> source, ref CompInfoTemp output) { foreach (var kv in source) { DictionaryFunctions.UpdatePair(kv, output.content); } }
protected override void WriteAuto(CompInfoTemp c, int autoBufferNo, ref string scripts) { bool LL, RL; LL = c.content.ContainsKey(KeyWordDef.LL); RL = c.content.ContainsKey(KeyWordDef.RL); if (LL || RL) { int index = CompManager.GetBufferIndex(autoBufferNo, scripts); int count = CompManager.GetBufferIndex(autoBufferNo, scripts); List <Dictionary <string, string> > autoDictList = new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "#AxisNo#", GetAxisNo(c).ToString() }, { "@RL", RL ? c.content[KeyWordDef.RL] : "#RL" }, { "@LL", LL ? c.content[KeyWordDef.LL] : "#LL" }, { "#RightLimit#", RL ? "" : "!" }, { "#LeftLimit#", LL ? "" : "!" }, } }; string repeatKeyWord = "LimitRepeat"; TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, autoDictList, index, count); } }
protected override List <Dictionary <string, string> > GenerateDictList(CompInfoTemp c, out int IIndex, out int OIndex) { List <Dictionary <string, string> > IODictList = new List <Dictionary <string, string> >(); IIndex = GetIOStartIndex(true, c); OIndex = GetIOStartIndex(false, c); int IOIncrement = 0; foreach (var dt in TopoDict) { int i = dt.First().Value; bool isIn = dt.First().Key; if (i % 8 != 0) { throw new Exception($"部件{c.rname}属性错误:IO数目必须是8的整数倍"); } for (int jj = 0; i > 0; i -= 8, jj++) { var l = GenerateSingleDictList(c, isIn, ref IOIncrement, ref IIndex, ref OIndex); IIndex -= isIn ? 1 : 0; OIndex -= !isIn ? 1 : 0; l.RemoveAt(1); l.First()["#NUM#"] = jj.ToString(); l.First()["#MappingName#"] = isIn ? "DI1" : "DO1"; IOIncrement = 0; IODictList.Add(l.First()); } } return(IODictList); }
protected override void WriteComp(CompInfoTemp c, int compBufferNo, List <int> homeBufferNo, ref string scripts) { foreach (var content in c.contents) { c.content = content; base.WriteComp(c, compBufferNo, homeBufferNo, ref scripts); } }
protected override void WriteAuto(CompInfoTemp c, int autoBufferNo, ref string scripts) { foreach (var content in c.contents) { c.content = content; WriteAutoSingle(c, autoBufferNo, ref scripts); } }
public virtual void FillContentFromDefLine(CompInfoTemp t, string defLine) { Dictionary <string, string> dt = RegFunctions.GetDefLineDict(defLine); foreach (var kv in dt) { DictionaryFunctions.AddOrUpdatePair(kv, t.content); } }
protected override void WriteHome(CompInfoTemp c, List <int> homeBufferNo, ref string scripts) { foreach (var content in c.contents) { c.content = content; CheckAxisNo(c); base.WriteHome(c, homeBufferNo, ref scripts); } }
protected virtual int GetHomeBufferNo(CompInfoTemp c, List <int> homeBufferNo) { int HG = int.Parse(c.content[KeyWordDef.HG]); if (!homeBufferNo.Contains(HG)) { throw new Exception("回零Buffer号不在定义范围内"); } return(HG); }
protected override int GetSO(Dictionary <string, string> d, CompInfoTemp output) { int so = base.GetSO(d, output); ParseTopo(output.content.ContainsKey(KeyWordDef.TOP) ? output.content[KeyWordDef.TOP] : d[KeyWordDef.TOP]); foreach (var dt in TopoDict) { so -= dt.First().Value; } return(so); }
public virtual void WriteScript(CompInfoTemp c, Dictionary <ST, List <int> > scriptNo, ref string scripts) { if (IsSkip(c)) { return; } WriteHome(c, scriptNo[ST.HOME], ref scripts); WriteComp(c, scriptNo[ST.COMP][0], scriptNo[ST.HOME], ref scripts); WriteLaser(c, scriptNo[ST.LASER][0], ref scripts); WriteAuto(c, scriptNo[ST.AUTO][0], ref scripts); WriteDBuffer(c, ref scripts); }
protected override void WriteComp(CompInfoTemp c, int compBufferNo, List <int> homeBufferNo, ref string scripts) { string CHM = c.content[KeyWordDef.HM]; if (!CHM.Contains("D")) { TextFunctions.AppendMultiRepeat( ref scripts, "SingleAxisHome", new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "#AxisNo#", GetAxisNo(c).ToString() }, { "#NAME#", GetAxisName(c, false) }, { "@HG", GetHomeBufferNo(c, homeBufferNo).ToString() }, } }, CompManager.GetBufferIndex(compBufferNo, scripts), CompManager.GetBufferCount(compBufferNo, scripts) ); } bool CN = int.Parse(c.content[KeyWordDef.CN]) > 0 ? true : false; if (!CN) { return; } int index = GetHomeIndex(c, homeBufferNo, scripts); int count = GetHomeCount(c, homeBufferNo, scripts); List <Dictionary <string, string> > compDictList = new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "#AxisNo#", GetAxisNo(c).ToString() }, { "#BCNo#", compBufferNo.ToString() }, { "@CS", c.content[KeyWordDef.CS] }, { "@CT", c.content[KeyWordDef.CT] }, { "@CND", c.content[KeyWordDef.CND] }, { "#NAME#", GetAxisName(c, false) }, { "@HG", GetHomeBufferNo(c, homeBufferNo).ToString() }, } }; string repeatKeyWord = "CompRepeat"; TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, compDictList, index, count); index = CompManager.GetBufferIndex(compBufferNo, scripts); count = CompManager.GetBufferCount(compBufferNo, scripts); TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, compDictList, index, count); index = CompManager.GetBufferIndex(ST.DEF, scripts); TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, compDictList, index); }
public virtual void FillAllAxisAndContent(ref int axisIndex, Dictionary <string, string> source, ref CompInfoTemp output) { FillContent(source, ref output); if (Type != ACSStr) { output.axisStart = axisIndex; output.axisOccupied = GetAO(source, output); axisIndex += output.axisOccupied; } }
protected virtual int GetIOStartIndex(bool isIn, CompInfoTemp c) { string s = c.content[isIn ? KeyWordDef.ISI : KeyWordDef.OSI]; if (s == "AUTO") { return(isIn ? inputIndexes.Max() + 1 : outputIndexes.Max() + 1); } else { return(int.Parse(s)); } }
string GenerateBase(Dictionary <ST, string> STContent, CompInfoTemp c) { scriptNo = new Dictionary <ST, List <int> >(); List <int> homeBuffer = c.content[KeyWordDef.BH].Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries) .Select(s => int.Parse(s)).ToList(); int compBuffer = int.Parse(c.content[KeyWordDef.BC]); int laserBuffer = int.Parse(c.content[KeyWordDef.BL]); int autoBuffer = int.Parse(c.content[KeyWordDef.BA]); string ss = ""; List <int> li = new List <int>(); foreach (int i in homeBuffer) { ss += ContraScript(i, STContent, ST.HOME); li.Add(i); } scriptNo.Add(ST.HOME, new List <int>(li)); ss += ContraScript(compBuffer, STContent, ST.COMP); scriptNo.Add(ST.COMP, new List <int>() { compBuffer }); li.Add(compBuffer); ss += ContraScript(laserBuffer, STContent, ST.LASER); scriptNo.Add(ST.LASER, new List <int>() { laserBuffer }); li.Add(laserBuffer); ss += ContraScript(autoBuffer, STContent, ST.AUTO); scriptNo.Add(ST.AUTO, new List <int>() { autoBuffer }); li.Add(autoBuffer); CheckBufferNo(li); ss += ContraScript(999, STContent, ST.DEF); scriptNo.Add(ST.DEF, new List <int>() { 999 }); return(ss); }
void FillTopoFromGeneralCompInfo(List <CompInfoTemp> topolist, string[] input) { for (int i = 0; i < topolist.Count; i++) { CompInfoTemp c = topolist[i]; if (!defaultDict.ContainsKey(c.gname)) { Dictionary <string, string> d = ScanFile(c.gname); if (!DictionaryFunctions.NotNullOrEmpty(d)) { throw new Exception($"未定义的部件{c.gname}"); } defaultDict.Add(c.gname, d); } } }
public virtual void FillSlaveAndACSAxis(ref int slaveIndex, ref int axisIndex, Dictionary <string, string> source, ref CompInfoTemp output) { int ao = GetAO(source, output); if (Type != ACSStr) { ao = 0; } output.axisStart = axisIndex; output.slaveStart = slaveIndex; output.axisOccupied = ao; output.slaveOccupied = GetSO(source, output); axisIndex += output.axisOccupied; slaveIndex += output.slaveOccupied; }
protected override void WriteLaser(CompInfoTemp c, int laserBufferNo, ref string scripts) { int index = CompManager.GetBufferIndex(laserBufferNo, scripts); int count = CompManager.GetBufferCount(laserBufferNo, scripts); List <Dictionary <string, string> > LCMDictList = new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "#AxisNo#", (c.axisStart + 3).ToString() }, } }; string repeatKeyWord = "LaserRepeat_LCM_" + c.content[KeyWordDef.LM]; TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, LCMDictList, index, count); }
protected override void WriteAuto(CompInfoTemp c, int autoBufferNo, ref string scripts) { int index = CompManager.GetBufferIndex(autoBufferNo, scripts); int count = CompManager.GetBufferIndex(autoBufferNo, scripts); List <Dictionary <string, string> > autoDictList; autoDictList = new List <Dictionary <string, string> >() { c.content.ToDictionary(k => '@' + k.Key, v => v.Value) }; autoDictList.First().Add("#AxisNo#", c.axisStart.ToString()); string repeatKeyWord = "CANRepeat"; TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, autoDictList, index, count); base.WriteAuto(c, autoBufferNo, ref scripts); }
protected virtual List <Dictionary <string, string> > GetOADictList(CompInfoTemp c, string OAKey) { try { var v = c.content[OAKey] .Split(',') .Select(s => new Dictionary <string, string>() { { "#Item#", s.Split(':')[0] }, { "#Value#", s.Split(':')[1] }, }) .ToList(); return(v); } catch (Exception e) { throw new Exception($"{c.rname}@{OAKey}:{c.content[OAKey]}表达式错误: {e.Message}"); } }
protected override void WriteAuto(CompInfoTemp c, int autoBufferNo, ref string scripts) { ParseTopo(c.content[KeyWordDef.TOP]); //Write IO Config string KeyWord = "IORepeat"; int startIndex = CompManager.GetBufferIndex(ST.AUTO, scripts); List <Dictionary <string, string> > IODictList = GenerateDictList(c, out int IIndex, out int OIndex); IODictList = IODictList.OrderByDescending(d => d["#IOType#"]).Select((d, i) => { if (i != 0) { d.Remove("#StartIndex#"); } return(d); }).ToList(); CheckIndexes(IODictList); TextFunctions.AppendMultiRepeat(ref scripts, KeyWord, IODictList, startIndex); Dictionary <string, string> OADict = new Dictionary <string, string> { { "OA1", "BeforeUnstopRepeat" }, { "OA2", "DuringEMGRepeat" }, { "OA3", "EscapeEMGRepeat" }, }; foreach (var kv in OADict) { if (c.content.ContainsKey(kv.Key)) { KeyWord = kv.Value; IODictList = GetOADictList(c, kv.Key); TextFunctions.AppendMultiRepeat(ref scripts, KeyWord, IODictList, startIndex); } } if (!c.content.ContainsKey("EMG")) { c.content.Add("EMG", "EMG"); } TextFunctions.ReplaceSingle(ref scripts, c.content, startIndex); TextFunctions.AppendMultiNoRepeat(ref scripts, c.content, startIndex); }
protected virtual List <Dictionary <string, string> > GenerateDictList(CompInfoTemp c, out int IIndex, out int OIndex) { List <Dictionary <string, string> > IODictList = new List <Dictionary <string, string> >(); IIndex = GetIOStartIndex(true, c); OIndex = GetIOStartIndex(false, c); int IOIncrement = 0; foreach (var dt in TopoDict) { int i = dt.First().Value; bool isIn = dt.First().Key; for (; i > 0; i--) { IODictList.AddRange(GenerateSingleDictList(c, isIn, ref IOIncrement, ref IIndex, ref OIndex)); } } return(IODictList); }
public string GenerateScript(Dictionary <ST, string> STContent, List <CompInfoTemp> topoList) { if (!CheckMainController(topoList[0])) { throw new Exception("第一个部件不是EC"); } string baseScripts = GenerateBase(STContent, topoList[0]); for (int i = 0; i < topoList.Count; i++) { CompInfoTemp c = topoList[i]; if (CheckMainController(c) && i > 0) { throw new Exception("存在多个EC"); } GetCompFromType(c.content[KeyWordDef.AT]).WriteScript(c, scriptNo, ref baseScripts); } return(baseScripts); }
protected override void FillContent(Dictionary <string, string> source, ref CompInfoTemp output) { string v; string name = output.rname; if (output.contents.Count == 0) { output.contents.Add(source); } output.contents = (from dict in output.contents let t = dict.TryGetValue(KeyWordDef.AN, out v) ? v : DictionaryFunctions.GetValueOrThrowException(name, source, KeyWordDef.AN) from n in t.Split(',').Select(i => int.Parse(i)) let ndict = new Dictionary <string, string>(dict) group ndict by n into gdict orderby gdict.Key let rdict = AggregateDicts(gdict).Concat(source) .GroupBy(d => d.Key) .ToDictionary(d => d.Key, d => d.First().Value) select rdict).ToList(); output.content = output.contents[0]; }
protected virtual string GetAxisName(CompInfoTemp c, bool check = true) { if (c.content.TryGetValue(KeyWordDef.NAME, out string name)) { if (!Regex.IsMatch(name, @"^\w+$") || Regex.IsMatch(name, @"^Axis\d+$")) { throw new Exception($"轴名称非法{name}"); } } else { name = $"Axis{GetAxisNo(c)}"; } if (nameList.Contains(name) && check) { throw new Exception($"轴名称重复{name}"); } nameList.Add(name); return(name); }
protected virtual void WriteAutoSingle(CompInfoTemp c, int autoBufferNo, ref string scripts) { bool MU = int.Parse(c.content[KeyWordDef.MU]) > 0 ? true : false; int index = CompManager.GetBufferIndex(autoBufferNo, scripts); int count = CompManager.GetBufferIndex(autoBufferNo, scripts); List <Dictionary <string, string> > autoDictList; if (MU) { autoDictList = new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "#AxisNo#", GetAxisNo(c).ToString() }, } }; string repeatKeyWord = "CommutRepeat"; TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, autoDictList, index, count); } base.WriteAuto(c, autoBufferNo, ref scripts); }
public virtual List <Dictionary <string, string> > GenerateSingleDictList(CompInfoTemp c, bool isIn, ref int IOIncrement, ref int IIndex, ref int OIndex) { string MapCommand = isIn ? "ECIN" : "ECOUT"; string IOType = isIn ? "1" : "0"; string MappingName = isIn ? "Input" : "Output"; string IOName = isIn ? c.content[KeyWordDef.INAME] : c.content[KeyWordDef.ONAME]; int _IONameIndex = isIn ? IIndex : OIndex; int _IOIncrement = IOIncrement; IIndex += isIn ? 2 : 0; OIndex += !isIn ? 2 : 0; IOIncrement++; return(new List <Dictionary <string, string> > { new Dictionary <string, string> { { "#StartIndex#", (c.slaveStart + 1).ToString() }, { "#MapCommand#", MapCommand }, { "#MappingName#", MappingName }, { "#Increment#", _IOIncrement.ToString() }, { "#IOType#", IOType }, { "#NUM#", "0" }, { "@IONAME", IOName }, { "#IOIndex#", _IONameIndex.ToString() }, }, new Dictionary <string, string> { { "#StartIndex#", (c.slaveStart + 1).ToString() }, { "#MapCommand#", MapCommand }, { "#MappingName#", MappingName }, { "#Increment#", _IOIncrement.ToString() }, { "#IOType#", IOType }, { "#NUM#", "1" }, { "@IONAME", IOName }, { "#IOIndex#", (++_IONameIndex).ToString() }, }, }); }
void FillTopoFromUserCompInfo(List <CompInfoTemp> topolist, string[] input) { input = (from cc in input let rt = Regex.Match(cc, RegFunctions.compCustomReg) where rt.Success let name = rt.Groups[1].Value let num = rt.Groups[2].Value.Split(',') from n in num select name + n + rt.Groups[4]).ToArray(); foreach (string s in input) { CompInfoTemp t = topolist.Find(c => c.rname == s.Split('@')[0]); if (t == null) { continue; } string type = defaultDict[t.gname][KeyWordDef.AT]; if (t != null) { CManager.FillContentFromDefLine(t, s, type); } } int slaveIndex = 0; int axisIndex = 0; for (int i = 0; i < topolist.Count; i++) { CompInfoTemp c = topolist[i]; CManager.FillSlaveAndACSAxis(ref slaveIndex, ref axisIndex, defaultDict[c.gname], ref c); } for (int i = 0; i < topolist.Count; i++) { CompInfoTemp c = topolist[i]; CManager.FillAllAxisAndContent(ref axisIndex, defaultDict[c.gname], ref c); } }
protected virtual int GetAxisNo(CompInfoTemp c) { return(c.axisStart); }