protected void UpdateComment(string valuestring) { if (ValueString1.Equals(valuestring)) { CommentString1 = ValueCommentManager.GetComment(valuestring); PropertyChanged(this, new PropertyChangedEventArgs("CommentString1")); } if (ValueString2.Equals(valuestring)) { CommentString2 = ValueCommentManager.GetComment(valuestring); PropertyChanged(this, new PropertyChangedEventArgs("CommentString2")); } if (ValueString3.Equals(valuestring)) { CommentString3 = ValueCommentManager.GetComment(valuestring); PropertyChanged(this, new PropertyChangedEventArgs("CommentString3")); } if (ValueString4.Equals(valuestring)) { CommentString4 = ValueCommentManager.GetComment(valuestring); PropertyChanged(this, new PropertyChangedEventArgs("CommentString4")); } if (ValueString5.Equals(valuestring)) { CommentString5 = ValueCommentManager.GetComment(valuestring); PropertyChanged(this, new PropertyChangedEventArgs("CommentString5")); } }
private void ValueTextBox5_TextChanged(object sender, TextChangedEventArgs e) { switch (InstMode) { case INST_ATCH: IEnumerable <string> fit = SubRoutines.Where( (string name) => { return(name.Equals(ValueString5)); }); if (fit.Count() == 0) { ValueTextBox5.Background = Brushes.Red; } else { ValueTextBox5.Background = Brushes.White; } PropertyChanged(this, new PropertyChangedEventArgs("CollectionSource")); return; } if (ValueParser.IsVariablePattern(ValueString5)) { CommentString5 = ValueCommentManager.GetComment(ValueString5); } else { CommentString5 = ValueCommentManager.GetComment(ValueString5.ToUpper()); } }
private void ValueTextBox7_TextChanged(object sender, TextChangedEventArgs e) { if (ValueParser.IsVariablePattern(ValueString7)) { CommentString7 = ValueCommentManager.GetComment(ValueString7); } else { CommentString7 = ValueCommentManager.GetComment(ValueString7.ToUpper()); } }
public void UpdateComment() { foreach (TextBlock comment in comments) { if (G_Inst.Children.Contains(comment)) { G_Inst.Children.Remove(comment); } } comments.Clear(); int rowid = 0; foreach (PLCOriginInst inst in insts) { BaseViewModel bvmodel = inst.ProtoType; if (bvmodel != null) { TextBlock cmt = new TextBlock(); cmt.Visibility = iscommentmode ? Visibility.Visible : Visibility.Hidden; cmt.Foreground = Brushes.Green; cmt.Text = "//"; BaseModel bmodel = bvmodel.Model; for (int i = 0; i < bmodel.ParaCount; i++) { IValueModel ivmodel = bmodel.GetPara(i); cmt.Text += String.Format("{0:s}:{1:s},", ivmodel.ValueString, ValueCommentManager.GetComment(ivmodel)); } Grid.SetRow(cmt, rowid); Grid.SetColumn(cmt, 7); G_Inst.Children.Add(cmt); comments.Add(cmt); } rowid++; } }
private void ValueTextBox1_TextChanged(object sender, TextChangedEventArgs e) { switch (InstMode) { case INST_CALLM: IEnumerable <string[]> fit = Functions.Where( (string[] msgs) => { return(msgs[1].Equals(ValueString1)); }); if (fit.Count() == 0) { ValueTextBox1.Background = Brushes.Red; ValueCount = 1; } else { ValueTextBox1.Background = Brushes.White; string[] msgs = fit.First(); ValueCount = msgs.Length / 2; switch (ValueCount) { case 1: ShowLine1("FUNC"); ValueString1 = msgs[1]; break; case 2: ShowLine1("FUNC"); ValueString1 = msgs[1]; ShowLine2(msgs[2].Remove(msgs[2].Length - 1)); break; case 3: ShowLine1("FUNC"); ValueString1 = msgs[1]; ShowLine2(msgs[2].Remove(msgs[2].Length - 1)); ShowLine3(msgs[4].Remove(msgs[4].Length - 1)); break; case 4: ShowLine1("FUNC"); ValueString1 = msgs[1]; ShowLine2(msgs[2].Remove(msgs[2].Length - 1)); ShowLine3(msgs[4].Remove(msgs[4].Length - 1)); ShowLine4(msgs[6].Remove(msgs[6].Length - 1)); break; case 5: ShowLine1("FUNC"); ValueString1 = msgs[1]; ShowLine2(msgs[2].Remove(msgs[2].Length - 1)); ShowLine3(msgs[4].Remove(msgs[4].Length - 1)); ShowLine4(msgs[6].Remove(msgs[6].Length - 1)); ShowLine5(msgs[8].Remove(msgs[8].Length - 1)); break; default: throw new ArgumentException("Error Function Messages Array"); } } PropertyChanged(this, new PropertyChangedEventArgs("CollectionSource")); return; } if (ValueParser.IsVariablePattern(ValueString1)) { CommentString1 = ValueCommentManager.GetComment(ValueString1); } else { CommentString1 = ValueCommentManager.GetComment(ValueString1.ToUpper()); } }
/// <summary> /// 写入所有软元件的信息 /// </summary> /// <param name="option">选项</param> unsafe static private void WriteRegisters(int option) { // 头标志(0xfc)和长度 edata.Add(0xfc); edata.Add(Int32_Low(regs.Count())); edata.Add(Int32_High(regs.Count())); // 将表中的所有软元件逐一写入 foreach (IValueModel ivmodel in regs) { // 整数常量(包括单字和双字) if (ivmodel is KWordValue || ivmodel is KDoubleWordValue) { if (ivmodel is KWordValue) { edata.Add((byte)(DownloadRegisterType.K)); } else { edata.Add((byte)(DownloadRegisterType.K32)); } int value = int.Parse(ivmodel.ValueString.Substring(1)); for (int i = 0; i < 4; i++) { edata.Add((byte)(value & 0xff)); value >>= 8; } } // 16进制表示的整数常量(包括单字和双字) else if (ivmodel is HWordValue || ivmodel is HDoubleWordValue) { if (ivmodel is HWordValue) { edata.Add((byte)(DownloadRegisterType.H)); } else { edata.Add((byte)(DownloadRegisterType.H32)); } string value = ivmodel.ValueString; for (int i = 0; i < 4; i++) { int p = value.Length - i * 2 - 2; byte valueb = p < 1 ? (byte)(0x00) : char.IsDigit(value[p]) ? (byte)(value[p] - '0') : (byte)(char.ToUpper(value[p]) - 'A' + 10); p = value.Length - i * 2 - 1; valueb <<= 4; valueb |= p < 1 ? (byte)(0x00) : char.IsDigit(value[p]) ? (byte)(value[p] - '0') : (byte)(char.ToUpper(value[p]) - 'A' + 10); edata.Add(valueb); } } // 浮点常量 else if (ivmodel is KFloatValue) { edata.Add((byte)(DownloadRegisterType.F)); float valuef = float.Parse(((KFloatValue)ivmodel).ValueString.Substring(1)); int value = *((int *)(&valuef)); for (int i = 0; i < 4; i++) { edata.Add((byte)(value & 0xff)); value >>= 8; } } // 字符串 else if (ivmodel is StringValue) { edata.Add((byte)(DownloadRegisterType.STR)); Write(ivmodel.ValueString); } // 寄存器 else { // 函数参数获取原型 IValueModel _ivmodel = ivmodel; if (_ivmodel is ArgumentValue) { _ivmodel = ((ArgumentValue)_ivmodel).Argument; } // 判断基地址并写入 if (_ivmodel is XBitValue) { edata.Add((byte)(DownloadRegisterType.X)); } if (_ivmodel is YBitValue) { edata.Add((byte)(DownloadRegisterType.Y)); } if (_ivmodel is SBitValue) { edata.Add((byte)(DownloadRegisterType.S)); } if (_ivmodel is MBitValue) { edata.Add((byte)(DownloadRegisterType.M)); } if (_ivmodel is CBitValue) { edata.Add((byte)(DownloadRegisterType.C)); } if (_ivmodel is TBitValue) { edata.Add((byte)(DownloadRegisterType.T)); } if (_ivmodel is DWordValue) { edata.Add((byte)(DownloadRegisterType.D)); } if (_ivmodel is AIWordValue) { edata.Add((byte)(DownloadRegisterType.AI)); } if (_ivmodel is AOWordValue) { edata.Add((byte)(DownloadRegisterType.AO)); } if (_ivmodel is CVWordValue) { edata.Add((byte)(DownloadRegisterType.CV)); } if (_ivmodel is TVWordValue) { edata.Add((byte)(DownloadRegisterType.TV)); } if (_ivmodel is VWordValue) { edata.Add((byte)(DownloadRegisterType.V)); } if (_ivmodel is ZWordValue) { edata.Add((byte)(DownloadRegisterType.Z)); } if (_ivmodel is CV32DoubleWordValue) { edata.Add((byte)(DownloadRegisterType.CV32)); } // 写入下标位置 edata.Add(Int32_Low((int)(_ivmodel.Index))); edata.Add(Int32_High((int)(_ivmodel.Index))); // 写入变址信息(基地址,下标) if (_ivmodel.IsVariable) { if (_ivmodel.Offset is VWordValue) { edata.Add((byte)(DownloadRegisterType.V)); } else if (_ivmodel.Offset is ZWordValue) { edata.Add((byte)(DownloadRegisterType.Z)); } else { edata.Add(0x00); } edata.Add(Int32_Low((int)(_ivmodel.Offset.Index))); } // 非变址软元件则写入空数据 else { edata.Add(0x00); edata.Add(0x00); } } // 根据选项选择是否写入注释 if ((option & OPTION_COMMENT) != 0) { string comment = ValueCommentManager.GetComment(ivmodel); Write(comment); } } }