/// <summary>
 /// Setup: do the all required intial Setup (setup the connection of Service Bus and Geo SCADA)
 /// </summary>
 static bool SetUpGeoSCADAConnection()
 {
     // The arguments here will specify your server by its IP address and port. These are the defaults for local use.
     ClearScada.Client.ServerNode node = new ClearScada.Client.ServerNode(ClearScada.Client.ConnectionType.Standard, GeoSCADAnode, GeoSCADAport);
     try
     {
         connection.Connect(node);
     }
     catch (CommunicationsException)
     {
         Console.WriteLine("Unable to communicate with Geo SCADA server.");
         return(false);
     }
     if (!connection.IsConnected)
     {
         Console.WriteLine("Not connected to Geo SCADA server.");
         return(false);
     }
     using (var spassword = new System.Security.SecureString())
     {
         foreach (var c in GeoSCADApass)
         {
             spassword.AppendChar(c);
         }
         try
         {
             connection.LogOn(GeoSCADAuser, spassword);
         }
         catch (AccessDeniedException)
         {
             Console.WriteLine("Access denied, incorrect user Id or password");
             return(false);
         }
         catch (PasswordExpiredException)
         {
             Console.WriteLine("Credentials expired.");
             return(false);
         }
     }
     return(true);
 }
Esempio n. 2
0
        // Alarm acknowledgement
        private bool TryAlarmAck(string UserId, string PIN, long Cookie, string Phone)
        {
            // Log on to the .Net Client API with these details
            // This requires a Reference from the project to this dll
            ClearScada.Client.Simple.Connection connection;
            var node = new ClearScada.Client.ServerNode(ClearScada.Client.ConnectionType.Standard, "127.0.0.1", 5481);

            ((DrvNotifyChannel)this.Channel).LogAndEvent("Acknowledge - connection created.");

            connection = new ClearScada.Client.Simple.Connection("Notify");
            try
            {
                ((DrvNotifyChannel)this.Channel).LogAndEvent("Acknowledge - connecting.");
                connection.Connect(node);
            }
            catch (CommunicationsException)
            {
                ((DrvNotifyChannel)this.Channel).LogAndEvent("Ack request - Unable to log in to ClearSCADA server using UserId and PIN.");
                return(false);
            }
            if (!connection.IsConnected)
            {
                ((DrvNotifyChannel)this.Channel).LogAndEvent("Acknowledge - failed connection.");
                return(false);
            }
            using (var spassword = new System.Security.SecureString())
            {
                foreach (var c in PIN)
                {
                    spassword.AppendChar(c);
                }
                try
                {
                    ((DrvNotifyChannel)this.Channel).LogAndEvent("Acknowledge - logging in.");
                    connection.LogOn(UserId, spassword);
                }
                catch (AccessDeniedException)
                {
                    ((DrvNotifyChannel)this.Channel).LogAndEvent("Ack request - Access denied, incorrect user Id or PIN.");
                    return(false);
                }
                catch (PasswordExpiredException)
                {
                    ((DrvNotifyChannel)this.Channel).LogAndEvent("Ack request - credentials expired.");
                    return(false);
                }
            }
            // Get root object
            ClearScada.Client.Simple.DBObject root = null;
            try
            {
                ((DrvNotifyChannel)this.Channel).LogAndEvent("Acknowledge - get database object.");
                root = connection.GetObject("$Root");
            }
            catch (Exception e)
            {
                ((DrvNotifyChannel)this.Channel).LogAndEvent("Ack request - Cannot get root object. " + e.Message);
                return(false);
            }
            object[] parameters = new object[2];
            parameters[0] = Cookie;
            parameters[1] = "By Phone";

            // Try acknowledging alarm
            try
            {
                ((DrvNotifyChannel)this.Channel).LogAndEvent("Acknowledge - accepting by cookie.");
                root.InvokeMethod("AcceptAlarmByCookie", parameters);
            }
            catch (Exception e)
            {
                ((DrvNotifyChannel)this.Channel).LogAndEvent("Ack request - Cannot acknowledge. " + e.Message);
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        static int Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Usage: SetInternalPoint \"username\" \"password\" \"Point-Name\" \"Value\" ");
                return(1);
            }
            string user      = args[0];
            string pass      = args[1];
            string pointname = args[2];
            string valuetext = args[3];
            double valuedouble;

            if (!double.TryParse(valuetext, out valuedouble))
            {
                Console.WriteLine("Value is not numeric");
                return(1);
            }

            ClearScada.Client.Simple.Connection connection;
            var node = new ClearScada.Client.ServerNode(ClearScada.Client.ConnectionType.Standard, "127.0.0.1", 5481);

            connection = new ClearScada.Client.Simple.Connection("Utility");
            try
            {
                connection.Connect(node);
            }
            catch (CommunicationsException)
            {
                Console.WriteLine("Unable to communicate with Geo SCADA server.");
                return(1);
            }
            if (!connection.IsConnected)
            {
                Console.WriteLine("Not connected to Geo SCADA server.");
                return(1);
            }
            using (var spassword = new System.Security.SecureString())
            {
                foreach (var c in pass)
                {
                    spassword.AppendChar(c);
                }
                try
                {
                    connection.LogOn(user, spassword);
                }
                catch (AccessDeniedException)
                {
                    Console.WriteLine("Access denied, incorrect user Id or password");
                    return(1);
                }
                catch (PasswordExpiredException)
                {
                    Console.WriteLine("Credentials expired.");
                    return(1);
                }
            }
            // Get point object
            ClearScada.Client.Simple.DBObject pointobject = null;
            try
            {
                pointobject = connection.GetObject(pointname);
            }
            catch (Exception e)
            {
                Console.WriteLine("Cannot get point object. " + e.Message);
                return(1);
            }
            // Set value
            try
            {
                object [] callparam = new object [1];
                callparam[0] = valuedouble;
                pointobject.InvokeMethod("CurrentValue", valuedouble);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error setting value. " + e.Message);
                return(1);
            }
            // Demo to read historic

            /*
             * var pointObject2 = connection.GetObject("Example Projects.Oil and Gas.Transportation.Inflow Computer.GasFlow");
             * DateTime hisStart = new DateTime(2021, 1, 19, 0, 0, 0);
             * DateTime hisEnd = new DateTime(2021, 1, 20, 0, 0, 0);
             * object[] hisArgs = { hisStart, hisEnd, 0, 1000, true, "All" };
             * var hisResult = pointObject2.InvokeMethod("Historic.RawValues", hisArgs);
             * Console.WriteLine(hisResult);
             * Console.ReadKey();
             */
            connection.Disconnect();
            return(0);
        }
