Welcome to the new Schneider Electric Community

It's your place to connect with experts and peers, get continuous support, and share knowledge.

  • Explore the new navigation for even easier access to your community.
  • Bookmark and use our new, easy-to-remember address (community.se.com).
  • Get ready for more content and an improved experience.

Contact SchneiderCommunity.Support@se.com if you have any questions.

Close
Invite a Co-worker
Send a co-worker an invite to the Exchange portal.Just enter their email address and we’ll connect them to register. After joining, they will belong to the same company.
Send Invite Cancel
84248members
353348posts

how to connect to geoscada database from python

EcoStruxure Geo SCADA Expert Forum

Find out how SCADA systems and networks, like EcoStruxure Geo SCADA Expert, help industrial organizations maintaining efficiency, processing data for smarter decision making with IoT, RTU and PLC devices.

Solved
wexx
Crewman Crewman
Crewman
0 Likes
3
1324

how to connect to geoscada database from python

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!

 

 


Accepted Solutions
sbeadle
Janeway Janeway
Janeway
0
1303

Re: how to connect to geoscada database from python

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!

See Answer In Context

3 Replies 3
tfranklin
Lt. Commander
Lt. Commander
0 Likes
0
1317

Re: how to connect to geoscada database from python

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)
BevanWeiss
Spock
Spock
0 Likes
1
1309

Re: how to connect to geoscada database from python

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://tprojects.schneider-electric.com/telemetry/display/public/CS/Using+the+Automation+Interface+...

 


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..
sbeadle
Janeway Janeway
Janeway
0
1304

Re: how to connect to geoscada database from python

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!