private ReadData GetReadData(ReadValue readValue) { var reg = _registrations[readValue.ClientAlias]; var readData = readValue.ToReadData(reg); return(readData); }
private void PushReadData(ReadValue readValue) { var reg = _registrations[readValue.ClientAlias]; var readData = readValue.ToReadData(reg); reg.OnNext(readData); }
private void FrmMain_Load(object sender, EventArgs e) { #region 判断系统是否已启动 System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcessesByName(Application.ProductName); //获取指定的进程名 if (myProcesses.Length > 1) //如果可以获取到知道的进程名则说明已经启动 { MessageBox.Show("程序已启动!"); Application.Exit(); //关闭系统 } #endregion CommonMethods.ReadConfig(); autoOutXlsToolStripMenuItem.Checked = Model.Global.AutoOut; if (autoOutXlsToolStripMenuItem.Checked) { autoOutXlsToolStripMenuItem.BackColor = Color.Green; } if (Global.SavePath == "") { Global.SavePath = Application.StartupPath + @"\Data\"; } Global.DateFilePath = Global.SavePath + DateTime.Now.Date.ToString("yyyy") + @"\" + DateTime.Now.Date.ToString("yyyyMM") + @"\"; ReadValue.ConnnectPlc1(); ReadValue.ConnnectPlc2(); this.Width = Screen.PrimaryScreen.Bounds.Width; this.Height = Screen.PrimaryScreen.Bounds.Height; this.StartPosition = FormStartPosition.CenterScreen; 检测界面ToolStripMenuItem_Click(null, null); timer.Interval = 500; timer.Tick += Timer_Tick; timer.Start(); ReadValue.StartRead1(); ReadValue.StartRead2(); }
protected override void OnReadValue(dynamic value) { try { dynamic source = value; if (Dictionary.ContainsValue(source)) { var tempValNameList = Dictionary.Where(x => x.Value == source); foreach (var tempValName in tempValNameList) { var tempValue = new { source.Value, tempValName.Key }; BaseClass.UpdateClass(tempValue); ReadValue[tempValName.Key] = true; } if (!ReadValue.ContainsValue(false)) { ReadyForUpdate = true; } } if (ReadyForUpdate) { BaseClass.UpdateServer(NameDataObj, _iedServer, _iedModel); Reset(); } } catch { Log.Log.Write($"DestinationObjectAnalog OnReadValue {value.GetType()}", "Warrning"); } }
public override void SetValue(string property, string value) { if (value == null) { Remove(property); return; } bool expression = IsExpression(value); ReadValue read = this.GetValue; if (expression) { read = base.GetValue; } Log.Verbose("Changing property {0} to {1}", property, value); bool changesMade = false; string original = read(property); if (original == value) { return; } foreach (BuildPropertyGroup grp in _project.PropertyGroups) { if (grp.IsImported) { continue; } foreach (BuildProperty prop in grp) { if (!prop.IsImported && StringComparer.OrdinalIgnoreCase.Equals(prop.Name, property)) { prop.Value = value; changesMade = true; } } } if (!changesMade || value != read(property)) { if (expression) { base.SetValue(property, value); } else { _project.SetProperty(property, value); } } string testNewValue = read(property); if (value != testNewValue) { throw new ApplicationException(String.Format("Unable to modify property value {0}", property)); } }
public static ReadData ReadDataEx(this XiDataList dataList, IAccessItemRegistration reg) { ReadValue readValue = dataList.ReadData(reg.ServerAlias); var rd = readValue.ToReadData(reg); return(rd); }
/// <summary> /// 读取表的三相数据 /// </summary> /// <param name="reading"></param> /// <returns></returns> public virtual bool Reading(out ThreePhase reading) { ReadValue value = new ReadValue(); bool result = Reading(out value); reading = ThreePhase.Parse(value); return(result); }
protected virtual void OnIsReturnEvent() { ReturnEndEvent handler = IsReturnEvent; if (handler != null) { handler(this, new ReturnEndReadEventargs(true, ReadValue.ToString())); } }
protected override void Reset() { foreach (var item in ReadValue.ToList()) { ReadValue[item.Key] = false; } ReadyForUpdate = true; }
/// <summary> /// 读取数据 /// </summary> /// <param name="reading"></param> /// <returns></returns> public virtual bool Reading(out ReadValue reading) { List <float> value = new List <float>(); Dictionary <string, string> parm = new Dictionary <string, string>(); parm.Add("Code", "All"); bool result = Read <float>(out value, parm); reading = new ReadValue(); //Vol*4,VolLine*4,Cur*4,Power*4,PowerNoUse*4,PowerAll*4,Factor*4,Hz*1,.....固定格式 if (result) { if (value == null) { All.Class.Error.Add(string.Format("电量表读取数据为空,读取数据错误")); return(false); } if (value.Count != 29) { All.Class.Error.Add(string.Format("电量表要求读取后的数据为29个才能进行转换,当前数据为{0}", value.Count)); return(false); } int index = 0; for (int i = 0; i < reading.Vol.Length; i++) { reading.Vol[i] = value[index++]; } for (int i = 0; i < reading.VolLine.Length; i++) { reading.VolLine[i] = value[index++]; } for (int i = 0; i < reading.Cur.Length; i++) { reading.Cur[i] = value[index++]; } for (int i = 0; i < reading.Power.Length; i++) { reading.Power[i] = value[index++]; } for (int i = 0; i < reading.PowerNoUse.Length; i++) { reading.PowerNoUse[i] = value[index++]; } for (int i = 0; i < reading.PowerAll.Length; i++) { reading.PowerAll[i] = value[index++]; } for (int i = 0; i < reading.Factor.Length; i++) { reading.Factor[i] = value[index++]; } reading.Hz = value[index++]; } return(result); }
/// <summary> /// 取所有数据中的三相数据 /// </summary> /// <param name="value"></param> /// <returns></returns> public static SinglePhase Parse(ReadValue value) { SinglePhase result = new SinglePhase(); result.Vol = value.Vol[0]; result.Cur = value.Cur[0]; result.Power = value.Power[0]; result.Factor = value.Factor[0]; result.Hz = value.Hz; return(result); }
public override void AddSource(SourceClass source, string name) { ReadValue.Add(name, false); Dictionary.Add(name, source); if (!SourceItem.Contains(source)) { SourceItem.Add(source); source.ReadValue += OnReadValue; } }
// private static dynamic ConvertReadData(AccessItemRegistration registerInfo, dynamic data) // { // return data; // } /* public static ReadData ToReadData(this ReadValue readData) * { * dynamic data = readData.DataValue.Value; * * var readData1 = new ReadData * { * Value = data, * ClientAlias = readData.ClientAlias, * }; * return readData1; * }*/ public static ReadData ToReadData(this ReadValue readData, IAccessItemRegistration reg) { dynamic data = readData.DataValue.Value; var readData1 = new ReadData { Value = DeviceConfigExtensions.Convert(data, reg), ClientAlias = readData.ClientAlias }; return(readData1); }
public async void Read2() { await Task.Run(() => { while (true) { //此处后续添加按钮使能判断 if (ReadValue.Read2())//读成功 { DataTreating2(); } } }); }
public object Clone() { ReadValue result = new ReadValue(); result.Result = this.Result; result.Over = this.Over; if (Value != null && Value.Count > 0) { Value.ForEach(value => { this.Value.Add((StepValue)value.Clone()); }); } return(result); }
/// <summary> /// 取所有数据中的三相数据 /// </summary> /// <param name="value"></param> /// <returns></returns> public static ThreePhase Parse(ReadValue value) { ThreePhase result = new ThreePhase(); result.Vol[0] = value.Vol[0]; result.Vol[1] = value.Vol[1]; result.Vol[2] = value.Vol[2]; result.Cur[0] = value.Cur[0]; result.Cur[1] = value.Cur[1]; result.Cur[2] = value.Cur[2]; result.Power[0] = value.Power[0]; result.Power[1] = value.Power[1]; result.Power[2] = value.Power[2]; result.Factor[0] = value.Factor[0]; result.Factor[1] = value.Factor[1]; result.Factor[2] = value.Factor[2]; result.Hz = value.Hz; return(result); }
/// <summary> /// 读取数据 /// </summary> /// <param name="reading"></param> /// <returns></returns> public virtual bool Reading(out ReadValue reading) { Dictionary <string, string> parm = new Dictionary <string, string>(); List <float> value = new List <float>(); parm.Add("Code", "Reading"); bool result = Read <float>(out value, parm); reading = new ReadValue(); int index = 0; //[Project,OutValue,Value,ValueTwo,ValueOther,Time,Active,Result]*N+Result,Over,.....固定格式 if (result && value != null && value.Count >= 2) { ReadValue.StepValue tmp; for (int i = 0; i < 8 && index < value.Count - 2; i++, index = index + 8) { if (value[index] == 0 && value[index + 1] == 0 && value[index + 2] == 0 && value[index + 3] == 0 && value[index + 4] == 0 && value[index + 5] == 0 && value[index + 6] == 0 && value[index + 7] == 0) { continue; } tmp = new ReadValue.StepValue(); tmp.Project = (Projects)(((int)(float)(object)value[index]) % Enum.GetNames(typeof(Projects)).Length); tmp.OutValue = (float)(object)value[index + 1]; tmp.Value = (float)(object)value[index + 2]; tmp.ValueTwo = (float)(object)value[index + 3]; tmp.ValueOther = (float)(object)value[index + 4]; tmp.Time = (float)(object)value[index + 5]; tmp.Active = (1 == (int)(float)(object)value[index + 6]); tmp.Result = (1 == (int)(float)(object)value[index + 7]); reading.Value.Add(tmp); } reading.Result = (1 == (int)(float)(object)value[index + 1]); reading.Over = (1 == (int)(float)(object)value[index]); } return(result); }
public TestViewModel(IEventAggregator eventAggregator, IWindowManager windowManager) { //初始化 _windowManager = windowManager; _eventAggregator = eventAggregator; _connectStatusEvent = new ConnectStatusEvent("离线!", "离线!"); Workrec1 = new Workrec(); Workrec2 = new Workrec(); Holerec1 = new Holerec(); Holerec2 = new Holerec(); Point1 = new Models.Point(); Point2 = new Models.Point(); ActualPoint1 = new ActualPoint(); ActualPoint2 = new ActualPoint(); StartTime = DateTime.Now.AddDays(-5); CanRedo2 = CanStop1 = CanRedo1 = CanStop2 = Working1 = Working2 = SubWorking1 = SubWorking2 = false; CanStart1 = CanStart2 = true; ReadValue.ConnnectPlc1(); InitalChart(); // 默认情况下开始画面曲线数据刷新 IsReading = IsWorking1 = true; Read1(); FreshCurve(); }
private void GenStmt(Stmt stmt) { //Обработка элемента последовательности дерева if (stmt is Sequence) { Sequence seq = (Sequence)stmt; //Выполним обработку левой части дерева this.GenStmt(seq.First); //Выполним обработку правой части дерева this.GenStmt(seq.Second); } //Обработка элемента дерева - "Объявление" else if (stmt is DeclareVar) { // Добавим переменную в список переменных DeclareVar declare = (DeclareVar)stmt; this.varTable[declare.Ident] = this.TypeOfExpr(declare.Expression); //Приведем элемент типа "Объевление" к типу "Присвоение" Assign assign = new Assign(); assign.Ident = declare.Ident; assign.Expression = declare.Expression; //Запишем тип переменной accum.Append(string.Format("\n{0} ", this.TypeOfExpr(declare.Expression).Name)); //Запустим на обработку this.GenStmt(assign); } //Обработка элемента дерева - "Присвоение" else if (stmt is Assign) { Assign assign = (Assign)stmt; accum.Append(string.Format("{0}=", assign.Ident)); //Обработка правой части элемента this.GenAssign(assign.Expression); accum.Append(";"); } //Обработка элемента дерева - "Вывод данных" else if (stmt is Print) { Print print = (Print)stmt; accum.Append(print.VarExpression != null ? string.Format("\nConsole.WriteLine(\"{0}\", {1});", this.GetExprValue(print.Expression), this.GetExprValue(print.VarExpression)) : string.Format("\nConsole.WriteLine(\"{0}\");", this.GetExprValue(print.Expression))); } //Обработка элемента дерева - "Ввод данных" else if (stmt is ReadValue) { ReadValue readValue = (ReadValue)stmt; accum.Append(readValue.Exp != null ? string.Format("\n{0} = Console.ReadLine(\"{1}\");", readValue.Ident, this.GetExprValue(readValue.Exp)) : string.Format("\n{0} = Console.ReadLine();", readValue.Ident)); //Проверка, что переменная объявлена ранее //CheckVariable } else if (stmt is IfElse) { IfElse ifElse = (IfElse)stmt; string operation = string.Empty; switch (ifElse.Condition.Operation) { case ConOperation.Equal: operation = "="; break; case ConOperation.Less: operation = "<"; break; case ConOperation.LessEqual: operation = "<="; break; case ConOperation.More: operation = ">"; break; case ConOperation.MoreEqual: operation = ">="; break; } accum.Append(string.Format("\nif ({0}{1}{2})", this.GetExprValue(ifElse.Condition.Left), operation, this.GetExprValue(ifElse.Condition.Right))); if (ifElse.BodyThen != null) { accum.Append("\n{\n"); this.GenStmt(ifElse.BodyThen); accum.Append("\n}"); } if (ifElse.BodyElse != null) { if (ifElse.BodyThen == null) { throw new System.Exception("error if - else"); } accum.Append("\nelse\n{\n"); this.GenStmt(ifElse.BodyElse); accum.Append("\n}"); } } else if (stmt is ForNext) { ForNext forNext = (ForNext)stmt; accum.Append(string.Format("\nfor(")); Assign assign = new Assign(); assign.Ident = forNext.Ident; assign.Expression = forNext.From; this.GenStmt(assign); accum.Append(string.Format("{0}<{1};{2}++)", forNext.Ident, this.GetExprValue(forNext.To), forNext.Ident)); this.varTable[forNext.Ident] = typeof(int); if (forNext.Body != null) { accum.Append("\n{"); this.GenStmt(forNext.Body); accum.Append("\n}"); } } else { throw new System.Exception("Отсутствует инструкция для генерирования операции: " + stmt.GetType().Name); } }
public override void GetValueResponse(dynamic value) { Value = value; ReadValue?.Invoke(this); }
public Token(string name, ReadValue value) : this(name, null, s => value()) { }
public TokensSet Add(string name, ReadValue value) { _tokens.Add(name, new Token(name, value)); return this; }
private Stmt ParseStmt() { Stmt result; if (this.index == this.tokens.Count) { throw new System.Exception("expected statement, got EOF"); } // <stmt> := print <expr> // <expr> := <string> // | <int> // | <arith_expr> // | <ident> if (this.tokens[this.index].Equals("print")) { this.index++; Print print = new Print(); //Если есть текстовое описание if (this.index < this.tokens.Count && this.tokens[this.index] is Text.StringBuilder) { print.Expression = this.ParseExpr(); } if (this.index < this.tokens.Count && this.tokens[this.index] is string) { print.VarExpression = this.ParseExpr(); } result = print; } else if (this.tokens[this.index].Equals("var")) { this.index++; DeclareVar declareVar = new DeclareVar(); if (this.index < this.tokens.Count && this.tokens[this.index] is string) { declareVar.Ident = (string)this.tokens[this.index]; } else { throw new System.Exception("expected variable name after 'var'"); } this.index++; if (this.index == this.tokens.Count || this.tokens[this.index] != Scanner.Equal) { throw new System.Exception("expected = after 'var ident'"); } this.index++; declareVar.Expression = this.ParseExpr(); result = declareVar; } else if (this.tokens[this.index].Equals("input")) { this.index++; ReadValue readValue = new ReadValue(); //Если есть текстовое описание if (this.index < this.tokens.Count && this.tokens[this.index] is Text.StringBuilder) { readValue.Exp = this.ParseExpr(); } if (this.index < this.tokens.Count && this.tokens[this.index] is string) { readValue.Ident = (string)this.tokens[this.index++]; result = readValue; } else { throw new System.Exception("expected variable name after 'input'"); } } /*else if (this.tokens[this.index].Equals("read_int")) * { * this.index++; * ReadValue readValue = new ReadValue(); * * if (this.index < this.tokens.Count && * this.tokens[this.index] is string) * { * readValue.Ident = (string)this.tokens[this.index++]; * result = readValue; * } * else * { * throw new System.Exception("expected variable name after 'read_int'"); * } * }*/ else if (this.tokens[this.index].Equals("for")) { this.index++; ForNext forNext = new ForNext(); if (this.index < this.tokens.Count && this.tokens[this.index] is string) { forNext.Ident = (string)this.tokens[this.index]; } else { throw new System.Exception("expected identifier after 'for'"); } this.index++; if (this.index == this.tokens.Count || this.tokens[this.index] != Scanner.Equal) { throw new System.Exception("for missing '='"); } this.index++; forNext.From = this.ParseExpr(); if (this.index == this.tokens.Count || !this.tokens[this.index].Equals("to")) { throw new System.Exception("expected 'to' after for"); } this.index++; forNext.To = this.ParseExpr(); /*if (this.index == this.tokens.Count || * !this.tokens[this.index].Equals("do")) * { * throw new System.Exception("expected 'do' after from expression in for next"); * }*/ this.index++; forNext.Body = this.ParseStmt(); result = forNext; if (this.index == this.tokens.Count || !this.tokens[this.index].Equals("next")) { throw new System.Exception("unterminated 'for' loop body"); } this.index++; } else if (this.tokens[this.index].Equals("if")) { this.index++; IfElse ifthen = new IfElse(); ifthen.Condition = new ConExpression(); //Запишем первый операнд в условии if (this.index < this.tokens.Count && this.tokens[this.index] is string) { ifthen.Condition.Left = this.ParseExpr(); } else { throw new System.Exception("expected identifier after 'if'"); } // Запишем условный оператор if (this.tokens[this.index] == Scanner.More) //Больше { ifthen.Condition.Operation = ConOperation.More; } else if (this.tokens[this.index] == Scanner.MoreEqual) //Больше-равно { ifthen.Condition.Operation = ConOperation.MoreEqual; } else if (this.tokens[this.index] == Scanner.Less) //Меньше { ifthen.Condition.Operation = ConOperation.Less; } else if (this.tokens[this.index] == Scanner.LessEqual) //Меньше-равно { ifthen.Condition.Operation = ConOperation.LessEqual; } else if (this.tokens[this.index] == Scanner.Equal) //Равенство { ifthen.Condition.Operation = ConOperation.Equal; } else { throw new System.Exception("missing condition operator"); } //Запишем второй операнд в условии this.index++; ifthen.Condition.Right = this.ParseExpr(); if (this.index == this.tokens.Count || !this.tokens[this.index].Equals("then")) { throw new System.Exception("expected 'then' after if"); } this.index++; ifthen.BodyThen = this.ParseStmt(); if (this.index < this.tokens.Count && this.tokens[this.index].Equals("else")) { this.index++; ifthen.BodyElse = this.ParseStmt(); } result = ifthen; if (this.index == this.tokens.Count || !this.tokens[this.index].Equals("endif")) { throw new System.Exception("unterminated 'if' body"); } this.index++; } else if (this.tokens[this.index] is string) { //--------------------------------------------------------- // assignment Assign assign = new Assign(); assign.Ident = (string)this.tokens[this.index++]; if (this.index == this.tokens.Count || this.tokens[this.index] != Scanner.Equal) { throw new System.Exception("expected '='"); } this.index++; assign.Expression = this.ParseExpr(); //Проверим наличие операции if (this.tokens[this.index] != Scanner.Semi) { assign.Expression = this.ParseBinExpr(assign.Expression); } result = assign; } else { throw new System.Exception("parse error at token " + this.index + ": " + this.tokens[this.index]); } if (this.index < this.tokens.Count && this.tokens[this.index] == Scanner.Semi) { this.index++; if (this.index < this.tokens.Count && !this.tokens[this.index].Equals("next") && !this.tokens[this.index].Equals("endif") && !this.tokens[this.index].Equals("else")) { Sequence sequence = new Sequence(); sequence.First = result; sequence.Second = this.ParseStmt(); result = sequence; } } return(result); }
public ValueDynamic(Scrollbar _scroll, ReadValue _readValue) : base() { scroll = _scroll; readValue = _readValue; }