public async Task <IActionResult> SetStringValue(string variableName, string value) { await OPC.WriteVar(node, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>(variableName, value) }); await ReadValues(); return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> SetValues(string[] variableNames, string[] values, string[] types) { int submitCount = values.Count(h => h == "submit"); int submitsEncountered = 0; KeyValuePair <string, object>[] submitSignals = null; KeyValuePair <string, object>[] valuesToSet = new KeyValuePair <string, object> [variableNames.Length - submitCount]; for (int i = 0; i < variableNames.Length; i++) { switch (types[i]) { case "bool": valuesToSet[i - submitsEncountered] = new KeyValuePair <string, object>(variableNames[i], bool.Parse(values[i])); break; case "string": valuesToSet[i - submitsEncountered] = new KeyValuePair <string, object>(variableNames[i], (string)values[i]); break; case "ushort": valuesToSet[i - submitsEncountered] = new KeyValuePair <string, object>(variableNames[i], ushort.Parse(values[i])); break; case "int": valuesToSet[i - submitsEncountered] = new KeyValuePair <string, object>(variableNames[i], int.Parse(values[i])); break; case "submit": if (submitSignals == null) { submitSignals = new KeyValuePair <string, object> [1]; submitSignals[0] = new KeyValuePair <string, object>(variableNames[i], true); } else { submitSignals = submitSignals.Append(new KeyValuePair <string, object>(variableNames[i], true)).ToArray(); } submitsEncountered++; break; default: valuesToSet[i - submitsEncountered] = new KeyValuePair <string, object>(variableNames[i], values[i]); break; } } await OPC.WriteVar(node, valuesToSet); if (submitSignals != null) { await OPC.WriteVar(node, submitSignals); } await ReadValues(); return(RedirectToAction("Index", "Home")); }
public async Task <bool> ToggleValue(string variableName) { DataValue value = (await OPC.ReadVar(node, new string[] { variableName })).FirstOrDefault(); bool variable = value.GetValueOrDefault <bool>(); if (variable == false) { OPC.WriteVar(node, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>(variableName, true) }); } else { OPC.WriteVar(node, new KeyValuePair <string, object>[] { new KeyValuePair <string, object>(variableName, false) }); } return(true); }