Welcome to the new Schneider Electric Community

It's your place to connect with experts and peers, get continuous support, and share knowledge.

  • Explore the new navigation for even easier access to your community.
  • Bookmark and use our new, easy-to-remember address (community.se.com).
  • Get ready for more content and an improved experience.

Contact SchneiderCommunity.Support@se.com if you have any questions.

Close
Invite a Co-worker
Send a co-worker an invite to the Exchange portal.Just enter their email address and we’ll connect them to register. After joining, they will belong to the same company.
Send Invite Cancel
84649members
353989posts

Using the Automation Interface with C(sharp)

EcoStruxure Geo SCADA Expert Forum

Find out how SCADA systems and networks, like EcoStruxure Geo SCADA Expert, help industrial organizations maintaining efficiency, processing data for smarter decision making with IoT, RTU and PLC devices.

Solved
DavidSkilbeck
Lt. Commander
Lt. Commander
0 Likes
7
1631

Using the Automation Interface with C(sharp)

Hi,

I refer to the page of the below link and the comment at the bottom of the page;

 

https://tprojects.schneider-electric.com/telemetry/display/public/CS/Using+the+Automation+Interface+...

 

Anonymous says: Is reflection still need in .NET Framework version 4.x now that dynamic exists? ...

Is reflection still need in .NET Framework version 4.x now that dynamic exists?

From this line ScxV6DbClient.ScxV6Object O = S.FindObject( "New Analogue Point" );

what is S? How is it created/assigned? Mar 25th 2011

Thanks,


Accepted Solutions
DavidSkilbeck
Lt. Commander
Lt. Commander
0 Likes
3
1589

Re: Using the Automation Interface with C(sharp)

Hi Gents, I went over to VB and the code below works for me and I can change it further to fit my requirements.

 

Imports System
Imports Microsoft.SqlServer
Imports ScxV6DbClient

Module Program
Sub Main(args As String())

Dim Svr As ScxV6DbClient.ScxV6Server
Svr = New ScxV6DbClient.ScxV6Server
Svr.Connect("XXXXXXXXX", "XXXX", "XXXXXXXX")

Dim csObj As ScxV6Object
csObj = Svr.FindObject("New Analog Point")


Dim csAgg As ScxV6Aggregate
csAgg = csObj.Aggregate("Historic")
csAgg.Enable = True
csObj.Aggregate("Historic").Enable = True

End Sub
End Module

 

Thanks,

See Answer In Context

7 Replies 7
BevanWeiss
Spock
Spock
0 Likes
6
1628

Re: Using the Automation Interface with C(sharp)


Is reflection still need in .NET Framework version 4.x now that dynamic exists?

dynamic can dynamically 'cast' a type at runtime, and then allows for the methods / properties of this to be accessed (if they exist) at run time.  But in doing so it throws away all compile time checks related to the object.

So for the example given, it could likely be replaced with a dynamic reference.  Although I haven't tested this myself.

 

I would say that utilising static cast object and then invoking reflection only as needed is still probably my preferred way.  It provides improved 'type safety' early on, when writing the code, rather than relying on getting it right when it comes to runtime.

 

 


From this line ScxV6DbClient.ScxV6Object O = S.FindObject( "New Analogue Point" );

what is S? How is it created/assigned?


S is a reference to the ScxV6DbClient.ScxV6Server object.  It's the job of the reader to have already correctly defined this variable, and connected the connection etc etc.

 

 

Overall I would still recommend the .NET API in preference to the Automation Interface however.  It can be a little more annoying to get the initial system definition all worked out (having to manual load the Systems.xml file is annoying compared to just being able to enumerate an ScxV6System ala Automation Interface), but that becomes cookie cutter stuff after the first time, and accessing objects etc via .NET API is much nicer.


Lead Control Systems Engineer for Alliance Automation (VIC).
All opinions are my own and do not represent the opinions or policies of my employer, or of my cat..
sbeadle
Janeway Janeway
Janeway
0 Likes
5
1620

Re: Using the Automation Interface with C(sharp)

There is an example of using the .Net Client library here:

https://github.com/ClearSCADA/utility-examples

 

Perhaps you can share sample code for reading system names and getting valid connection parameters from the systems.xml?

 

Thanks.

 

DavidSkilbeck
Lt. Commander
Lt. Commander
0 Likes
3
1590

Re: Using the Automation Interface with C(sharp)

Hi Gents, I went over to VB and the code below works for me and I can change it further to fit my requirements.

 

Imports System
Imports Microsoft.SqlServer
Imports ScxV6DbClient

Module Program
Sub Main(args As String())

Dim Svr As ScxV6DbClient.ScxV6Server
Svr = New ScxV6DbClient.ScxV6Server
Svr.Connect("XXXXXXXXX", "XXXX", "XXXXXXXX")

