Example #1
0
        private HistoryReadValuesTests <EndpointModel> GetTests()
        {
            var codec = new JsonVariantEncoder();

            return(new HistoryReadValuesTests <EndpointModel>(
                       () => new HistoricAccessAdapter <EndpointModel>(new AddressSpaceServices(_server.Client,
                                                                                                codec, _server.Logger), codec, _server.Logger),
                       new EndpointModel {
                Url = $"opc.tcp://{Dns.GetHostName()}:{_server.Port}/UA/SampleServer"
            }));
        }
        /// <summary>
        /// Read value
        /// </summary>
        /// <param name="client"></param>
        /// <param name="endpoint"></param>
        /// <param name="elevation"></param>
        /// <param name="readNode"></param>
        /// <returns></returns>
        public static Task <JToken> ReadValueAsync(this IEndpointServices client,
                                                   EndpointModel endpoint, CredentialModel elevation, string readNode)
        {
            var codec = new JsonVariantEncoder();

            return(client.ExecuteServiceAsync(endpoint, elevation, session => {
                var nodesToRead = new ReadValueIdCollection {
                    new ReadValueId {
                        NodeId = readNode.ToNodeId(session.MessageContext),
                        AttributeId = Attributes.Value
                    }
                };
                var responseHeader = session.Read(null, 0, TimestampsToReturn.Both,
                                                  nodesToRead, out var values, out var diagnosticInfos);
                var result = codec.Encode(values[0].WrappedValue,
                                          out var tmp, session.MessageContext);
                return Task.FromResult(result);
            }));