EcoStruxure Geo SCADA Expert Forum
Schneider Electric support forum about installation, configuration, integration and troubleshooting of EcoStruxure Geo SCADA Expert (ClearSCADA, ViewX, WebX).
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
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.
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();
Link copied. Please paste this link to share this article on your social media post.
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();
Link copied. Please paste this link to share this article on your social media post.
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
Link copied. Please paste this link to share this article on your social media post.
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..
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.