Exemplo n.º 1
0
        public LevelSensor(OpcSimModule parent, OpcName name, OpcContext context, double maxLevel) : base(parent, name, context)
        {
            _maxLevelKg             = new OpcAnalogItemNode <double>(this, "MaxLevelKg", maxLevel);
            _maxLevelKg.AccessLevel = OpcAccessLevel.CurrentRead;

            _levelKg = new OpcAnalogItemNode <double>(this, "LevelKg");
            _levelKg.InstrumentRange      = new OpcValueRange(MaxLevelKg, 0);
            _levelKg.EngineeringUnit      = new OpcEngineeringUnitInfo(4933453, "Kg", "Kilogramm");
            _levelKg.EngineeringUnitRange = new OpcValueRange(MaxLevelKg, 0);
            _levelKg.Description          = "Füllstand in Kilogramm";
            _levelKg.BeforeApplyChanges  += _levelKg_BeforeApplyChanges;

            _levelPercent             = new OpcDataVariableNode <double>(this, "LevelPercent");
            _levelPercent.Description = "Füllstand in Prozent";
            _levelPercent.AccessLevel = OpcAccessLevel.CurrentRead;

            _alarmLevelHeigh             = new OpcDataVariableNode <bool>(this, "AlarmFüllstandHoch");
            _alarmLevelHeigh.Description = "Füllstand > 95%";

            _warningLevelHeigh             = new OpcDataVariableNode <bool>(this, "WarnungFüllstandHoch");
            _warningLevelHeigh.Description = "Füllstand > 80%";

            //Random r = new Random();
            //LevelKg = r.NextDouble() * 5000.0;
        }
Exemplo n.º 2
0
        private OpcDataVariableNode <T> CreateNode <T>(
            OpcFolderNode nodes,
            T defaultValue,
            Func <T, int, T> randomizer = null)
        {
            var name = typeof(T).Name;

            name = char.ToUpper(name[0]) + name.Substring(1);

            if (typeof(T).IsArray)
            {
                name = typeof(T).GetElementType().Name + "Array";
            }

            var node = new OpcDataVariableNode <T>(nodes, name, defaultValue);

            node.ReadVariableValueCallback  = this.HandleReadVariableValue;
            node.WriteVariableValueCallback = this.HandleWriteVariableValue;

            if (randomizer != null)
            {
                this.tasks.Add(() => {
                    node.Value = randomizer(node.Value, this.valueRandom.Next(0, 183));
                    node.ApplyChanges(this.SystemContext);
                });
            }

            return(node);
        }
Exemplo n.º 3
0
 public ManualControl(IOpcNode parent, OpcName name, OpcContext context) : base(parent, name, context)
 {
     _start                    = new OpcDataVariableNode <bool>(this, "Ein");
     _start.AccessLevel        = OpcAccessLevel.CurrentRead;
     _manualActive             = new OpcDataVariableNode <bool>(this, "Erlaubt");
     _manualActive.AccessLevel = OpcAccessLevel.CurrentRead;
 }
Exemplo n.º 4
0
        public Zyklon(IOpcNode parent, OpcName name, OpcContext context, Drehrohrofen ofen) : base(parent, name, context)
        {
            Ofen = ofen;
            tempSensors.Add(new TemperaturSensor(this, "Temperatur_1,", Context)
            {
                UpperLimit = Ofen.MaxTemp
            });
            tempSensors.Add(new TemperaturSensor(this, "Temperatur_2,", Context)
            {
                UpperLimit = Ofen.MaxTemp
            });
            tempSensors.Add(new TemperaturSensor(this, "Temperatur_3,", Context)
            {
                UpperLimit = Ofen.MaxTemp
            });
            tempSensors.Add(new TemperaturSensor(this, "Temperatur_4,", Context)
            {
                UpperLimit = Ofen.MaxTemp
            });
            tempSensors.Add(new TemperaturSensor(this, "Temperatur_5,", Context)
            {
                UpperLimit = Ofen.MaxTemp
            });

            tempSensors.ForEach(s => s.TempPt1.TimeConstant = 8000);

            exhaustHeat             = new OpcDataVariableNode <bool>(this, "AbwärmeOk", false);
            exhaustHeat.AccessLevel = OpcAccessLevel.CurrentRead;

            tempSensors.ForEach(s => RegisterComponent(s));
        }
