- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-06-28 10:27 PM . Last Modified: 2023-05-03 12:13 AM
.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.
Link copied. Please paste this link to share this article on your social media post.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-06-29 02:51 AM
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:
- english
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-06-29 02:51 AM
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:
- english
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-06-29 02:58 AM
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:
- english
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-06-29 08:42 PM
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:
- english
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2025-02-26 07:26 PM . Last Modified: 2025-02-26 07:29 PM
For anyone stumbling upon this in 2025, below is the same code (mostly!) as Steve's for Geo SCADA 2023 and PowerShell 5.1 (removed a load of exception handling to simplify things a little)
Link copied. Please paste this link to share this article on your social media post.