Esempio n. 4
0
        async static Task Main(string[] args)
        {
            if (args.Length != 5)
            {
                Console.WriteLine("Usage: SetAndWatchInternalPoint \"username\" \"password\" \"Point-Name\" \"Value\" \"Watch-Point-Name\" ");
                return;
            }
            string user           = args[0];
            string pass           = args[1];
            string pointname      = args[2];
            string valuetext      = args[3];
            string watchpointname = args[4];
            double valuedouble;

            if (!double.TryParse(valuetext, out valuedouble))
            {
                Console.WriteLine("Value is not numeric");
                return;
            }

            ClearScada.Client.Simple.Connection connection;
            var node = new ClearScada.Client.ServerNode(ClearScada.Client.ConnectionType.Standard, "127.0.0.1", 5481);

            connection = new ClearScada.Client.Simple.Connection("Utility");
            IServer AdvConnection;

            try
            {
                connection.Connect(node);
                AdvConnection = node.Connect("Utility", false);
            }
            catch (CommunicationsException)
            {
                Console.WriteLine("Unable to communicate with Geo SCADA server.");
                return;
            }
            if (!connection.IsConnected)
            {
                Console.WriteLine("Not connected to Geo SCADA server.");
                return;
            }
            using (var spassword = new System.Security.SecureString())
            {
                foreach (var c in pass)
                {
                    spassword.AppendChar(c);
                }
                try
                {
                    connection.LogOn(user, spassword);
                    AdvConnection.LogOn(user, spassword);
                }
                catch (AccessDeniedException)
                {
                    Console.WriteLine("Access denied, incorrect user Id or password");
                    return;
                }
                catch (PasswordExpiredException)
                {
                    Console.WriteLine("Credentials expired.");
                    return;
                }
            }

            // Set event callback
            AdvConnection.TagsUpdated += TagUpdateEvent;

            // Disconnect Callback
            AdvConnection.StateChanged += DBStateChangeEvent;
            AdvConnection.AdviseStateChange();

            // Register for change for this point
            // ReadSeconds is the interval for the Server to watch for change. Be careful not to set this small
            int ReadSeconds = 10;

            try
            {
                int RegisterId = 1;                 // Use a unique number for each point waited for (not needed to be same as Object Id)
                // Registration is by point name, specify the field which has to change (could use CurrentTime to catch every change).
                AdvConnection.AddTags(new TagDetails(RegisterId, watchpointname + ".CurrentValue", new TimeSpan(0, 0, ReadSeconds)));
            }
            catch (ClearScada.Client.CommunicationsException)
            {
                Console.WriteLine("*** Comms exception (AddTags)");
                return;
            }

            // Get point object to be modified
            ClearScada.Client.Simple.DBObject pointobject = null;
            try
            {
                pointobject = connection.GetObject(pointname);
            }
            catch (Exception e)
            {
                Console.WriteLine("Cannot get point object. " + e.Message);
                return;
            }
            // Set value
            try
            {
                pointobject.InvokeMethod("CurrentValue", valuedouble);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error setting value. " + e.Message);
                return;
            }

            // Wait and watch for changes
            Console.WriteLine("Waiting for changes");
            while (WaitUntilStopped)
            {
                await Task.Delay(1000);
            }



            // Demo to read historic data

            /*
             * var pointObject2 = connection.GetObject("Example Projects.Oil and Gas.Transportation.Inflow Computer.GasFlow");
             * DateTime hisStart = new DateTime(2021, 1, 19, 0, 0, 0);
             * DateTime hisEnd = new DateTime(2021, 1, 20, 0, 0, 0);
             * object[] hisArgs = { hisStart, hisEnd, 0, 1000, true, "All" };
             * var hisResult = pointObject2.InvokeMethod("Historic.RawValues", hisArgs);
             * Console.WriteLine(hisResult);
             * Console.ReadKey();
             */
            connection.Disconnect();
            return;
        }
