-
-
Save paladini/08d2824f5692893157a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env/bin python | |
""" Tests the ScadaBR API through Python. | |
Based on: http://www.scadabr.com.br/?q=node/443 | |
""" | |
from suds.client import Client | |
from suds.sax.element import Element | |
import datetime | |
dateStart = datetime.datetime.now() | |
# Authentication process | |
client = Client('http://localhost:8080/ScadaBR/services/API?wsdl') | |
# token = client.service.doLogin('admin', '12a06-fs') | |
# print(token) | |
auth = Element('authentication', ns=['api','http://auth.api.scadabr.org.br']) | |
auth.set("mustUnderstand", False) | |
user = Element('username').setText('admin') | |
auth.append(user) | |
passwd = Element('password').setText('******') | |
auth.append(passwd) | |
client.set_options(soapheaders=auth) | |
print '######################################' | |
print 'describing the service:' | |
print client | |
print '######################################' | |
#types are created as follows: | |
browseTagsOptions = client.factory.create('ns3:BrowseTagsOptions') | |
#note the type | |
print 'BrowseTagsOptions' | |
print browseTagsOptions | |
#set BrowseTagsParams | |
browseTagsOptions.maxReturn = 2 | |
itemsPath = 'counterProduct' | |
#calling browseTags(xs:string itemsPath, ns3:BrowseTagsOptions options, ) | |
BrowseTagsResponse = client.service.browseTags(itemsPath,browseTagsOptions) | |
print 'browse tag counterProduct' | |
print BrowseTagsResponse | |
#all tags | |
print 'ALL TAGS' | |
print client.service.browseTags() | |
print '######################################' | |
#browseEventsParams = client.factory.create('tns6:BrowseEventsParams') | |
getStatusResponse = client.factory.create('tns4:GetStatusResponse') | |
#browseEventsParams.options.eventType = True | |
#browseEventsParams.options.returnEventsConfig = True | |
getStatusResponse = client.service.getStatus() | |
print 'status' | |
print getStatusResponse | |
print '######################################' | |
#calling readData (xs:string[] itemPathList, ns3:ReadDataOptions options, )' | |
#create and set the parameters: | |
itemPathList = ['counterProduct','operatorID'] | |
readDataOptions = client.factory.create('ns3:ReadDataOptions') | |
readDataOptions.maxReturn = 3 | |
readDataResponse = client.service.readData(itemPathList , readDataOptions ) | |
print 'reading tags: counterProduct , operatorID' | |
print readDataResponse | |
print 'reading the tag: counterProduct' | |
print readDataResponse.itemsList[0] | |
print 'reading only the value of tag: counterProduct' | |
print readDataResponse.itemsList[0].value | |
print '######################################' | |
#calling writeStringData(ns5:ItemStringValue[] itemsList, ns3:WriteDataOptions options, ) | |
#create and set the parameters: | |
# writeDataOptions = client.factory.create('ns3:WriteDataOptions') | |
# writeDataOptions.returnItemValues = True | |
# itemStringList= client.factory.create('ns5:ItemStringValue') | |
# dataType = client.factory.create('ns2:DataType') | |
# quality = client.factory.create('ns2:QualityCode') | |
# itemStringList.itemName = 'counterProduct' | |
# itemStringList.dataType = dataType.FLOAT | |
# itemStringList.value = 23.5 | |
# itemStringList.quality =quality.GOOD | |
# itemStringList.timestamp = datetime.datetime.now() | |
# writeStringDataResponse=client.service.writeStringData(itemStringList,writeDataOptions ) | |
# print 'writing on the tag counterProduct' | |
# print writeStringDataResponse | |
# print '######################################' | |
#calling getDataHistory(xs:string itemName, ns4:GetDataHistoryOptions options, ) | |
#create and set the parameters: | |
# getDataHistoryOptions = client.factory.create('ns4:GetDataHistoryOptions') | |
# print getDataHistoryOptions | |
# itemName = 'counterProduct' | |
# getDataHistoryOptions .maxReturn = 10 | |
# getDataHistoryOptions .initialDate = dateStart | |
# itemStringList.value = 28.0 | |
# client.service.writeStringData(itemStringList,writeDataOptions ) | |
# itemStringList.value = 29.0 | |
# client.service.writeStringData(itemStringList,writeDataOptions ) | |
# itemStringList.value = 30.0 | |
# client.service.writeStringData(itemStringList,writeDataOptions ) | |
# itemStringList.value = 31.5 | |
# client.service.writeStringData(itemStringList,writeDataOptions ) | |
# getDataHistoryOptions.finalDate = datetime.datetime.now() | |
# getDataHistoryResponse = client.factory.create('tns5:GetDataHistoryResponse') | |
# print 'getDataHistoryResponse' | |
# print getDataHistoryResponse | |
# print 'Obtaining historical data of tag' | |
# print client.service.getDataHistory(itemName,getDataHistoryOptions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment