41355members
184437posts

Getting historic data via .NET client API

Highlighted

Getting historic data via .NET client API

Has anyone here tried getting historic data out of ClearSCADA using the .NET client API?

 

I've tried calling "historicAggregate.InvokeMethod("RawValuesRange", args)" and  "historicAggregate.InvokeMethod("RawValues", args)", but both are returning the exception "ClearScada.Client.MethodException: 'Failed to execute method 'Historic.RawValuesRange': Not implemented"

 

4 REPLIES 4
Highlighted
Lieutenant

Re: Getting historic ata via .NET client API

I've not done it and couldn't find an example, but I did find a suggestion that it might be easier to to via ODBC (System.Data.Odbc.OdbcConnection).

Highlighted
Sisko

Re: Getting historic ata via .NET client API

Here's an example. Other ways of declaring and using parameters are possible. This uses an array declaration to receive the results.

 

Jesse - using ODBC will be similar performance, maybe a shade slower as the query has to be interpreted. You'd also need a connection string/details in addition to what your code might be doing elsewhere.

 

There's also an SQL interface in the C# library, so to use the client object functions as well as sql statements in the same connection is possible. If someone asks a separate question about that I may post an example!

 

using System;
using ClearScada.Client;            // This requires a Reference from the project to this dll
using System.Security;

namespace InsertHistoricData
{
	class Program
	{
		static void Main()
		{
			string user = "s";
			string pass = "s";

			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);
			ClearScada.Client.Simple.DBObject PointObj = connection.GetObject("Test General.Test His Insert and Load.New Analog Point");
			DateTime now = DateTime.UtcNow;

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


			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]);

			Console.ReadKey();
		}
	}
}

 

Highlighted
Sisko

Re: Getting historic ata via .NET client API

And to use the ...Range methods, you need a time offset string:

			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]);
Highlighted

Re: Getting historic ata via .NET client API

This worked for me. Thank you.