Exemple #1
0
        public Variant ReadVariable(RemoteVariable remoteVariable)
        {
            if (string.IsNullOrWhiteSpace(remoteVariable.Name))
            {
                throw new Exception("Method name is empty!");
            }

            if (_parentNode == null)
            {
                throw new Exception($"Parent node is null for method '{remoteVariable.Name}'!");
            }

            var readValue = new ReadValueId
            {
                NodeId      = BrowseNodeId(_parentNode, remoteVariable.Name),
                AttributeId = Attributes.Value
            };

            var result = _session.Read(new List <ReadValueId> {
                readValue
            }, 0, TimestampsToReturn.Both,
                                       new RequestSettings {
                OperationTimeout = 10000
            });

            if (result == null || result.Count < 1)
            {
                throw new Exception($"Cannot read UA Variable {_parentNode.Identifier}.{remoteVariable.Name} on server.");
            }

            return(result[0].WrappedValue);
        }
Exemple #2
0
        public void Write(string name, object parameter)
        {
            try
            {
                var variable = new RemoteVariable
                {
                    Name  = name,
                    Value = TypeMapping.ToVariant(parameter)
                };

                variable.Write(this);
            }
            catch (Exception e)
            {
                ExceptionHandler.Log(e, $"Cannot write {Name}.{name} without errors!");
            }
        }
Exemple #3
0
        public T Read <T>(string name)
        {
            try
            {
                var variable = new RemoteVariable
                {
                    Name  = name,
                    Value = TypeMapping.MapType <T>()
                };

                var result = variable.Read(this);
                return((T)TypeMapping.ToObject(result));
            }
            catch (Exception e)
            {
                ExceptionHandler.Log(e, $"Cannot read {Name}.{name} without errors!");
            }

            return((T)TypeMapping.ToObject(TypeMapping.MapType <T>()));
        }
Exemple #4
0
        public Variant WriteVariable(RemoteVariable remoteVariable)
        {
            if (string.IsNullOrWhiteSpace(remoteVariable.Name))
            {
                throw new Exception("Method name is empty!");
            }

            if (_parentNode == null)
            {
                throw new Exception($"Parent node is null for method '{remoteVariable.Name}'!");
            }

            var writeValue = new WriteValue
            {
                NodeId      = BrowseNodeId(_parentNode, remoteVariable.Name),
                AttributeId = Attributes.Value,
                Value       = new DataValue()
                {
                    WrappedValue = remoteVariable.Value
                }
            };

            var result = _session.Write(new List <WriteValue> {
                writeValue
            },
                                        new RequestSettings {
                OperationTimeout = 10000
            });

            if (result == null || result.Count < 1 || result[0] != StatusCodes.Good)
            {
                throw new Exception(
                          $"Cannot write UA Variable {_parentNode.Identifier}.{remoteVariable.Name} on server.");
            }

            return(remoteVariable.Value);
        }