Exemplo n.º 1
0
 private void Commanding_DoWork()
 {
     while (true)
     {
         try
         {
             Thread.Sleep(1000);
             foreach (var item in calculationEngineCommands)
             {
                 if (item.MillisecondsPassedSinceLastPoll >= item.Milliseconds)
                 {
                     processingManager.ExecuteWriteCommand(item.RegisterType, item.Index, item.Value);
                     item.Remove = true;
                 }
                 item.MillisecondsPassedSinceLastPoll += 1000;
             }
             calculationEngineCommands = new ConcurrentBag <CeCommand>(calculationEngineCommands.Where(x => x.Remove == false).ToList());
         }
         catch (Exception e)
         {
             ScadaProxyFactory.Instance().LoggingProxy().Log(new SCADA.Common.Logging.LogEventModel()
             {
                 EventType = SCADA.Common.Logging.LogEventType.ERROR,
                 Message   = $"{e.Message} - {e.StackTrace}"
             });
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Executes command for specified data
 /// </summary>
 /// <param name="pointId">Id of Point</param>
 /// <param name="address">Address of Point</param>
 /// <param name="value">Commanded Value</param>
 public void ExecuteCommand(int pointId, int address, int value)
 {
     if (pointsCache.TryGetValue(pointId, out IPoint point))
     {
         processingManager.ExecuteWriteCommand(point.ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, (ushort)address, value);
     }
 }
Exemplo n.º 3
0
        public RegisterData WriteCommand(int point, ushort value)
        {
            var         pointToWrite = storage.GetPoint(point) as BasePointItem;
            Transaction trans        = null;

            try
            {
                ushort tranId = configuration.GetTransactionId();
                processingManager.Transactions.Add(trans = new Transaction(tranId, pointToWrite.Address, false));
                processingManager.ExecuteWriteCommand(pointToWrite.ConfigItem, tranId, configuration.UnitAddress, pointToWrite.Address, (int)value);

                while (!(trans = processingManager.Transactions.Find(t => t.TransactionId == tranId)).Finished)
                {
                    Thread.Sleep(10);
                }

                processingManager.Transactions.Remove(trans);

                pointToWrite = storage.GetPoint(point) as BasePointItem;
                var returnValue = new RegisterData()
                {
                    PointId   = pointToWrite.PointId,
                    Alarm     = (WCFContract.AlarmType)pointToWrite.Alarm,
                    Timestamp = pointToWrite.Timestamp,
                    Type      = (WCFContract.PointType)pointToWrite.ConfigItem.RegistryType,
                    RawValue  = pointToWrite.RawValue,
                    EguValue  = pointToWrite.ConfigItem.RegistryType == Common.PointType.ANALOG_INPUT || pointToWrite.ConfigItem.RegistryType == Common.PointType.ANALOG_OUTPUT ? ((AnalogBase)pointToWrite).EguValue : 0,
                    State     = pointToWrite.ConfigItem.RegistryType == Common.PointType.DIGITAL_INPUT || pointToWrite.ConfigItem.RegistryType == Common.PointType.DIGITAL_OUTPUT ? (WCFContract.DState)((DigitalBase)pointToWrite).State : 0
                };
                return(returnValue);
            }
            catch
            {
                processingManager.Transactions.Remove(trans);
                return(null);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Defines custom work for automation
        /// </summary>
        private void AutomationWorker_DoWork()
        {
            int                    counter = 0;
            List <IPoint>          points;
            List <PointIdentifier> pointIdentifiers = new List <PointIdentifier>()
            {
                new PointIdentifier(PointType.DIGITAL_OUTPUT, 40),
                new PointIdentifier(PointType.DIGITAL_OUTPUT, 41),
                new PointIdentifier(PointType.DIGITAL_INPUT, 1000),
                new PointIdentifier(PointType.DIGITAL_INPUT, 1001),
                new PointIdentifier(PointType.ANALOG_INPUT, 2000),
                new PointIdentifier(PointType.ANALOG_INPUT, 2001),
                new PointIdentifier(PointType.ANALOG_OUTPUT, 3000),
                new PointIdentifier(PointType.ANALOG_OUTPUT, 3001),
            };

            while (!disposedValue)
            {
                if (counter == configuration.DelayBetweenCommands)
                {
                    points = storage.GetPoints(pointIdentifiers);

                    int    DO1 = ((IDigitalPoint)points[0]).RawValue;
                    int    DO2 = ((IDigitalPoint)points[1]).RawValue;
                    double AO1 = ((IAnalogPoint)points[6]).EguValue;
                    double AO2 = ((IAnalogPoint)points[7]).EguValue;

                    if (DO1 == 0)
                    {
                        DO1 = 1;
                        processingManager.ExecuteWriteCommand(points[0].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress,
                                                              pointIdentifiers[0].Address, DO1);
                    }

                    if (DO2 == 0)
                    {
                        DO2 = 1;
                        processingManager.ExecuteWriteCommand(points[1].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress,
                                                              pointIdentifiers[1].Address, DO2);
                    }

                    if (AO1 < 1000 || AO1 > 4500)
                    {
                        AO1 = 2000;
                        processingManager.ExecuteWriteCommand(points[6].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress,
                                                              pointIdentifiers[6].Address, (int)AO1);
                    }

                    if (AO2 < 1000 || AO2 > 4500)
                    {
                        AO2 = 2000;
                        processingManager.ExecuteWriteCommand(points[7].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress,
                                                              pointIdentifiers[7].Address, (int)AO2);
                    }

                    counter = 0;
                }
                automationTrigger.WaitOne();
                ++counter;
            }
        }
Exemplo n.º 5
0
        private void AutomationWorker_DoWork()
        {
            EGUConverter eguConverter = new EGUConverter();

            while (!disposedValue)
            {
                PointIdentifier        analogOut = new PointIdentifier(PointType.ANALOG_OUTPUT, 1000);
                PointIdentifier        izlaz1    = new PointIdentifier(PointType.DIGITAL_OUTPUT, 2000);
                PointIdentifier        izlaz2    = new PointIdentifier(PointType.DIGITAL_OUTPUT, 2001);
                PointIdentifier        izlaz3    = new PointIdentifier(PointType.DIGITAL_OUTPUT, 2002);
                PointIdentifier        izlaz4    = new PointIdentifier(PointType.DIGITAL_OUTPUT, 2003);
                PointIdentifier        punjac1   = new PointIdentifier(PointType.DIGITAL_OUTPUT, 3000);
                PointIdentifier        punjac2   = new PointIdentifier(PointType.DIGITAL_OUTPUT, 3001);
                List <PointIdentifier> points    = new List <PointIdentifier>()
                {
                    analogOut, izlaz1, izlaz2, izlaz3, izlaz4, punjac1, punjac2
                };
                //
                List <IPoint> pointList = storage.GetPoints(points);
                //
                ushort value       = pointList[0].RawValue;
                bool   ugasiIzlaz  = false;
                bool   ugasiPunjac = false;


                // kad rezervoar stigne do manje od 1000 onda ugasiti izlaze i upaliti punjace
                if (value < eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 1000))
                {
                    ugasiIzlaz = true;
                }

                // kad rezervoar stigne do vise od 8000 onda ugasiti punjace
                if (value > eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 8000))
                {
                    ugasiPunjac = true;
                }
                // logika za rad izlaza
                if (!ugasiIzlaz)
                {
                    if (pointList[1].RawValue == 1)
                    {
                        value -= eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 10);
                    }
                    if (pointList[2].RawValue == 1)
                    {
                        value -= eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 10);
                    }
                    if (pointList[3].RawValue == 1)
                    {
                        value -= eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 10);
                    }
                    if (pointList[4].RawValue == 1)
                    {
                        value -= eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 10);
                    }
                }

                if (!ugasiPunjac)
                {
                    if (pointList[5].RawValue == 1)
                    {
                        value += eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 100);
                    }
                    if (pointList[6].RawValue == 1)
                    {
                        value += eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 50);
                    }

                    // pokusaj zabrane promene
                    if (pointList[1].RawValue == 1)
                    {
                        processingManager.ExecuteWriteCommand(pointList[1].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[1].Address, 0);
                    }
                    if (pointList[2].RawValue == 1)
                    {
                        processingManager.ExecuteWriteCommand(pointList[2].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[2].Address, 0);
                    }
                    if (pointList[3].RawValue == 1)
                    {
                        processingManager.ExecuteWriteCommand(pointList[1].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[3].Address, 0);
                    }
                    if (pointList[4].RawValue == 1)
                    {
                        processingManager.ExecuteWriteCommand(pointList[2].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[4].Address, 0);
                    }
                }

                // slanje updatovane vrednosti nazad u rezervoar
                if (value != pointList[0].RawValue)
                {
                    processingManager.ExecuteWriteCommand(pointList[0].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[0].Address, value);
                }

                if (ugasiIzlaz)
                {
                    // ugasi sve izlaze
                    if (pointList[1].RawValue == 1)
                    {
                        processingManager.ExecuteWriteCommand(pointList[1].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[1].Address, 0);
                    }
                    if (pointList[2].RawValue == 1)
                    {
                        processingManager.ExecuteWriteCommand(pointList[2].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[2].Address, 0);
                    }
                    if (pointList[3].RawValue == 1)
                    {
                        processingManager.ExecuteWriteCommand(pointList[1].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[3].Address, 0);
                    }
                    if (pointList[4].RawValue == 1)
                    {
                        processingManager.ExecuteWriteCommand(pointList[2].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[4].Address, 0);
                    }

                    // upali sve punjace
                    if (pointList[5].RawValue == 0)
                    {
                        processingManager.ExecuteWriteCommand(pointList[5].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[5].Address, 1);
                    }
                    if (pointList[6].RawValue == 0)
                    {
                        processingManager.ExecuteWriteCommand(pointList[6].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[6].Address, 1);
                    }
                }

                // ugasi sve punjace
                if (ugasiPunjac)
                {
                    if (pointList[5].RawValue == 1)
                    {
                        processingManager.ExecuteWriteCommand(pointList[5].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[5].Address, 0);
                    }
                    if (pointList[6].RawValue == 1)
                    {
                        processingManager.ExecuteWriteCommand(pointList[6].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[6].Address, 0);
                    }
                }

                automationTrigger.WaitOne(delayBetweenCommands);
            }
        }
Exemplo n.º 6
0
 public void ExecuteCommand(ScadaCommand command)
 {
     processingManager.ExecuteWriteCommand(command.RegisterType, command.Index, command.Value);
 }