Esempio n. 5
0
        async static Task Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: EventWatcher \"username\" \"password\" ");
                return;
            }
            string user = args[0];
            string pass = args[1];

            ClearScada.Client.Simple.Connection connection;
            var node = new ClearScada.Client.ServerNode(ClearScada.Client.ConnectionType.Standard, "127.0.0.1", 5481);

            connection = new ClearScada.Client.Simple.Connection("Utility");
            IServer AdvConnection;

            try
            {
                connection.Connect(node);
                AdvConnection = node.Connect("Utility", false);
            }
            catch (CommunicationsException)
            {
                Console.WriteLine("Unable to communicate with Geo SCADA server.");
                return;
            }
            if (!connection.IsConnected)
            {
                Console.WriteLine("Not connected to Geo SCADA server.");
                return;
            }
            using (var spassword = new System.Security.SecureString())
            {
                foreach (var c in pass)
                {
                    spassword.AppendChar(c);
                }
                try
                {
                    connection.LogOn(user, spassword);
                    AdvConnection.LogOn(user, spassword);
                }
                catch (AccessDeniedException)
                {
                    Console.WriteLine("Access denied, incorrect user Id or password");
                    return;
                }
                catch (PasswordExpiredException)
                {
                    Console.WriteLine("Credentials expired.");
                    return;
                }
            }

            // Set event callback
            // subscriptionId is just a unique Id, we just use  a Guid (you can make many subscriptions if you want)
            var subscriptionId = Guid.NewGuid().ToString();

            // Filter string is the Server side Alarm Filter String that you can configure in ViewX
            var filter = "Categories=\"PointState;Security;Action\"";

            // OPCEventCategory allows you to request properties are sent along with events.
            // The CategoryId 0x208 identifies the EventCategory and comes from the Database.
            // The opcvalue is a an OPC property number from the schema
            ///OPCEventCategory category1 = new OPCEventCategory(0x208); // Analogue alarm
            ///category1.OPCAttributes.Add(OPCAttr1);
            ///category1.OPCAttributes.Add(OPCAttr2);
            ///List<OPCEventCategory> OPCCategories = new List<OPCEventCategory>();
            ///OPCCategories.Add(category1);
            // And add OPCCategories to the AddEventSubscription call below

            // Register the Event Handler
            AdvConnection.EventsUpdated += OnEventSubscriptionEvents;

            // Disconnect Callback
            AdvConnection.StateChanged += DBStateChangeEvent;
            AdvConnection.AdviseStateChange();


            // Subscribe to Events
            AdvConnection.AddEventSubscription(subscriptionId, filter);             ///, OPCCategories);

            // Wait and watch for changes
            Console.WriteLine("Waiting for changes");
            while (WaitUntilStopped)
            {
                await Task.Delay(1000);
            }

            connection.Disconnect();
            return;
        }