Exemplo n.º 5
0
        internal IOpcNode AddNode(IOpcNode parentNode, params string[] path)
        {
            var context = this.SystemContext;

            foreach (var name in path)
            {
                var childNode = (OpcInstanceNode)parentNode.Child(context, name);

                if (childNode == null)
                {
                    if (name[0] == '.')
                    {
                        childNode = new OpcDataVariableNode <int>(parentNode, name, DateTime.Now.Millisecond);
                    }
                    else
                    {
                        childNode = new OpcFolderNode(parentNode, name);
                    }

                    this.AddNode(context, childNode);

                    if (childNode is OpcVariableNode)
                    {
                        return(childNode);
                    }
                }

                parentNode = childNode;
            }

            return(parentNode);
        }
        public MachineToolAlarmConditionNode()
            : base("MachineToolAlarmCondition")
        {
            this.alarmIdentifierNode = new OpcDataVariableNode <string>(this, "2:AlarmIdentifier");
            this.auxParametersNode   = new OpcDataVariableNode <string>(this, "2:AuxParameters");

            this.EventTypeId = "ns=2;i=1042";
        }
Exemplo n.º 7
0
 public OpcSimOperation(IOpcNode parent, OpcName name, OpcContext context) : base(parent, name, context)
 {
     _operationState = new OpcDataVariableNode <OperationState>(this, "State");
     _operationState.BeforeApplyChanges += _operationState_BeforeApplyChanges;
     _operationState.AccessLevel         = OpcAccessLevel.CurrentRead;
     _operationMode = new OpcDataVariableNode <OperationMode>(this, "Mode");
     _operationMode.BeforeApplyChanges += _operationMode_BeforeApplyChanges;
 }
Exemplo n.º 8
0
    public static void Main()
    {
        connectedClients = 0;
        List <OpcDataVariableNode> nodeList = new List <OpcDataVariableNode>();
        var temperatureNode    = new OpcDataVariableNode <double>("Temperature", 100.0);
        var messageNode        = new OpcDataVariableNode <string>("Message", string.Empty);
        var levelDetectionNode = new OpcDataVariableNode <bool>("Level", false);

        bool avslutt = false;

        nodeList.Add(levelDetectionNode);
        nodeList.Add(temperatureNode);
        nodeList.Add(messageNode);

        using (var server = new OpcServer("opc.tcp://localhost:4840/", nodeList))
        {
            server.Started += new EventHandler((sender, e) => ServerStarted(sender, e, nodeList, server));
            // server.RequestProcessing += new OpcRequestProcessingEventHandler((a, b) => reqProcessing(a,b));
            //server.RequestProcessed += new OpcRequestProcessedEventHandler((sender, e) => RequestProcessed(sender, e));
            server.SessionActivated += new OpcSessionEventHandler((sender, e) => SessionMethod(sender, e));
            server.SessionCreated   += new OpcSessionEventHandler((serr, rerrr) => sessionCreatedMethod(serr, rerrr));
            server.SessionClosing   += new OpcSessionEventHandler((sender, e) => SessionClosingMethod(sender, e));

            server.Start();

            while (true)
            {
                if (temperatureNode.Value == 110)
                {
                    temperatureNode.Value = 100;
                }
                else
                {
                    temperatureNode.Value++;
                }

                if (messageNode.Value.Length > 5)
                {
                    messageNode.Value = "e";
                }
                else
                {
                    messageNode.Value += 'a';
                }
                if (levelDetectionNode.Value == true)
                {
                    levelDetectionNode.Value = false;
                }
                else
                {
                    levelDetectionNode.Value = true;
                }


                Thread.Sleep(1000);
            }
        }
    }
Exemplo n.º 9
0
 public OpcSimComponent(IOpcNode parent, OpcName name, OpcContext context) : base(parent, name, context)
 {
     _warningActive = new OpcDataVariableNode <bool>(this, "WarnungAktiv");
     _errorActive   = new OpcDataVariableNode <bool>(this, "ErrorAktiv");
     _simError      = new OpcDataVariableNode <bool>(this, "SimStörung");
     _simError.BeforeApplyChanges += _simError_BeforeApplyChanges;
     _simWarning = new OpcDataVariableNode <bool>(this, "SimWarnung");
     _simWarning.BeforeApplyChanges += _simWarning_BeforeApplyChanges;
 }
