2014-12-01 10:34:45 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using IEC61850.Common;
|
|
|
|
using IEC61850.Client;
|
2014-12-01 10:47:22 +01:00
|
|
|
using System.Threading;
|
2014-12-01 10:34:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace control
|
|
|
|
{
|
|
|
|
class ControlExample
|
|
|
|
{
|
2014-12-01 10:47:22 +01:00
|
|
|
private static void commandTerminationHandler (Object parameter, ControlObject control)
|
|
|
|
{
|
|
|
|
LastApplError lastApplError = control.GetLastApplError();
|
|
|
|
Console.WriteLine("HANDLER CALLED! " + lastApplError.addCause);
|
|
|
|
}
|
|
|
|
|
2014-12-01 10:34:45 +01:00
|
|
|
public static void Main (string[] args)
|
|
|
|
{
|
|
|
|
IedConnection con = new IedConnection ();
|
|
|
|
|
|
|
|
string hostname;
|
|
|
|
|
|
|
|
if (args.Length > 0)
|
|
|
|
hostname = args[0];
|
|
|
|
else
|
|
|
|
hostname = "localhost";
|
|
|
|
|
|
|
|
Console.WriteLine("Connect to " + hostname);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
con.Connect(hostname, 102);
|
|
|
|
|
2015-06-03 16:24:43 +02:00
|
|
|
/* direct control with normal security or SBO with normal security */
|
2014-12-01 10:47:22 +01:00
|
|
|
string objectReference = "simpleIOGenericIO/GGIO1.SPCSO1";
|
2014-12-01 10:34:45 +01:00
|
|
|
|
|
|
|
ControlObject control = con.CreateControlObject(objectReference);
|
|
|
|
|
|
|
|
ControlModel controlModel = control.GetControlModel();
|
|
|
|
|
|
|
|
Console.WriteLine(objectReference + " has control model " + controlModel.ToString());
|
|
|
|
|
2014-12-01 10:47:22 +01:00
|
|
|
|
2015-06-03 16:24:43 +02:00
|
|
|
switch (controlModel) {
|
|
|
|
|
|
|
|
case ControlModel.STATUS_ONLY:
|
|
|
|
Console.WriteLine("Control is status-only!");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ControlModel.DIRECT_NORMAL:
|
|
|
|
case ControlModel.DIRECT_ENHANCED:
|
|
|
|
if (!control.Operate(true))
|
|
|
|
Console.WriteLine("operate failed!");
|
|
|
|
else
|
|
|
|
Console.WriteLine("operated successfully!");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ControlModel.SBO_NORMAL:
|
|
|
|
case ControlModel.SBO_ENHANCED:
|
|
|
|
|
|
|
|
if (control.Select()) {
|
|
|
|
if (!control.Operate(true))
|
|
|
|
Console.WriteLine("operate failed!");
|
|
|
|
else
|
|
|
|
Console.WriteLine("operated successfully!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Console.WriteLine("Select failed!");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2014-12-01 10:34:45 +01:00
|
|
|
|
2014-12-01 10:47:22 +01:00
|
|
|
/* direct control with enhanced security */
|
|
|
|
objectReference = "simpleIOGenericIO/GGIO1.SPCSO3";
|
|
|
|
control = con.CreateControlObject(objectReference);
|
|
|
|
|
|
|
|
controlModel = control.GetControlModel();
|
|
|
|
Console.WriteLine(objectReference + " has control model " + controlModel.ToString());
|
|
|
|
|
2015-04-21 09:28:48 +02:00
|
|
|
if (controlModel == ControlModel.DIRECT_ENHANCED) {
|
2014-12-01 10:47:22 +01:00
|
|
|
control.SetCommandTerminationHandler(commandTerminationHandler, null);
|
|
|
|
|
|
|
|
control.Operate(true);
|
|
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
}
|
|
|
|
|
2017-10-28 15:52:49 +02:00
|
|
|
// has to be called before IedConnection dispose method!
|
|
|
|
control.Dispose();
|
|
|
|
|
|
|
|
con.Abort();
|
2014-12-01 10:34:45 +01:00
|
|
|
}
|
|
|
|
catch (IedConnectionException e)
|
|
|
|
{
|
|
|
|
Console.WriteLine(e.Message);
|
2015-10-27 17:13:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// release all resources - do NOT use the object after this call!!
|
|
|
|
con.Dispose ();
|
2014-12-01 10:34:45 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|