Esempio n. 6
0
        static void Main()
        {
            string user = "******";
            string pass = "******";

            ClearScada.Client.Simple.Connection connection;
            var node = new ClearScada.Client.ServerNode(ClearScada.Client.ConnectionType.Standard, "127.0.0.1", 5481);

            connection = new ClearScada.Client.Simple.Connection("Utility");
            connection.Connect(node);
            var spassword = new System.Security.SecureString();

            foreach (var c in pass)
            {
                spassword.AppendChar(c);
            }
            connection.LogOn(user, spassword);
            // Insert point name here
            ClearScada.Client.Simple.DBObject PointObj = connection.GetObject("New Analog Point");
            DateTime now = DateTime.UtcNow;

            // Add a value
            Object[] p1 = new Object[4];
            p1[0] = 1;
            p1[1] = 192;
            p1[2] = now;
            p1[3] = 1;
            PointObj.Aggregates["Historic"].InvokeMethod("LoadDataValue", p1);

            // Various calls to read values back
            Object[] p2 = new Object[5];
            p2[0] = now.AddSeconds(-1);
            p2[1] = now.AddSeconds(1);
            p2[2] = 0;
            p2[3] = true;
            p2[4] = "All";
            object r = PointObj.Aggregates["Historic"].InvokeMethod("RawValue", p2);

            Console.WriteLine(r);

            Object[] p3 = new Object[6];
            p3[0] = now.AddSeconds(-1);
            p3[1] = now.AddSeconds(1);
            p3[2] = 0;
            p3[3] = 1;
            p3[4] = true;
            p3[5] = "All";
            object [] k = (object [])PointObj.Aggregates["Historic"].InvokeMethod("RawValues", p3);
            Console.WriteLine(k[0]);

            Object[] p4 = new Object[6];
            p4[0] = now.AddSeconds(-1);
            p4[1] = "2S";
            p4[2] = 0;
            p4[3] = 1;
            p4[4] = true;
            p4[5] = "All";
            object[] q = (object[])PointObj.Aggregates["Historic"].InvokeMethod("RawValuesRange", p4);
            Console.WriteLine(q[0]);

            Console.ReadKey();
        }