Exemplo n.º 10
0
 private List <string> UpdateVariables()
 {
     try
     {
         HashSet <string> variableList = new HashSet <string>();
         _matlabService.Matlab.Execute(string.Format("{0} = who", MatlabService.VariablesTag));
         object vars;
         _matlabService.Matlab.GetWorkspaceData(MatlabService.VariablesTag, MatlabService.BaseTag, out vars);
         object[,] variables = vars as object[, ];
         if (variables != null)
         {
             for (int i = 0; i < variables.GetLength(0); i++)
             {
                 string variableName = variables[i, 0].ToString();
                 if (variableName != MatlabService.VariablesTag)
                 {
                     variableList.Add(variableName);
                     object variable = _matlabService.Matlab.GetVariable(variableName, MatlabService.BaseTag);
                     OpcDataVariableNode dataNode;
                     if (!_variableNodesIds.TryGetValue(variableName, out dataNode))
                     {
                         dataNode = new OpcDataVariableNode(_matlabFolder,
                                                            new OpcName(variableName), variable);
                         dataNode.WriteVariableValueCallback = WriteMatlabVariableValueCallback;
                         _variableNodesIds.Add(variableName, dataNode);
                         AddNode(dataNode);
                         Console.WriteLine("Added variable {0} : {1}", variableName, variable);
                     }
                     else if (!dataNode.Value.Equals(variable))
                     {
                         dataNode.Value = variable;
                         Console.WriteLine("Modified variable {0} : {1}", variableName, variable);
                     }
                     dataNode.DataType = OpcDataTypes.GetDataType(variable.GetType());
                 }
             }
             //Remove variables that no longer exists
             List <string> keys = _variableNodesIds.Keys.ToList();
             foreach (string key in keys)
             {
                 if (!variableList.Contains(key))
                 {
                     IOpcNode removeNode = _variableNodesIds[key];
                     this.RemoveNode(removeNode);
                     _variableNodesIds.Remove(key);
                     Console.WriteLine("Removed variable: {0}", key);
                 }
             }
         }
         return(variableList.ToList());
     }
     catch (Exception ex)
     {
         Console.WriteLine("Update variables error:{0}{1}{0}{2}", Environment.NewLine, ex.Message, ex.StackTrace);
         return(null);
     }
 }
Exemplo n.º 11
0
        public UAServer(string host)
        {
            //_nodeManager = new NodeManager();
            _temperatureNode = new OpcDataVariableNode <double>("Temperature", 100.0);

            _server = new OpcServer(host, _temperatureNode);
            _server.Start();

            Task task = Task.Factory.StartNew(TemperatureMaker);
        }
Exemplo n.º 12
0
 public TemperaturSensor(IOpcNode parent, OpcName name, OpcContext context) : base(parent, name, context)
 {
     _unit                   = new OpcDataVariableNode <string>(this, "Unit", "°C");
     _range                  = new OpcDataVariableNode <string>(this, "Range", "0..0");
     _maxValue               = new OpcDataVariableNode <double>(this, "MaxValue");
     _tempValue              = new OpcDataVariableNode <double>(this, "Value");
     _upperLimit             = new OpcDataVariableNode <double>(this, "UpperLimit", 100.0);
     _upperLimit.AccessLevel = OpcAccessLevel.CurrentRead;
     _overtemp               = new OpcDataVariableNode <bool>(this, "AlarmÜbertemperatur");
     CreatePT1();
 }
Exemplo n.º 13
0
        public Absackung(IOpcNode parent, OpcName name, OpcContext context) : base(parent, name, context)
        {
            Abfüllung = new Motor(this, "Abfüllung", context);

            _numberOfBags             = new OpcDataVariableNode <int>(this, "AnzahlSäcke", 0);
            _numberOfBags.AccessLevel = OpcAccessLevel.CurrentRead;
            _resetBags = new OpcDataVariableNode <bool>(this, "ResetAnzahl");
            _resetBags.BeforeApplyChanges += _resetBags_BeforeApplyChanges;

            RegisterComponent(Abfüllung);
        }