Dim csObj As ScxV6Object
csObj = Svr.FindObject("New Analog Point")


Dim csAgg As ScxV6Aggregate
csAgg = csObj.Aggregate("Historic")
csAgg.Enable = True
csObj.Aggregate("Historic").Enable = True

End Sub
End Module

 

Thanks,

BevanWeiss
Spock
Spock
0 Likes
2
1584

Re: Using the Automation Interface with C(sharp)

Seriously?!?

You're marking your own post on Visual Basic as 'the solution' to how to use the Automation Interface with C#?

Your 'solution' didn't address your question on 'dynamic', or reflection, or what 'S' is.

 

And your VB example doesn't even deal with calling methods.

C# can trivially do all that your VB example does.  None of this is 'dynamic', or late bound invocation.

 

ScxV6Server Svr = new ScxV6DbClient.ScxV6Server();
Svr.Connect("XXXXXXXXX", "XXXX", "XXXXXXXX");

ScxV6Object csObj = Svr.FindObject("New Analog Point");

ScxV6Aggregate csAgg = csObj.Aggregate["Historic"];
csAgg.Enable = true;
csObj.Aggregate["Historic"].Enable = true;


Lead Control Systems Engineer for Alliance Automation (VIC).
All opinions are my own and do not represent the opinions or policies of my employer, or of my cat..
DavidSkilbeck
Lt. Commander
Lt. Commander
0 Likes
1
1578

Re: Using the Automation Interface with C(sharp)

Hi Bevan,

your code locks the enable option up. So it cannot be manually changed with GeoSCADA.

The point has to be deleted.

Have you missed something.

 

Thanks,

BevanWeiss
Spock
Spock
0 Likes
0
1575

Re: Using the Automation Interface with C(sharp)

'my' code is line for line equivalent to 'your' code, so it does everything that 'your' code does.

i.e. whilst run it sets the Historic Aggregate Enable flag (twice).


Lead Control Systems Engineer for Alliance Automation (VIC).
All opinions are my own and do not represent the opinions or policies of my employer, or of my cat..
BevanWeiss
Spock
Spock
0 Likes
0
1571

Re: Using the Automation Interface with C(sharp)

@sbeadle 

I don't have access to my cookie materials anymore, since I changed bakeries...

 

In all honesty I typically just grabbed the list of ServerNodes, and then in sequence tried to connect to them.  But the code below should be 'better' (but untested).

It would be really nice if the .NET API started to use some of the async stuff.

It would be nice if we could just await a connection once we setup the System Monitor.

If some async stuff was pushed into the .NET API, it would probably help to improve some of the performance issues I've seen with ViewX when not all nodes are available.

Really, so much of ViewX operation should be aync. 

    class Program
    {
        private static ClearScada.Client.Advanced.IServer server;
        private static EventWaitHandle waiter;


        static void Main(string[] args)
        {
            ServerSystemCollection systems;
            NetworkCredential credentials;

            using (XmlReader reader = XmlReader.Create(
                Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                    "Schneider Electric",
                    "ClearSCADA",
                    "Systems.xml")))
            {
                systems = new ServerSystemCollection(reader);
            }

            ServerSystem system = systems["TestSystem"];
            ServerSystemMonitor monitor = new ServerSystemMonitor(system);
            // obviously don't look at the password below... it's definitely secure.  Ideally this should never
            // be stored in this way, it should be parsed directly into a SecureString and stored that way forever
            credentials = new NetworkCredential("TestUser", "TestPassword");
            monitor.SetProvisionalLogOnCredentials(credentials.UserName, credentials.SecurePassword);
            monitor.PreferredNodeChanged += Monitor_PreferredNodeChanged;
            monitor.Start(false);

            waiter = new EventWaitHandle(false, EventResetMode.ManualReset);

            // we'll just go away and do some other stuff until we're told that a preferred node is available
            // we should probably do something if we get bored of waiting here...
            waiter.WaitOne(Timeout.Infinite);

            // I think we need to log on again
            server.LogOn(credentials.UserName, credentials.SecurePassword);

            // and then we can create the objects we care so much about
            server.CreateObject("CDBPoint", ObjectId.Root, "Cat");

        }

        private static void Monitor_PreferredNodeChanged(object sender, ServerNodeEventArgs e)
        {
            if(e.State.State == ServerState.Main || e.State.State == ServerState.Standby)
            {
                server = e.Node.Connect("TestApp", false);
                waiter.Set();
            }
        }
    }

 


Lead Control Systems Engineer for Alliance Automation (VIC).
All opinions are my own and do not represent the opinions or policies of my employer, or of my cat..