public bool SwitchAutoManual(string tagId) { for (int i = 0; i < tags.Count; i++) { if (tags[i].ID.Equals(tagId)) { if (tags[i].GetType() == typeof(DigitalInput)) { DigitalInput temp = (DigitalInput)tags[i]; temp.AutoManual = !temp.AutoManual; tags[i] = temp; Serialize(); return(true); } else if (tags[i].GetType() == typeof(AnalogInput)) { AnalogInput temp = (AnalogInput)tags[i]; temp.AutoManual = !temp.AutoManual; tags[i] = temp; Serialize(); return(true); } } } return(false); }
public void addAI(AnalogInput el) { if (el != null && !tags.ContainsKey(el.TagName)) { lock (tags) { tags.Add(el.TagName, el); } Console.WriteLine("AI Tag :" + el.TagName + " is added"); } }
public bool AddAITag(string id, string desc, int scanTime, bool realTime, string rtuId, double lowLimit, double highLimit, string units, string simType) { foreach (Tag iter in tags) { if (iter.ID.Equals(id)) { return(false); } } AnalogInput tag = new AnalogInput(); tag.ID = id; tag.Description = desc; tag.ScanTime = scanTime; tag.Alarms = new List <string>(); tag.AutoManual = true; tag.OnOffScan = true; tag.LowLimit = lowLimit; tag.HighLimit = highLimit; tag.Units = units; if (realTime) { tag.Driver = true; tag.IOAddress = RTUIdAddressMap[rtuId]; connectedRTUs[rtuId] = id; } else { tag.Driver = false; tag.IOAddress = rtuId; InitSimulation(simType, rtuId); //tags.Add(tag); //return true; } tags.Add(tag); Thread thread = new Thread(tag.Scan); threads[tag.ID] = thread; threads[tag.ID].Start(); return(true); }
public bool ChangeInfo(string tagId, Tuple <string, string> newVal) { int i; Tag tag = null; bool check = false; for (i = 0; i < tags.Count; i++) { if (tags[i].ID.Equals(tagId)) { check = true; tag = tags[i]; break; } } if (!check) { return(false); } if (!newVal.Item2.Equals("")) { if (newVal.Item1.Equals("Name")) { tag.ID = newVal.Item2; } else if (newVal.Item1.Equals("Description")) { tag.Description = newVal.Item2; } else if (newVal.Item1.Equals("Units")) { if (tag.GetType() == typeof(AnalogInput)) { AnalogInput temp = (AnalogInput)tag; temp.Units = newVal.Item2; tag = temp; } else { AnalogOutput temp = (AnalogOutput)tag; temp.Units = newVal.Item2; tag = temp; } } else if (newVal.Item1.Equals("Low limit")) { if (tag.GetType() == typeof(AnalogInput)) { AnalogInput temp = (AnalogInput)tag; temp.LowLimit = double.Parse(newVal.Item2); tag = temp; } else { AnalogOutput temp = (AnalogOutput)tag; temp.LowLimit = double.Parse(newVal.Item2); tag = temp; } } else if (newVal.Item1.Equals("High limit")) { if (tag.GetType() == typeof(AnalogInput)) { AnalogInput temp = (AnalogInput)tag; temp.HighLimit = double.Parse(newVal.Item2); tag = temp; } else { AnalogOutput temp = (AnalogOutput)tag; temp.HighLimit = double.Parse(newVal.Item2); tag = temp; } } else if (newVal.Item1.Equals("Scan time")) { if (tag.GetType() == typeof(AnalogInput)) { AnalogInput temp = (AnalogInput)tag; temp.ScanTime = int.Parse(newVal.Item2); tag = temp; } else { DigitalInput temp = (DigitalInput)tag; temp.ScanTime = int.Parse(newVal.Item2); tag = temp; } } else // Inital value { if (tag.GetType() == typeof(AnalogInput)) { DigitalOutput temp = (DigitalOutput)tag; temp.InitialValue = double.Parse(newVal.Item2); tag = temp; } else { AnalogOutput temp = (AnalogOutput)tag; temp.InitialValue = double.Parse(newVal.Item2); tag = temp; } } } tags[i] = tag; Serialize(); return(true); }
public Dictionary <string, string> GetTagInfo(string tagId) { Dictionary <string, string> retVal = new Dictionary <string, string>(); foreach (Tag tag in tags) { if (tag.ID.Equals(tagId)) { if (tag.GetType() == typeof(DigitalInput)) { DigitalInput temp = (DigitalInput)tag; retVal["Name"] = temp.ID; retVal["Type"] = "DigitalInput"; retVal["Description"] = temp.Description; retVal["Driver"] = temp.Driver ? "Real-Time" : "Simulation"; retVal["I/O Address"] = temp.IOAddress; retVal["Scan time"] = temp.ScanTime.ToString(); string alarms = ""; foreach (string s in temp.Alarms) { alarms += s + "\n"; } retVal["Alarms"] = alarms; retVal["Scan"] = temp.OnOffScan ? "ON" : "OFF"; retVal["Auto/Manual"] = temp.AutoManual ? "AUTO" : "MANUAL"; return(retVal); } else if (tag.GetType() == typeof(AnalogInput)) { AnalogInput temp = (AnalogInput)tag; retVal["Name"] = temp.ID; retVal["Type"] = "AnalogInput"; retVal["Description"] = temp.Description; retVal["Driver"] = temp.Driver ? "Real-Time" : "Simulation"; retVal["I/O Address"] = temp.IOAddress; retVal["Scan time"] = temp.ScanTime.ToString(); string alarms = ""; foreach (string s in temp.Alarms) { alarms += s + "\n"; } retVal["Alarms"] = alarms; retVal["Scan"] = temp.OnOffScan ? "ON" : "OFF"; retVal["Auto/Manual"] = temp.AutoManual ? "AUTO" : "MANUAL"; retVal["Low limit"] = temp.LowLimit.ToString(); retVal["High limit"] = temp.HighLimit.ToString(); retVal["Units"] = temp.Units; return(retVal); } else if (tag.GetType() == typeof(DigitalOutput)) { DigitalOutput temp = (DigitalOutput)tag; retVal["Name"] = temp.ID; retVal["Type"] = "DigitalOutput"; retVal["Description"] = temp.Description; retVal["Driver"] = temp.Driver ? "Real-Time" : "Simulation"; retVal["I/O Address"] = temp.IOAddress; retVal["Initial value"] = temp.InitialValue.ToString(); return(retVal); } else { AnalogOutput temp = (AnalogOutput)tag; retVal["Name"] = temp.ID; retVal["Type"] = "AnalogOutput"; retVal["Description"] = temp.Description; retVal["Driver"] = temp.Driver ? "Real-Time" : "Simulation"; retVal["I/O Address"] = temp.IOAddress; retVal["Low limit"] = temp.LowLimit.ToString(); retVal["High limit"] = temp.HighLimit.ToString(); retVal["Units"] = temp.Units; retVal["Initial value"] = temp.InitialValue.ToString(); return(retVal); } } } return(null); }