Exemplo n.º 14
0
        private static OpcFolderNode CreateDataNode()
        {
            var dataNode = new OpcFolderNode("Data");

            for (int index = 0; index < NumberOfNodes; index++)
            {
                dataNodes.Add(new OpcDataVariableNode <int>(dataNode, $"Var{index:00000}", value: index));
            }

            timestampNode = new OpcDataVariableNode <DateTime>(dataNode, "Timestamp");
            return(dataNode);
        }
Exemplo n.º 15
0
        public Drehrohrofen(IOpcNode parent, OpcName name, OpcContext context, Brennstoffzufuhr bsz) : base(parent, name, context)
        {
            Brennstoffzufuhr           = bsz;
            _heatOk                    = new OpcDataVariableNode <bool>(this, "TemperaturOk");
            _delayLengthMs             = new OpcDataVariableNode <int>(this, "SimDelayLength", 10000);
            _delayLengthMs.Description = "Simulierte Verzögerung von Einlauf zum Auslauf von Material";
            Brenner                    = new Brenner(this, "Brenner", Context);
            Motor           = new Motor(this, "Hauptmotor", Context);
            ValveWasteHeate = new Valve(this, "VentilAbwärme", Context);



            tempSensors.Add(new TemperaturSensor(this, "Temperatur_1,", Context)
            {
                UpperLimit = MaxTemp
            });
            tempSensors.Add(new TemperaturSensor(this, "Temperatur_2,", Context)
            {
                UpperLimit = MaxTemp
            });
            tempSensors.Add(new TemperaturSensor(this, "Temperatur_3,", Context)
            {
                UpperLimit = MaxTemp
            });
            tempSensors.Add(new TemperaturSensor(this, "Temperatur_4,", Context)
            {
                UpperLimit = MaxTemp
            });
            tempSensors.Add(new TemperaturSensor(this, "Temperatur_5,", Context)
            {
                UpperLimit = MaxTemp
            });
            tempSensors.Add(new TemperaturSensor(this, "Temperatur_4,", Context)
            {
                UpperLimit = MaxTemp
            });
            tempSensors.Add(new TemperaturSensor(this, "Temperatur_5,", Context)
            {
                UpperLimit = MaxTemp
            });

            tempSensors.ForEach(s => s.TempPt1.TimeConstant = 14000);

            RegisterComponent(Brenner);
            RegisterComponent(Motor);
            RegisterComponent(ValveWasteHeate);

            tempSensors.ForEach(s => RegisterComponent(s));
        }
Exemplo n.º 16
0
        public Valve(IOpcNode parent, OpcName name, OpcContext context) : base(parent, name, context)
        {
            _maxFlow = new OpcAnalogItemNode <double>(this, "MaxDurchfluss", 600.0);
            _maxFlow.BeforeApplyChanges += _maxFlow_BeforeApplyChanges;

            _flow = new OpcAnalogItemNode <double>(this, "Durchfluss");
            _flow.InstrumentRange      = new OpcValueRange(400.0, 0);
            _flow.EngineeringUnit      = new OpcEngineeringUnitInfo(4666675, "m3/min", "Kubikmeter pro Minute");
            _flow.EngineeringUnitRange = new OpcValueRange(400.0, 0);
            _flow.Description          = "Kubikmeter pro Minute";

            _open             = new OpcDataVariableNode <bool>(this, "Offen");
            _open.Description = "True = offen, False = zu";
            _movementAlarm    = new OpcDataVariableNode <bool>(this, "AlarmPosition");
            ManualControl     = new ManualControl(this, "Handbetrieb", Context);
        }
Exemplo n.º 17
0
        private static OpcFolderNode CreateDataNode()
        {
            var dataNode = new OpcFolderNode("Data");

            dataAvailableNode = new OpcDataVariableNode <bool>(dataNode, "DataAvailable");

            dataProcessedNode = new OpcDataVariableNode <bool>(dataNode, "DataProcessed");
            dataProcessedNode.WriteVariableValueCallback = WriteDataProcessed;

            for (int index = 0; index < NumberOfNodes; index++)
            {
                dataNodes.Add(new OpcDataVariableNode <int>(dataNode, $"Var{index:00000}", value: index));
            }

            timestampNode = new OpcDataVariableNode <DateTime>(dataNode, "Timestamp");
            return(dataNode);
        }
