Ejemplo n.º 1
0
        private void UpdateInputTagValue(InputTag tag)
        {
            switch (tag.FunctionType)
            {
            case FunctionType.Sine:
                tag.SetValue(SimulationDriver.Sine());
                break;

            case FunctionType.Cosine:
                tag.SetValue(SimulationDriver.Cosine());
                break;

            case FunctionType.Ramp:
                tag.SetValue(SimulationDriver.Ramp());
                break;

            case FunctionType.Triangle:
                tag.SetValue(SimulationDriver.Triangle());
                break;

            case FunctionType.Rectangle:
                tag.SetValue(SimulationDriver.Rectangle());
                break;

            case FunctionType.Digital:
                tag.SetValue(SimulationDriver.Digital());
                break;
            }
            PublishTagUpdated(tag);
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        private void DeserializeTags()
        {
            if (!File.Exists("scadaConfig.xml"))
            {
                _simulationDriver = new SimulationDriver();
                return;
            }
            using (var reader = new StreamReader("scadaConfig.xml"))
            {
                var serializer = new XmlSerializer(typeof(List <Tag>));
                var tagsList   = (List <Tag>)serializer.Deserialize(reader);

                if (tagsList == null || tagsList.Count == 0)
                {
                    _simulationDriver = new SimulationDriver();
                }
                else
                {
                    _simulationDriver = tagsList[0].Driver;
                }

                lock (Locker)
                {
                    if (tagsList != null)
                    {
                        _tags = tagsList.ToDictionary(tag => tag.Id);
                    }
                    foreach (var tag in _tags.Values)
                    {
                        if (tag is InputTag && ((InputTag)tag).AutoMode)
                        {
                            StartInputTagUpdatingThread(tag);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        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);
                }
            }
        }