pi_web_api_cs_helper.PIWebAPIClient.GetTagValueAsync C# (CSharp) Méthode

GetTagValueAsync() public méthode

Get the value of a particular PI tag.
public GetTagValueAsync ( string serverWebId, string tagName ) : Task
serverWebId string WebId of the PI Data Archive.
tagName string Name of the PI tag.
Résultat Task
        public async Task<dynamic> GetTagValueAsync(string serverWebId, string tagName)
        {
            string url = await GetTagValueLink(serverWebId, tagName);
            dynamic result = await GetAsync(url);
            return result.Value;
        }

Usage Example

        static void Main(string[] args)
        {
            Console.Write("Enter username: "******"Enter password: "******"Getting list of PI Data Archives...");
                Dictionary<string, string> serversWebId = client.GetDataServersWebIdAsync().Result;
                foreach (var server in serversWebId)
                {
                    Console.WriteLine(server.Key);
                }
                do
                {
                    Console.Write("Please type in name of the PI Data Archive: ");
                    string myPI = Console.ReadLine();
                    Console.Write("Please type in name of the tag: ");
                    string myTag = Console.ReadLine();

                    if (IsRead())
                    {
                        dynamic value = client.GetTagValueAsync(serversWebId[myPI], myTag).Result;
                        Console.WriteLine("Current value = {0}", value);
                    }
                    else
                    {
                        Console.Write("Value to write? ");
                        string valueToWrite = Console.ReadLine();
                        client.WriteTagValueAsync(serversWebId[myPI], myTag, valueToWrite).Wait();
                        Console.WriteLine("Value written.");
                    }
                    Console.WriteLine("Press any key to continue (esc to exit)...");
                } while (Console.ReadKey().Key != ConsoleKey.Escape);
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (KeyNotFoundException)
            {
                Console.WriteLine("The specified PI Data Archive cannot be found.");
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    Console.WriteLine(e.Message);
                }
            }
            finally
            {
                client.Dispose();
                Console.ReadKey();
            }
        }