Exemplo n.º 18
0
        protected override IEnumerable <IOpcNode> CreateNodes(OpcNodeReferenceCollection references)
        {
            _matlabFolder = new OpcFolderNode(
                new OpcName(MatlabFolderName, this.DefaultNamespaceIndex));


            references.Add(_matlabFolder, OpcObjectTypes.ObjectsFolder);
            MyDeleagate del = UpdateVariables;

            new OpcMethodNode(_matlabFolder, GetVariablesMethod, del);
            var v = new OpcDataVariableNode <int>(_matlabFolder, new OpcName("GetVariablesVariable"), 0);//new OpcVariableNode(_matlabFolder,new OpcName("GetVariablesVariable"), 0);

            v.WriteVariableValueCallback = WriteVariableValueCallback;
            v.AccessLevel = OpcAccessLevel.CurrentReadOrWrite;
            Console.WriteLine();
            UpdateVariables();

            return(new IOpcNode[] { _matlabFolder });
        }
Exemplo n.º 19
0
        public Motor(IOpcNode parent, OpcName name, OpcContext context) : base(parent, name, context)
        {
            tempSensor = new TemperaturSensor(this, "Temperatur", context);
            tempSensor.AlarmEventChanged += TempSensor_AlarmEventChanged;
            tempSensor.UpperLimit         = 70.0;

            _speed       = new OpcDataVariableNode <double>(this, "Speed");
            _current     = new OpcDataVariableNode <double>(this, "Current");
            _power       = new OpcDataVariableNode <double>(this, "Power");
            _running     = new OpcDataVariableNode <bool>(this, "Running");
            _overcurrent = new OpcDataVariableNode <bool>(this, "AlarmÜberlast");

            ManualControl = new ManualControl(this, "Handbetrieb", Context);

            CreateSpeedPt1();
            PowerPt1   = new PT1_Floating(5000);
            CurrentPt1 = new PT1_Floating(12.5);
            CurrentPt1.TimeConstant = 200;
        }
Exemplo n.º 20
0
        public RohMaterialGewinnung(IOpcNode parent, OpcName name, OpcContext context) : base(parent, name, context)
        {
            _truckReadyToUnload             = new OpcDataVariableNode <bool>(this, "TruckBereitZumAbladen");
            _truckReadyToUnload.Description = "Truck is ready to unload.";
            _truckReadyToUnload.AccessLevel = OpcAccessLevel.CurrentRead;

            _unloadingActive             = new OpcDataVariableNode <bool>(this, "TruckAbladenAktiv");
            _unloadingActive.Description = "Truck is ready to unload.";
            _unloadingActive.AccessLevel = OpcAccessLevel.CurrentRead;

            _timeUnloading             = new OpcDataVariableNode <int>(this, "ZeitAbladen");
            _timeUnloading.Description = "Zeit des Abladevorgangs";

            _timeWaitTruck             = new OpcDataVariableNode <int>(this, "ZeitWartenAufTruck");
            _timeWaitTruck.Description = "Wartezeit nächster Truck";

            _simTruckIntervalMs   = new OpcDataVariableNode <int>(this, "Z_SimTruckIntervallMs", 10000);
            _simTruckLoadCapacity = new OpcDataVariableNode <double>(this, "Z_SimTruckKapazität", 10000.0);
            _simTruckUnloadTimeMs = new OpcDataVariableNode <int>(this, "Z_SimTruckAbladeZeitMs", 8000);
        }
Exemplo n.º 21
0
        public static void Main(string[] args)
        {
            var someNode = new OpcDataVariableNode <string>("Hello", value: "Hello World!");

            using (var server = new OpcServer("opc.tcp://localhost:4840/", someNode)) {
                var users = server.Security.UserNameAcl;

                // 1. Add the generic users to the UserName-ACL.
                users.AddEntry(OpcWindowsIdentity.Generic);
                users.AddEntry(OpcSubSystemIdentity.Generic);

                // 2. Activate the UserName-ACL (this inline disables anonymous access).
                users.IsEnabled = true;

                server.Start();

                Console.WriteLine("Server started - press any key to exit.");
                Console.ReadKey(true);
            }
        }
