I refer to the page of the below link and the comment at the bottom of the page;
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,
Solved! Go to Solution.
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,
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.
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.
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,
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;
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,
'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).
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();
}
}
}
Discuss challenges in energy and automation with 30,000+ experts and peers.
Find answers in 10,000+ support articles to help solve your product and business challenges.
Find peer based solutions to your questions. Provide answers for fellow community members!