static public void SetValue(NameVar var, string value) { if (var.modbus == null) { if (!dumps.ContainsKey(var.subsystem)) { throw new ArgumentException("Subsystem " + var.subsystem + " not supported!"); } Dumper dump = dumps[var.subsystem]; string str = dump.GetValueStr(var.name); if (str == null) { throw new ArgumentException("Subsystem " + var.subsystem + " var " + var.name + " not found!"); } dump.SetValue(var.name, value); return; } if (!masters.ContainsKey(var.subsystem + "." + var.modbus)) { throw new ArgumentException("Subsystem " + var.subsystem + " and modbus" + var.modbus + " not supported!"); } MasterModbus master = masters[var.subsystem + "." + var.modbus]; string result = master.GetValueString(var.name); if (result == null) { throw new ArgumentException("Subsystem " + var.subsystem + " modbus " + var.modbus + " var " + var.name + " not found!"); } if (master.IsReadOnly(var.name)) { throw new ArgumentException("Subsystem " + var.subsystem + " modbus " + var.modbus + " var " + var.name + " read only!"); } master.SetValueString(var.name, value); }
protected override Parser.Result Evaluate(string data, ref int from) { string varName = Utils.GetToken(data, ref from, Constants.END_ARG_ARRAY); if (from >= data.Length) { throw new ArgumentException("Couldn't set variable before end of line"); } NameVar nv = new NameVar(varName); Parser.Result varValue = new Parser.Result(); ScDumper.SetValue(nv, varValue.Value.ToString()); return(varValue); }
protected override Parser.Result Evaluate(string data, ref int from) { string varName = Utils.GetToken(data, ref from, Constants.END_ARG_ARRAY); if (from >= data.Length) { throw new ArgumentException("Couldn't set variable before end of line"); } NameVar nv = new NameVar(varName); Parser.Result varValue = new Parser.Result(); string value = ScDumper.GetValue(nv); varValue.Value = Double.Parse(value); // Check if the variable to be set has the form of x(0), // meaning that this is an array element. int arrayIndex = Utils.ExtractArrayElement(ref varName); if (arrayIndex >= 0) { bool exists = ParserFunction.FunctionExists(varName); Parser.Result currentValue = exists ? ParserFunction.GetFunction(varName).GetValue(data, ref from) : new Parser.Result(); List <Parser.Result> tuple = currentValue.Tuple ?? new List <Parser.Result>(); if (tuple.Count > arrayIndex) { tuple[arrayIndex] = varValue; } else { for (int i = tuple.Count; i < arrayIndex; i++) { tuple.Add(new Parser.Result(Double.NaN, string.Empty)); } tuple.Add(varValue); } varValue = new Parser.Result(Double.NaN, null, tuple); } ParserFunction.AddFunction(varName, new GetVarFunction(varValue)); return(new Parser.Result(Double.NaN, varName)); }
static public string GetValue(NameVar var) { if (var.modbus == null) { if (!dumps.ContainsKey(var.subsystem)) { throw new ArgumentException("Subsystem " + var.subsystem + " not supported!"); } Dumper dump = dumps[var.subsystem]; string str = dump.GetValueStr(var.name); if (str == null) { throw new ArgumentException("Subsystem " + var.subsystem + " var " + var.name + "not found!"); } if (str.Contains("true")) { str = "1"; } if (str.Contains("false")) { str = "0"; } return(str); } if (!masters.ContainsKey(var.subsystem + "." + var.modbus)) { throw new ArgumentException("Subsystem " + var.subsystem + " and modbus" + var.modbus + " not supported!"); } MasterModbus master = masters[var.subsystem + "." + var.modbus]; string result = master.GetValueString(var.name); if (result == null) { throw new ArgumentException("Subsystem " + var.subsystem + " modbus " + var.modbus + " var " + var.name + "not found!"); } if (result.Contains("true")) { result = "1"; } if (result.Contains("false")) { result = "0"; } return(result); }