Exemplo n.º 22
0
        public static void Main(string[] args)
        {
            temperatureNode = new OpcDataVariableNode <double>("Temperature");
            speedNode       = new OpcDataVariableNode <int>("Speed");

            var machineNode = new OpcObjectNode(
                "Machine",
                temperatureNode,
                speedNode,
                new OpcActionMethodNode("StartMachine", StartMachine),
                new OpcActionMethodNode("StopMachine", StopMachine));

            using (var server = new OpcServer("opc.tcp://localhost:4840/", machineNode)) {
                server.Start();

                machineNode.AddNotifier(server.SystemContext, temperatureNode);
                machineNode.AddNotifier(server.SystemContext, speedNode);

                Console.WriteLine("Server started - press any key to exit.");
                Console.ReadKey(true);
            }
        }
Exemplo n.º 23
0
        public OpcSimModule(IOpcNode parent, OpcName name, OpcContext context) : base(parent, name, context)
        {
            _start             = new OpcDataVariableNode <bool>(this, "Start");
            _start.Description = "Eine steigende Flanke startet die Anlage.";

            _stop             = new OpcDataVariableNode <bool>(this, "Stop");
            _stop.Description = "Eine steigende Flanke stoppt die Anlage.";

            _warningPending             = new OpcDataVariableNode <bool>(this, "WarnungAktiv");
            _warningPending.Description = "Zeigt eine anstehende Warnung.";
            _warningPending.AccessLevel = OpcAccessLevel.CurrentRead;

            _acknowledge             = new OpcDataVariableNode <bool>(this, "Quittieren");
            _acknowledge.Description = "Eine steigende Flanke quittiert die Anlage.";

            _stop.BeforeApplyChanges        += _stop_BeforeApplyChanges;
            _start.BeforeApplyChanges       += _start_BeforeApplyChanges;
            _acknowledge.BeforeApplyChanges += _acknowledge_BeforeApplyChanges;

            _receiverReady             = new OpcDataVariableNode <bool>(this, "EmpfangenBereit");
            _receiverReady.AccessLevel = OpcAccessLevel.CurrentRead;
        }
Exemplo n.º 24
0
        public static void Main()
        {
            var temperatureNode = new OpcDataVariableNode <double>("Temperature", 100.0);

            using (var server = new OpcServer("opc.tcp://localhost:4840/", temperatureNode)) {
                server.Start();

                while (true)
                {
                    if (temperatureNode.Value == 110)
                    {
                        temperatureNode.Value = 100;
                    }
                    else
                    {
                        temperatureNode.Value++;
                    }

                    temperatureNode.ApplyChanges(server.SystemContext);
                    Thread.Sleep(1000);
                }
            }
        }
Exemplo n.º 25
0
        public static void Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                Console.WriteLine("Enter a valid ip address for the server (or localhost)");
                return;
            }
            string serverIP = args[0];

            #region 1st Way: Use the OpcServer class.
            {
                //// The OpcServer class interacts with one or more OPC UA clients using one of
                //// the registered base addresses of the server. While this class provides the
                //// different OPC UA services defined by OPC UA, it does not implement a main loop.

                //string serverURL = "https://localhost:4840/SampleServer";
                //string serverURL = "opc.tcp://localhost:4840/SampleServer";
                string serverURL       = $"opc.tcp://{serverIP}:4840/SampleServer";
                var    temperatureNode = new OpcDataVariableNode <double>("Temperature", 100.0);

                //using var server = new OpcServer(serverURL, temperatureNode);
                using var server = new OpcServer(serverURL, temperatureNode);
                server.Start();

                Console.WriteLine("Started the server at {0}", serverURL);

                while (true)
                {
                    if (temperatureNode.Value == 110)
                    {
                        temperatureNode.Value = 100;
                    }
                    else
                    {
                        temperatureNode.Value++;
                    }

                    temperatureNode.ApplyChanges(server.SystemContext);
                    Thread.Sleep(1000);
                }
            }
            #endregion

            #region 2nd Way: Use the OpcServerApplication class.
            {
                // The OpcServerApplication class uses a single OpcServer instance which is
                // wrapped within a main loop.
                //
                // Remarks
                // - The app instance does start a main loop when the server has been started.
                // - Custom startup code have to be implemented within the event handler of the
                //   Started event of the app instance.
                // new OpcServerApplication("opc.tcp://localhost:4840/SampleServer", new SampleNodeManager()).Run();
            }
            #endregion

            #region 3rd Way: Use the OpcServerServiceApplication class.
            {
                //// The OpcServerServiceApplication class uses a single OpcServer instance which is
                //// wrapped within a main loop when it is started with an interactive user or in
                //// debug mode. Otherwise it will start the process as a windows service which
                //// allows the application can be registered as a service process.
                ////
                //// Remarks
                //// - The app instance does start a main loop when the server has been started.
                //// - Custom startup code have to be implemented within the event handler of the
                ////   Started event of the app instance.
                //new OpcServerServiceApplication("opc.tcp://localhost:4840/SampleServer", new SampleNodeManager()).Run();
            }
            #endregion
        }
