public static void readDI(string id) { while (true) { DI tag; lock (db.DIs) { try { tag = DItags[id]; } catch { return; } double value; if (tag.OnOffScan) { if (tag.Driver == "SD") { value = SimulationDriver.ReturnValue(tag.Address); } else { value = RealTimeDriver.ReturnValue(tag.Address); } if (value > 0.5) { value = 1; } else { value = 0; } lock (locker) { TagValue tv = new TagValue("DI", tag.Id, dataKeyId, DateTime.Now, value); dataKeyId++; db.TagValues.Add(tv); db.SaveChanges(); } trending.write($"DI tag\t ID: {tag.Id}\t VALUE: {value} "); } } if (tag != null) { Thread.Sleep(tag.ScanTime * 1000); } } }
public static void readAI(string id) { double oldVal = -10000; while (true) { AI tag; lock (db.AIs) { try { tag = AItags[id]; } catch { return; } double value; if (tag.OnOffScan) { if (tag.Driver == "SD") { value = SimulationDriver.ReturnValue(tag.Address); } else { value = RealTimeDriver.ReturnValue(tag.Address); } if (value > tag.HighLimit) { value = tag.HighLimit; } else if (value < tag.LowLimit) { value = tag.LowLimit; } lock (locker) { TagValue tv = new TagValue("AI", tag.Id, dataKeyId, DateTime.Now, value); dataKeyId++; db.TagValues.Add(tv); } foreach (Alarm a in tag.Alarms) { if (a.checkAlarmActivated(value)) { lock (locker) { string alarmLogStr = $"AI tag ID: {tag.Id} is {a.Type.ToString()},\t Time>{DateTime.Now}"; StreamWriter file = new StreamWriter(alarmLogPath, append: true); file.WriteLine(alarmLogStr); file.Close(); for (int i = 0; i < a.Priority; i++) { lock (locker) { if (alarming != null) { alarming.write($"WARNING! AI tag ID: {tag.Id} is {a.Type.ToString()}"); } } } } } } if (trending != null && oldVal != value) { trending.write($"AI tag\t ID: {tag.Id}\t VALUE: {value} "); } oldVal = value; } } if (tag != null) { Thread.Sleep(tag.ScanTime * 1000); } } }