Dynamically accessing PI with .NET 4.0

Discussion created by MichaelvdV@Atos on Mar 1, 2010
Latest reply on May 17, 2010 by cescamilla

I started to play around with the DynamicObject class in .NET 4.0.


I have the tendancy to explore new technologies with PI. So, my goal was to create a 'dynamic PISDK' (the term 'SDK' should be taken lightly, because the implementation is very limited).


If you want to have some sense to how this works: the project is attached to this post (VS 2010 beta 2, .NET 4.0 beta). warning: For programmers not use to dynamic typed languages this can seem very strange and non-intuitive/unusable.


Here is an example on how to use it:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DPISDK
    class Program
        static void Main(string[] args)
            //Note: nlms025 is my local pi server. Change it to your PI servername.

            //Creating the dynamic SDK
            dynamic dpisdk = new DPISDK.CORE.DPISDK();
            //Accessing the tag 'sinusoid' on Pi server 'nlms025', and getting the 'snapshot' member.
            var snap = dpisdk.nlms025.sinusoid.Snapshot;
            //This returns a dynamic object called 'DPiValue', which contains the value, timestamp and isgood. It also overrides the ToString() to
            //print the formatted values
            Console.WriteLine("Snapshot: " + snap);
            //Accessing the tag 'sinusoidu' on Pi Server 'nlms025', and calling a dynamic function 'recordedvalues'.
            var values = dpisdk.nlms025.sinusoidu.recordedvalues("*", "*-2h");
            //This returns a List<DPiValue>. Print the list using the overridden ToString() method
            foreach (DPiValue value in values)

            //Accessing the tag 'sinusoid' on Pi Server 'nlms025', getting the 'descriptor' point attribute. Please note that getting a descriptor and
            //the snapshot (property) is on the same level. Please view the implementation of DPiPoint's TryGetMember to get a better sense of what's happening.

            //We want to see the results in Console, so wait for the enter key to exit