EcoStruxure Geo SCADA Expert Forum
Schneider Electric support forum about installation, configuration, integration and troubleshooting of EcoStruxure Geo SCADA Expert (ClearSCADA, ViewX, WebX).
Posted: 2021-06-10 06:57 AM . Last Modified: 2023-05-03 12:03 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-10 06:57 AM . Last Modified: 2023-05-03 12:03 AM
Hi,
could you help me with the connection to Geoscada database from python?
I want to create a python script that can read and write values to variables inside the Geoscada database (local geoscada server). I think I can use python library pyodbc, but I cannot find documentation or guide on how to do it. Is it possible? if yes, how to do it? And if not, is there any solution how to manipulate DB from python (or from another language)??
Thank you very much!
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: 2021-06-11 12:29 AM
Hi,
The best way to connect is to use the pythonnet library to connect to the Geo SCADA .Net client.
This is (was when I last looked) available for python up to v3.8).
Example:
# Import .Net runtime support - needs "pip install pythonnet"
import clr
# Get Geo SCADA Library (could use the namespace if the dll is on PATH)
CS = clr.AddReference( "c:\Program Files\Schneider Electric\ClearSCADA\ClearSCADA.Client.dll" )
import ClearScada.Client as CSClient
# Create node and connect, then log in. (Could read net parameters from SYSTEMS.XML)
node = CSClient.ServerNode( CSClient.ConnectionType.Standard, "127.0.0.1", 5481 )
connection = CSClient.Simple.Connection( "Utility" )
connection.Connect( node )
connection.LogOn( "AdminExample", "AdminExample" )
# instance a template
P = connection.GetObject("Test") #parent
T = connection.GetObject("Test.Test Bulk Data.Ten Points") # A template
I = P.CreateInstance(T, "New Instance") # Create an instance
# set string point value
P = connection.GetObject("Test.New String Point") # A string point
P.InvokeMethod("CurrentValue", "fred" )
# get object children
FieldDevice = connection.GetObject("Test")
Children = FieldDevice.GetChildren("CDBPoint","")
for value in Children:
print(value.FullName)
# set an object's Geo Location
FieldDevice = connection.GetObject("SELogger.2820015789 DLLTE4-SA.Logger" )
GeoAgg = FieldDevice.Aggregates["GISLocationSource"];
print( GeoAgg.Enabled);
GeoAgg.ClassName = "CGISLocationSrcDynamic"
print( GeoAgg.ClassName);
GeoAgg["Latitude"] = 3
GeoAgg["Longitude"] = 4
# Find and set internal point values in history
pointObject = connection.GetObject("Example Projects.Oil and Gas.Transportation.Graphics.End Station.Valve 3.Position Control" )
for i in range(1,100,30):
pointObject.InvokeMethod("CurrentValue", i )
print( "Point set to: " + str(pointObject.GetProperty("CurrentValue" ) ) )
# Find a historic point
pointObject2 = connection.GetObject("Example Projects.Oil and Gas.Transportation.Inflow Computer.GasFlow" )
from System import DateTime # To support .Net date/time
# Historic arguments are start, end, index(=0), maxrecords, forwards=true, reason="All"
hisStart = DateTime( 2021,1,19,0,0,0 )
hisEnd = DateTime( 2021,1,20,0,0,0 )
hisArgs = [ hisStart, hisEnd, 0, 100, True, "All" ]
# Call methods to get values and times. Could also read quality, or use .ProcessedValue to get fixed interval data
hisValues = pointObject2.InvokeMethod("Historic.RawValues", hisArgs )
hisQualities = pointObject2.InvokeMethod("Historic.RawQualities", hisArgs )
hisTimeStamps = pointObject2.InvokeMethod("Historic.RawTimestamps", hisArgs )
for i in range( hisTimeStamps.Length):
print( hisTimeStamps[i], hisValues[i], hisQualities[i] )
Please mark as a solution!
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: 2021-06-10 10:15 AM
You're on the right track with accessing it via ODBC when using python. I've written a few things against it for extracting history and doing data frames and such in the past and it works really well. Below is a sample on how to connect, run a query, and iterate through it. This should be enough to get you started.
import pyodbc
#connect to the DSN
cnxn = pyodbc.connect('DSN=DSNNAMEHERE;UID=USERNAMEHERE;PWD=PASSWORDHERE')
cursor = cnxn.cursor()
#execute the query. the same approach would be used for writing updates to update values.
cursor.execute("SELECT TOP(10) Id,FullName FROM CDBPOINT ORDER BY FullName ASC")
#build the record set
points = cursor.fetchall()
#loop the recordset
for point in points:
#do something here
#data can be accessed as follows
pId = point.Id
pFullName = point.FullName
print(str(pId) + ';' + pFullName)
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: 2021-06-10 05:37 PM . Last Modified: 2023-04-25 03:19 AM
There is the ODBC way as mentioned previously... I haven't tried this from Python, but I'm sure there would be some way to use the OLE / COM interface also (possibly even the .NET interface.. assuming there is some Python library to deal with managed .NET APIs).
On the about to be moved TProjects space there is a collection of (short) documents around using the Automation Interface from various languages. Perl isn't Python of course... but they possibly have similar traps around threading model, and needing to go via OLE to obtain an object reference... so it might be helpful (or not)
https://community.se.com/t5/Geo-SCADA-Knowledge-Base/Resource-Center-Home/ba-p/279133
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: 2021-06-11 12:29 AM
Hi,
The best way to connect is to use the pythonnet library to connect to the Geo SCADA .Net client.
This is (was when I last looked) available for python up to v3.8).
Example:
# Import .Net runtime support - needs "pip install pythonnet"
import clr
# Get Geo SCADA Library (could use the namespace if the dll is on PATH)
CS = clr.AddReference( "c:\Program Files\Schneider Electric\ClearSCADA\ClearSCADA.Client.dll" )
import ClearScada.Client as CSClient
# Create node and connect, then log in. (Could read net parameters from SYSTEMS.XML)
node = CSClient.ServerNode( CSClient.ConnectionType.Standard, "127.0.0.1", 5481 )
connection = CSClient.Simple.Connection( "Utility" )
connection.Connect( node )
connection.LogOn( "AdminExample", "AdminExample" )
# instance a template
P = connection.GetObject("Test") #parent
T = connection.GetObject("Test.Test Bulk Data.Ten Points") # A template
I = P.CreateInstance(T, "New Instance") # Create an instance
# set string point value
P = connection.GetObject("Test.New String Point") # A string point
P.InvokeMethod("CurrentValue", "fred" )
# get object children
FieldDevice = connection.GetObject("Test")
Children = FieldDevice.GetChildren("CDBPoint","")
for value in Children:
print(value.FullName)
# set an object's Geo Location
FieldDevice = connection.GetObject("SELogger.2820015789 DLLTE4-SA.Logger" )
GeoAgg = FieldDevice.Aggregates["GISLocationSource"];
print( GeoAgg.Enabled);
GeoAgg.ClassName = "CGISLocationSrcDynamic"
print( GeoAgg.ClassName);
GeoAgg["Latitude"] = 3
GeoAgg["Longitude"] = 4
# Find and set internal point values in history
pointObject = connection.GetObject("Example Projects.Oil and Gas.Transportation.Graphics.End Station.Valve 3.Position Control" )
for i in range(1,100,30):
pointObject.InvokeMethod("CurrentValue", i )
print( "Point set to: " + str(pointObject.GetProperty("CurrentValue" ) ) )
# Find a historic point
pointObject2 = connection.GetObject("Example Projects.Oil and Gas.Transportation.Inflow Computer.GasFlow" )
from System import DateTime # To support .Net date/time
# Historic arguments are start, end, index(=0), maxrecords, forwards=true, reason="All"
hisStart = DateTime( 2021,1,19,0,0,0 )
hisEnd = DateTime( 2021,1,20,0,0,0 )
hisArgs = [ hisStart, hisEnd, 0, 100, True, "All" ]
# Call methods to get values and times. Could also read quality, or use .ProcessedValue to get fixed interval data
hisValues = pointObject2.InvokeMethod("Historic.RawValues", hisArgs )
hisQualities = pointObject2.InvokeMethod("Historic.RawQualities", hisArgs )
hisTimeStamps = pointObject2.InvokeMethod("Historic.RawTimestamps", hisArgs )
for i in range( hisTimeStamps.Length):
print( hisTimeStamps[i], hisValues[i], hisQualities[i] )
Please mark as a solution!
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: 2024-07-03 12:43 AM
I assume this solution will only work for a local GeoSCADA server? Or is there a way to adapt this for accessing a server that is not local?
Or should I use the pyodbc library for a non-local SQL database?
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: 2024-07-03 03:40 AM
You should be able to simply change the IP address from localhost to the IP address or name of the remote server in the following line:
node = CSClient.ServerNode( CSClient.ConnectionType.Standard, "127.0.0.1", 5481 )
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: 2024-07-03 08:47 PM
OK thanks @AndrewScott
The thought I had was that it wouldn't work because you need access to the .dll file which needs to be stored locally? I am trying to make this work on a machine which doesn't have GeoSCADA installed.
# Get Geo SCADA Library (could use the namespace if the dll is on PATH)
CS = clr.AddReference( "c:\Program Files\Schneider Electric\ClearSCADA\ClearSCADA.Client.dll" )
From what I can see the solution by @tfranklin wouldn't need to have GeoSCADA installed locally.
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: 2024-07-04 02:17 AM
@AarondV you will need to locally install the Geo SCADA data access components for either the .NET client API (using "pythonnet") or for ODBC (using "pyodbc"). For ODBC you'll also need to setup an ODBC data source name (DSN).
For details on installing the data access components, see Install Data Access Components on a Third-Party ODBC Client in the help.
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: 2024-10-29 03:47 PM
I copied the relevant DLLs locally and I'm able to connect to a remote machine running geo scada to perform some functions.
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.