42270members
186184posts

.NET API to query ClearSCADA View

Highlighted
Cadet

.NET API to query ClearSCADA View

Hello! I need to replicate some logic in ClearSCADA code in .NET. The scada code selects values from a View and does some processing.


Does anyone know what API calls can query the View and get its data? Thanks a lot.

3 REPLIES 3
Highlighted
Sisko

Re: .NET API to query ClearSCADA View

What do you mean by a View - a SQL query?

 

An SQL query can be made on the .Net API using the Advanced connection type.

 

// Non-working code as an example:
                var node = new ClearScada.Client.ServerNode(ClearScada.Client.ConnectionType.Standard, "127.0.0.1", 5481);

                AdvConnection = node.Connect("mytest", false); // New type argument
                using (var spassword = new System.Security.SecureString())
                {
                    foreach (var c in password)
                    {
                        spassword.AppendChar(c);
                    }

                    AdvConnection.LogOn(user, spassword);
                }
// Fix indenting!
			Int32 result = 0;
                        String sql = "select id from cgroup"
			// Find the database reference of the thing
			ClearScada.Client.Advanced.IQuery serverQuery = AdvConnection.PrepareQuery(sql, new ClearScada.Client.Advanced.QueryParseParameters());
			ClearScada.Client.Advanced.QueryResult queryResult = serverQuery.ExecuteSync(new ClearScada.Client.Advanced.QueryExecuteParameters());

			if (queryResult.Status == ClearScada.Client.Advanced.QueryStatus.Succeeded || queryResult.Status == ClearScada.Client.Advanced.QueryStatus.NoDataFound)
			{
				if (queryResult.Rows.Count > 0)
				{
					// Found
					IEnumerator<ClearScada.Client.Advanced.QueryRow> e = queryResult.Rows.GetEnumerator();
					while (e.MoveNext())
					{
						result = (Int32)e.Current.Data[0];
					}
				}
			}
			serverQuery.Dispose();
Tags (1)
Highlighted
Cadet

Re: .NET API to query ClearSCADA View

Hi sbeadle,

 

Thanks heaps for answering my question.

 

I tried your solution and it works! The view in my question refers to the Historic Views defined in Historic Configuration.

 

Thank you again and have a nice day!

 

Kan

Tags (1)
Highlighted
Commander

Re: .NET API to query ClearSCADA View

Hey Steve,

 

That's quite some old style enumerator iteration there

while (e.MoveNext())
					{
						result = (Int32)e.Current.Data[0];
					}

 

You're not a fan of the 'foreach'?

There's really so much more power in the .NET stuff around this, like doing processing in parallel..


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..
Tags (1)