private void SegLBS() { string str1 = textBox9.Text; //ok string str2 = textBox10.Text; //seg string str3 = textBox8.Text; //req TxPlcLogicBehavior LB = CreatNewLB("RobSeg"); Dictionary <string, ITxPlcLogicBehaviorEntry> LBEnDic = new Dictionary <string, ITxPlcLogicBehaviorEntry>(); Dictionary <string, ITxPlcLogicBehaviorParameter> LBPaDic = new Dictionary <string, ITxPlcLogicBehaviorParameter>(); Dictionary <string, TxPlcExpressionBuilder> ExbuDic = new Dictionary <string, TxPlcExpressionBuilder>(); Dictionary <string, TxPlcExpressionBuilder> ExbuDic1 = new Dictionary <string, TxPlcExpressionBuilder>(); //try //{ for (int i = 0; i < Robots.Length; i++) { TxRobot r1 = Robots[i]; ITxPlcLogicBehaviorEntry en1 = SegEn(LB, FindSig(r1.Signals, str2, true)); ITxPlcLogicBehaviorEntry en2 = SegEn(LB, FindSig(r1.Signals, str3, true)); LBEnDic.Add(r1.Name + str2, en1); LBEnDic.Add(r1.Name + str3, en2); } for (int i = 0; i < dataGridView2.Rows.Count; i++) { if (dataGridView2.Rows[i].Cells[0].Value != null && dataGridView2.Rows[i].Cells[1].Value != null && dataGridView2.Rows[i].Cells[0].Value != "" && dataGridView2.Rows[i].Cells[1].Value != "") { string rob1name = dataGridView2.Rows[i].Cells[0].Value.ToString(); string strseg1 = dataGridView2.Rows[i].Cells[1].Value.ToString(); string rob1segok = rob1name + str1; string rob1seg = rob1name + str2; string rob1segreq = rob1name + str3; TxRobot r1 = RobDictionary[rob1name]; if (!ExbuDic1.ContainsKey(rob1segok)) { ExbuDic1.Add(rob1segok, new TxPlcExpressionBuilder()); ExbuDic1[rob1segok].Add(LBEnDic[rob1segreq]); ExbuDic1[rob1segok].Add(TxPlcExpressionOperator.And); ExbuDic1[rob1segok].Add(TxPlcExpressionOperator.LeftParenthesis); } //SegPa(LB,rob1name+"_seg_"+c,); string Parob1seg = ""; int c = 0; if (int.TryParse(strseg1, out c)) { Parob1seg = rob1name + "_seg_" + strseg1; if (!ExbuDic.ContainsKey(Parob1seg)) { ExbuDic.Add(Parob1seg, new TxPlcExpressionBuilder()); TxPlcValue pv = new TxPlcValue(); pv.ByteValue = (ushort)c; ExbuDic[Parob1seg].Add(TxPlcExpressionOperator.LeftParenthesis); ExbuDic[Parob1seg].Add(LBEnDic[rob1seg]); ExbuDic[Parob1seg].Add(TxPlcExpressionOperator.IsEqualTo); ExbuDic[Parob1seg].Add(TxPlcSignalDataType.Byte, pv); ExbuDic[Parob1seg].Add(TxPlcExpressionOperator.RightParenthesis); ExbuDic[Parob1seg].Add(TxPlcExpressionOperator.And); } } for (int j = 0; j < dataGridView8.Columns.Count; j++) { string rob2name = dataGridView8.Columns[j].HeaderText; string rob2seg = rob2name + str2; if (dataGridView8.Rows[i].Cells[j].Value != null && dataGridView8.Rows[i].Cells[j].Value != "") { if (j > 0) { ExbuDic[Parob1seg].Add(TxPlcExpressionOperator.And); } string strseg2 = dataGridView8.Rows[i].Cells[j].Value.ToString(); ExbuDic[Parob1seg].Add(TxPlcExpressionOperator.LeftParenthesis); ExbuDic[Parob1seg].Add(LBEnDic[rob2seg]); ExbuDic[Parob1seg].Add(TxPlcExpressionOperator.IsEqualTo); int c1 = 0; if (int.TryParse(strseg2, out c1)) { TxPlcValue pv = new TxPlcValue(); pv.ByteValue = (ushort)c1; ExbuDic[Parob1seg].Add(TxPlcSignalDataType.Byte, pv); ExbuDic[Parob1seg].Add(TxPlcExpressionOperator.RightParenthesis); } } } LBPaDic.Add(Parob1seg, SegPa(LB, Parob1seg, ExbuDic[Parob1seg].Expression)); } } foreach (KeyValuePair <string, TxPlcExpressionBuilder> k in ExbuDic1) { string strkey = k.Key; string[] str = strkey.Split('_'); TxRobot r1 = RobDictionary[str[0]]; int j = 0; foreach (KeyValuePair <string, ITxPlcLogicBehaviorParameter> k1 in LBPaDic) { if (k1.Key.Contains(str[0])) { if (j > 0 && j < LBPaDic.Count) { k.Value.Add(TxPlcExpressionOperator.Or); } k.Value.Add(k1.Value); j = j + 1; } } k.Value.Add(TxPlcExpressionOperator.RightParenthesis); SegEx(LB, FindSig(r1.Signals, str[1], false), k.Value.Expression); } //} //catch (System.Exception ex) //{ //} }
private void SegModlueS() { TxPlcExpressionBuilder eb1 = new TxPlcExpressionBuilder(); try { for (int i = 0; i < dataGridView2.Rows.Count; i++) { if (dataGridView2.Rows[i].Cells[0].Value != null && dataGridView2.Rows[i].Cells[1].Value != null) { string rob1name = dataGridView2.Rows[i].Cells[0].Value.ToString(); string strseg1 = dataGridView2.Rows[i].Cells[1].Value.ToString(); string str1 = textBox9.Text; string str2 = textBox10.Text; string str3 = textBox8.Text; TxRobot r1 = RobDictionary[rob1name]; eb1.Add(FindSig(r1.Signals, str3.Replace("Rob", rob1name), true)); eb1.Add(TxPlcExpressionOperator.And); //eb1.Add(TxPlcExpressionOperator.LeftParenthesis); eb1.Add(TxPlcExpressionOperator.LeftParenthesis); int c = 0; if (int.TryParse(strseg1, out c)) { TxPlcValue pv = new TxPlcValue(); pv.ByteValue = (ushort)c; eb1.Add(TxPlcExpressionOperator.LeftParenthesis); eb1.Add(FindSig(r1.Signals, str2.Replace("Rob", rob1name), true)); eb1.Add(TxPlcExpressionOperator.IsEqualTo); eb1.Add(TxPlcSignalDataType.Byte, pv); eb1.Add(TxPlcExpressionOperator.RightParenthesis); eb1.Add(TxPlcExpressionOperator.And); } for (int j = 0; j < dataGridView8.Columns.Count; j++) { string rob2name = dataGridView8.Columns[j].HeaderText; if (dataGridView8.Rows[i].Cells[j].Value != null) { if (j > 0) { eb1.Add(TxPlcExpressionOperator.And); } string strseg2 = dataGridView8.Rows[i].Cells[j].Value.ToString(); eb1.Add(TxPlcExpressionOperator.LeftParenthesis); eb1.Add(FindSig(Robots[j].Signals, str2.Replace("Rob", rob2name), true)); eb1.Add(TxPlcExpressionOperator.IsEqualTo); int c1 = 0; if (int.TryParse(strseg2, out c1)) { TxPlcValue pv = new TxPlcValue(); pv.ByteValue = (ushort)c1; eb1.Add(TxPlcSignalDataType.Byte, pv); eb1.Add(TxPlcExpressionOperator.RightParenthesis); } } } //eb1.Add(TxPlcExpressionOperator.RightParenthesis); eb1.Add(TxPlcExpressionOperator.RightParenthesis); if (string.Equals(rob1name, dataGridView2.Rows[i + 1].Cells[0].Value)) { eb1.Add(TxPlcExpressionOperator.Or); } else { ITxPlcSignal sig = FindSig(r1.Signals, str1.Replace("Rob", rob1name), false); ITxPlcModuleEntry pe = ModDictionary[rob1name].AddEntry(sig, eb1.Expression); eb1 = new TxPlcExpressionBuilder(); } } } } catch (System.Exception ex) { } }