Exemplo n.º 26
0
 protected static void AddConfig(IOpcNode node)
 {
     _timeLapse         = new OpcDataVariableNode <TimeMultiplier>(node, "Zeitraffer");
     _clock             = new OpcDataVariableNode <int>(node, "Clock", 100);
     _clock.Description = "Clock in Millisekunden";
 }
Exemplo n.º 27
0
        /// <summary>
        /// Creates the nodes provided and associated with the node manager.
        /// </summary>
        /// <param name="references">A dictionary used to determine the logical references between
        /// existing nodes (e.g. OPC default nodes) and the nodes provided by the node
        /// manager.</param>
        /// <returns>An enumerable containing the root nodes of the node manager.</returns>
        /// <remarks>This method will be only called once by the server on start up.</remarks>
        protected override IEnumerable <IOpcNode> CreateNodes(OpcNodeReferenceCollection references)
        {
            // It is necessary to assign to all root nodes one of the namespaces used to
            // identify one of the associated namespaces (see the ctor of the class). This
            // namespace does identify the node as member of the namespace of the node
            // manager. Optionally it is possible to assign namespace to the child nodes
            // too. But by default their missing namespace will be auto-completed through the
            // namespace of their parent node.
            var machineOne = new OpcFolderNode(this.DefaultNamespace.GetName("Machine_1"));

            // In case a client requests a condition referesh it queries the current event
            // information which is gathered using the CreateEvent method from each active
            // and retained alarm nodes.
            machineOne.QueryEventsCallback = (context, events) => {
                // Ensure that an re-entrance upon notifier cross-references will not add
                // events to the collection which are already stored in.
                if (events.Count != 0)
                {
                    return;
                }

                if (this.statusChangeNode.IsRetained)
                {
                    events.Add(this.statusChangeNode.CreateEvent(context));
                }

                if (this.positionLimitNode.IsRetained)
                {
                    events.Add(this.positionLimitNode.CreateEvent(context));
                }

                if (this.temperatureCriticalNode.IsRetained)
                {
                    events.Add(this.temperatureCriticalNode.CreateEvent(context));
                }
            };

            // Add new reference to make the node visible beneath the ObjectsFolder
            // (the top most root node within every OPC UA server).
            references.Add(machineOne, OpcObjectTypes.ObjectsFolder);

            new OpcDataVariableNode <string>(machineOne, "Name", "Machine 1");
            this.isActiveNode = new OpcDataVariableNode <bool>(machineOne, "IsActive", true);

            //// An alarm node have to be a notifier for another node or for the whole server.
            //// Is a alarm a notifier of another node:
            //// -> this node (the notified one) needs to be subscribed by the client to receive
            ////    the alarm data.
            //// Is a alarm a notifier of the whole server:
            //// -> the OpcObjectTypes.Server needs to be subscribed by the client to receive
            ////    the alarm data.

            // Machine 1, Status nodes setup
            {
                this.statusNode = new OpcDataVariableNode <byte>(machineOne, "Status", 1);

                // Define an alarm used to request a dialog which requires a dedicated response
                // action by a client. This kind of node can be used for service / operator tasks.
                this.statusChangeNode = new OpcDialogConditionNode(machineOne, "StatusChange");
                this.statusChangeNode.AutoReportChanges = true;

                this.statusChangeNode.Message         = "Operator requested";
                this.statusChangeNode.Prompt          = "The job has been finished, continue with the next one?";
                this.statusChangeNode.ResponseOptions = new OpcText[] { "Yes", "No" };
                this.statusChangeNode.DefaultResponse = 0;
                this.statusChangeNode.CancelResponse  = 1;
                this.statusChangeNode.OkResponse      = 0;

                // Handle any client response on an active dialog through applying the response
                // using RespondDialog and configuring the dialog as inactive.
                this.statusChangeNode.RespondCallback = (context, response) => {
                    this.isActiveNode.Value = (response == this.statusChangeNode.OkResponse);
                    this.isActiveNode.ApplyChanges(context);

                    this.statusChangeNode.RespondDialog(context, response);

                    this.statusChangeNode.Message    = "No operator required";
                    this.statusChangeNode.IsRetained = false;

                    return(OpcStatusCode.Good);
                };

                // Define the alarm as the notifier of the machineOne node.
                machineOne.AddNotifier(this.SystemContext, this.statusChangeNode);
            }

            // Machine 1, Position nodes setup
            {
                this.positionNode = new OpcAnalogItemNode <int>(machineOne, "Position", -1);
                this.positionNode.InstrumentRange      = new OpcValueRange(low: 120, high: 1);
                this.positionNode.EngineeringUnit      = new OpcEngineeringUnitInfo(4732211, "mm", "millimetre");
                this.positionNode.EngineeringUnitRange = new OpcValueRange(byte.MaxValue);

                // Define an alarm used to indicate the reaching of one or more limits during
                // a progress. Such limits may be predefined or progress dependent.
                this.positionLimitNode = new OpcExclusiveLimitAlarmNode(
                    machineOne, "PositionLimit", OpcLimitAlarmStates.All);

                this.positionLimitNode.HighHighLimit = 120; // e.g. mm
                this.positionLimitNode.HighLimit     = 100; // e.g. mm
                this.positionLimitNode.LowLimit      = 5;   // e.g. mm
                this.positionLimitNode.LowLowLimit   = 1;   // e.g. mm

                this.positionLimitNode.Message     = "No range problems";
                this.positionLimitNode.ReceiveTime = DateTime.UtcNow;

                this.positionLimitNode.AcknowledgeCallback = (context, eventId, comment) => {
                    this.positionLimitNode.Message = "Acknowledged with " + comment;
                    return(OpcStatusCode.Good);
                };

                // Define the alarm as the notifier of the machineOne node.
                machineOne.AddNotifier(this.SystemContext, this.positionLimitNode);
            }

            // Machine 1, Temperature nodes setup
            {
                this.temperatureNode = new OpcAnalogItemNode <double>(machineOne, "Temperature", 18.3);
                this.temperatureNode.InstrumentRange      = new OpcValueRange(80.0, -40.0);
                this.temperatureNode.EngineeringUnit      = new OpcEngineeringUnitInfo(4408652, "°C", "degree Celsius");
                this.temperatureNode.EngineeringUnitRange = new OpcValueRange(70.8, 5.0);

                // Define an alarm which just indicates the fulfillment of an alarm associated
                // condition. Such simple alarms only notify about the fulfillment without to
                // define additional prerequisites defined by the alarm itself. Much more
                // specialized alarms are subclasses of this type of alarm node.
                this.temperatureCriticalNode = new OpcAlarmConditionNode(machineOne, "TemperatureCritical");

                // Define the alarm as the notifier of the machineOne node.
                machineOne.AddNotifier(this.SystemContext, this.temperatureCriticalNode);

                // Define the alarm as the notifier of the whole Server node.
                this.AddNotifierNode(this.temperatureCriticalNode);
            }

            return(new IOpcNode[] { machineOne });
        }
Exemplo n.º 28
0
 public Brenner(IOpcNode parent, OpcName name, OpcContext context) : base(parent, name, context)
 {
     _fuelMissing = new OpcDataVariableNode <bool>(this, "AlarmBrennstoffFehlt");
 }
Exemplo n.º 29
0
 public Brennstoffzufuhr(IOpcNode parent, OpcName name, OpcContext context) : base(parent, name, context)
 {
     _gasLevel  = new OpcDataVariableNode <int>(this, "GasVorrat", 35);
     _coleLevel = new OpcDataVariableNode <int>(this, "KohleVorrat", 75);
 }