+ All Categories
Home > Documents > ScadaBR-Developers - CERTI - ScadaBR2

ScadaBR-Developers - CERTI - ScadaBR2

Date post: 07-Feb-2016
Category:
Upload: -
View: 210 times
Download: 19 times
Share this document with a friend
Description:
ScadaBR-Developers - CERTI - ScadaBR2
20
2/3/2015 ScadaBRdevelopers CERTI ScadaBR https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 1/20 CERTI ScadaBR Home short courses Development API ScadaBR Checklist ScadaBR 0.8 Distribution GUI IT Infrastructure Middleware Protocols Performance tests Use of PLCs Video Lessons ScadaBR Reference Document Glossary Mango Other Scada's Open Source Mango OpenScada Tests Mango Sitemap Home > short courses > ScadaBRdevelopers "Short Course Developers Module I: Using the API Minicourse 8h (for java users and other languages) 1. Introduction API "WebServices" The ScadaBR API is a web service (webservice) using the SOAP technology. This allows you to extend the ScadaBR through architecture "clientserver" where the ScadaBR acts as a server, and an external module (custom development) acts as a client. The ScadaBR and Application Client can be running on the same machine, or on computers separate, provided they are connected and accessible via IP network. To use the API, you must use the infrastructure access to WebServices Search the site
Transcript

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 1/20

CERTI

ScadaBRHome

short courses

DevelopmentAPI ScadaBRChecklist ScadaBR0.8DistributionGUIIT InfrastructureMiddlewareProtocolsPerformance testsUse of PLCsVideo Lessons

ScadaBR ReferenceDocumentGlossaryMangoOther Scada's OpenSource

MangoOpenScadaTests Mango

Sitemap

Home > short courses >

ScadaBRdevelopers

"Short Course Developers Module I: Using the API Minicourse 8h (for java users and otherlanguages)

1. Introduction API "WebServices"

The ScadaBR API is a web service (webservice) using the SOAPtechnology. This allows you to extend the ScadaBR through architecture"clientserver" where the ScadaBR acts as a server, and an externalmodule (custom development) acts as a client. The ScadaBR andApplication Client can be running on the same machine, or on computersseparate, provided they are connected and accessible via IP network.

To use the API, you must use the infrastructure access to WebServices

Search the site

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 2/20

of the chosen language for development. . This usually comes down to usean access to the SOAP library, following their specific documentation Inmost languages, especially those with more automated support for SOAP(such as Java and .NET), are made only two steps: 1) Creation thenecessary API classes from the WSDL import file (webservicesdescription language) 2) Access to the API methods.

The ScadaBR SOAP API exposes the most important features of SCADA,which are reading and writing tags , query historical data and access toalarms and events , among outos. The API can be extended according tospecific user needs. This type of change in ScadaBR will be displayed inthe module II of the short course developers.

2. List of methods available

Among the methods currently available, the most used are:

getStatus returns = operating status of ScadaBRbrowseTags = lists the tags availablereadData = read returns one or more variables (Tags)WriteData = write values TagswriteStringData = write values in Tags (for customers withoutcompatibility AnyData type)getDataHistory = historical pulls a taggetActiveEvents = pulls active events (eg alarms)getEventsHistory = pulls historical events, even inactive

Translate

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 3/20

ackEvents = "recognizes" an event / alarmbrowseEventsDefinitions = reads the types of defined eventsannotateEvent = add a user message at an event.

Some methods allow more detailed manipulation of ScadaBR settings,such as:

configureDataPoint removeDataPoint browseDataPointsremoveDataSource configureDataSourcebrowseDataSources

3. Use stepbystep API

1. Importing the webservice

Java

Note: This stepbystep was done using Eclipse as IDE, so theway to import WebService vary from IDE to IDE.Create a Java projectCopy the project to the .wsdl file

For the .wsdl file, with ScadaBR running, enter the addresswhere the WSDL is located (eg "http: // localhost: 8080 /ScadaBR / services / API wsdl" and save the page in .wsdlformat (originally .xml)

Then right click on the file in the project and select "Web Services > Generate Client"

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 4/20

On the screen that appears, click Finish and Eclipse will generatethe necessary proxies for you to use the API.

To create an instance of the API client:

APILocator locator = new APILocator ();ScadaBRAPI service = null;try service = (APISoapBindingStub) locator.getAPI (); Catch (ServiceException e) // Exception Treatment

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 5/20

VB .NET

This walkthrough was created using Microsoft Visual Basic 2010 Expressand presents the sequence of steps for creating a customer using VB.NET.

1. The installation of Microsoft Visual Basic 2010 Express is fairlystraightforward. It should be realized the web installer downloadofrom:

http://www.microsoft.com/express/downloadsAfter agreeing to the terms, a file called 'vb_web.exe' can bedownloaded. Save this file to the appropriate location andthen run it.The installer will guide the user through all the steps neededto use Microsoft Visual Basic 2010 Express and will alsoperform the download of all dependencies.

2. Once the installation is complete, you must run the Microsoft VisualBasic 2010 Express. If there is no shortcut on the user's desktop,you must run the program:

3. Start> Programs> Microsoft Visual Studio 2010 Express> MicrosoftVisual Basic 2010 Express

4. You must create a new project of type 'Windows FormsApplication'.

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 6/20

5. The new design can be renamed and saved in a suitable place.6. To import the API ScadaBR, you must click with the right mouse

button on the project name and select "Add Service Reference ..."

7. A new window will open and in the 'Address' must be informed ofthe Web Services address that provides the ScadaBR API. In the'Namespace' field you can edit the service name to something morefriendly.

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 7/20

8. If the address provided is correct and available for access, methodsofereceidos the API will be listed. The following image shows themethods AVAILABLE for access at http: // localhost: 8080 /ScadaBR / services / API wsdl?. In this example we also changedthe namespace for ScadaBR_API.

9. With the available Web Services can be written in VB .NET forcustomers to consume ScadaBR API. All methods developed forthe stepbystep were intended to be isolated and therefore allinstantiate via the API code

Dim MyAPI The New ScadaBR_API.ScadaBRAPIClient

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 8/20

PHP

NOTE : For PHP installation on ubuntu and the NuSoap library check thesteps below: 1) Install PHP and Apache: 1.1) $ sudo aptget installapache2 1.2) $ sudo aptget install php5 1.3) $ sudo aptget installlibapache2modphp5 1.4) $ /etc/init.d/apache2 restart 1.5) If apacheis already installed you can omit the item 1.1. 1.6) The web files will bein "/ var / www / " 1.7) To verify that the installation of apache + php isworking . please a browser and type "localhost" in the address bar 2)Download the NuSoap library > http://sourceforge.net/projects/nusoap/ 3)Place the client in the "/ var / www /" or some other of your choice in "/var / www / directory_name /" 4) Extract the library into the directorypreviously chosen, which will be the customer. 5 ) Enter a browser andtype in the address bar the client you want to run. Ex: "localhost /browseTags" or "localhost / directory_name / browseTags"

// Sets the localization of the wsdl $ wsdl ='http://150.162.164.129:8080/ScadaBR/services/API?wsdl';

// Creation of a client instantiates $ client = new nusoap_client ($ wsdl, true);

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 9/20

2. Reading the list of tags

Java

BrowseTagsOptions browseTagsOptions = new BrowseTagsOptions ();browseTagsOptions.setMaxReturn (20); // Optional parameter (default =100)BrowseTagsParams browseTagsParams = new BrowseTagsParams ();browseTagsParams.setOptions (browseTagsOptions);browseTagsParams.setItemsPath (path); // Optional parameter (to listall, just send an empty String or send null)BrowseTagsResponse browseTagsResponse = null;

try browseTagsResponse = service.browseTags (browseTagsParams); Catch (RemoteException e) e.printStackTrace ();

ItemInfo [] = ITEMLIST browseTagsResponse.getItemsList (); String response = "";ApiError [] errors = browseTagsResponse.getErrors ();if (errors [0] .getCode ()! = ErrorCode.OK) response = "Error:" + errors [0] .getDescription (); Else response = "Tags found: \ n"; for (int i = 0; i <itemList.length; i ++) response + = ("\ n" + ITEMLIST [i] .getItemName ());

Result:

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 10/20

VB .NET

Dim MyAPI The New ScadaBR_API.ScadaBRAPIClient

Dim resp As New ScadaBR_API.BrowseTagsResponse Dim params As New ScadaBR_API.BrowseTagsParams Dim options As New ScadaBR_API.BrowseTagsOptions

params.itemsPath = ""

resp = myAPI.browseTags (params)

As Integer Dim listSize listSize = resp. itemsList.GetLength (0)

Dim i As Integer For i = 0 To (listSize ‐ 1) ListBox1.Items.Add (resp.itemsList (i) .itemName) Next

Result:

PHP

$ Proxy = $ client‐> getProxy ();

$ param = array ();

// Call the method browseTags $ result = $ Proxy‐> call ('browseTags', $ param);

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 11/20

3. Reading the value of some tags

Java

ReadDataOptions readDataOptions = new ReadDataOptions ();ReadDataParams readDataParams = new ReadDataParams ();readDataParams.setOptions (readDataOptions);readDataParams.setItemPathList (itemPathList); // List of all tags to bereadReadDataResponse readDataResponse = new ReadDataResponse ();

try readDataResponse = service.readData (readDataParams); Catch (RemoteException e) e.printStackTrace ();

ItemValue [] = itemsValue readDataResponse.getItemsList ();String response = "";

ApiError [] errors = readDataResponse.getErrors ();if (errors [0] .getCode ()! = ErrorCode.OK) response = "Error:" + errors [0] .getDescription ();else response = path + "\ n" + itemsValue [0] .getValue ();

Result:

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 12/20

VB .NET

Dim MyAPI The New ScadaBR_API.ScadaBRAPIClient

Dim resp As New ScadaBR_API.ReadDataResponse Dim params As New ScadaBR_API.ReadDataParams Dim options As New ScadaBR_API.ReadDataOptions

Dim items () As String = "tag1", "tag2"

= params.itemPathList items

resp = myAPI.readData (params) TextBox3.Text = resp.itemsList (0) .value = TextBox4.Text resp.itemsList (1) .value

Result:

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 13/20

PHP

$ Proxy = $ client‐> getProxy ();

$ itemPathList = array ('itemPathList' => 'humidity');

$ param = array ($ itemPathList);

// Call the method readData $ result = $ Proxy‐> call ( 'readData', $ param);

4. Writing a tag

Java

WriteDataOptions writeDataOptions = new WriteDataOptions ();writeDataOptions.setReturnItemValues (false);

ItemValue itemValue = new ItemValue ();itemValue.setItemName (path); // Path of the tag to receive the writeoperationitemValue.setTimestamp (Calendar.getInstance ());itemValue.setQuality (QualityCode.GOOD);itemValue.setDataType (DataType.STRING);itemValue.setValue (novoValor);ItemValue [] = new itemValueList ItemValue [1]; // To change more thanone tag, just add more ItemValue objects in the list

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 14/20

itemValueList [0] = itemValue;

WriteDataParams writeDataParams = new WriteDataParams ();writeDataParams.setItemsList (itemValueList);

WriteDataResponse writeDataResponse = new WriteDataResponse ();

try writeDataResponse = service.writeData (writeDataParams); Catch (RemoteException e) e.printStackTrace ();

String response = "";

ApiError [] errors = writeDataResponse.getErrors ();if (errors [0] .getCode ()! = ErrorCode.OK) response = "Error:" + errors [0] .getDescription (); Else response = path + "\ n" + novoValor;

Result:

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 15/20

Before After

VB .NET

Dim MyAPI The New ScadaBR_API.ScadaBRAPIClient

Dim resp As New ScadaBR_API.WriteStringDataResponse Dim params As New ScadaBR_API.WriteStringDataParams Dim options As New ScadaBR_API.WriteDataOptions

options.returnItemValues = True

= params.options options

iValue0 Dim As New ScadaBR_API.ItemStringValue

iValue0.itemName = " tag1 " iValue0.dataType = ScadaBR_API.DataType.INTEGER iValue0.value = TextBox6.Text

Dim iL () The ScadaBR_API.ItemStringValue = iValue0

params.itemsList = iL

resp = myAPI.writeStringData (params)

Result:

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 16/20

PHP

$ Proxy = $ client‐> getProxy ();

$ Tag1 = array ("itemName" => "humidity", "dataType" =>'Double', "value" => '79', 'quality' => 'GOOD ', "timestamp" => time ());

$ Tag2 = array ("itemName" => "Temperature", "dataType"=> 'Double', "value" => '19', 'quality' => 'GOOD', "timestamp" => time ()) ;

$ itemsList = array ($ Tag1, Tag2 $),

$ param = array ($ itemsList);

// Call the method WriteData $ result = $ Proxy‐> call ('WriteData', $ param);

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 17/20

5. Getting historical data

Java

Calendar ini = Calendar.getInstance ();ini.set (2010, 10, 18, 15, 10, 00);Calendar end Calendar.getInstance = ();fim.set (2010, 10, 18, 15, 10, 10);

GetDataHistoryOptions dataHistoryOptions = newGetDataHistoryOptions ();dataHistoryOptions.setInitialDate (ini);dataHistoryOptions.setFinalDate (order);dataHistoryOptions.setMaxReturn (100); // optionalparameter (default = 500)

GetDataHistoryParams dataHistoryParams = newGetDataHistoryParams ();dataHistoryParams.setOptions (dataHistoryOptions);dataHistoryParams.setItemName (path);

GetDataHistoryResponse dataHistoryResponse = null;

try dataHistoryResponse = service.getDataHistory(dataHistoryParams); Catch (Exception e) e.printStackTrace ();

ItemValue [] = itemsList dataHistoryResponse.getItemsList();

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 18/20

int size;if (itemsList! = null) size = itemsList.length;else size = 1; String [] [] = new String historic [size] [2];ApiError [] errors = dataHistoryResponse.getErrors ();if (errors [0] .getCode ()! = ErrorCode.OK) historical [0] [0] = "Error"; History [0] [1] = errors [0] .getDescription (); Else for (int i = 0; i <size; i ++) historical [i] [0] = itemsList [i] .getValue ().toString (); Date date = itemsList [i] .getTimestamp () getTime ().; String dateFormat = getPrettyTimestamp (date); //method created to format the timestamps historical [i] [1] = dateFormat;

String response = "Value | Timestamp: \ n";for (int i = 0; i <historico.length; i ++) response + = ("\ n" + historic [i] [0] + "|" + historic[i] [1]);

Result:

VB .NET

Dim MyAPI The New ScadaBR_API.ScadaBRAPIClient

Dim resp As New ScadaBR_API.GetDataHistoryResponse Dim params As New ScadaBR_API.GetDataHistoryParams Dim options As New ScadaBR_API.GetDataHistoryOptions

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 19/20

options.initialDate = DateTimePicker1.Value options.finalDate = DateTimePicker2.Value

If (TextBox7.Text = "" ) Then options.maxReturn = 50 Else options.maxReturn = TextBox7.Text End If

params.options = options params.itemName = ComboBox1.SelectedItem.ToString

resp = myAPI.getDataHistory (params)

Dim listSize1 The New Integer = listSize1 resp.itemsList. GetLength (0)

Dim i As Integer For i = 0 To (listSize1 ‐ 1) ListBox2.Items.Add (resp.itemsList (i).itemName.ToString + "," + resp.itemsList (i) +.timestamp.ToString "" + resp.itemsList (i).value.ToString) Next

Result:

PHP

$ Proxy = $ client‐> getProxy ();

$ tags = array ("itemName" => "tag");

$ HistoryOptions = array ("initialDate" => "%","finalDate" => "%", " maxReturn "=>"% ");

2/3/2015 ScadaBRdevelopers CERTI ScadaBR

https://sites.google.com/a/certi.org.br/certi_scadabr/home/minicursos/scadabr 20/20

$ param = array ($ HistoryOptions, $ tag);

// Call the method getDataHistory $ result = $ Proxy‐> call ('getDataHistory', $ param);

4. More information

When installing ScadaBR, is installed a folder with examples of clientapplications. <where is the folder, which customers available> For accessto other methods of API, please refer to detailed documentation in theWIKI page ScadaBR project. <link to get in API help page> For specificinformation on object creation and use of webservice methods in itslanguage, see specific documentation of the chosen language.

Sign in | Recent Site Activity | Report Abuse | Print Page | Powered By Google Sites

Č

INSTALL_PHP [email protected], ċ (1k) 30 Nov. 2010 10:31v.1 ď

clienteBrowseTag… [email protected], ċ 30 Nov. 2010 10:33v.1 ď

clienteReadData.p… [email protected], ċ 30 Nov. 2010 10:34v.1 ď

clienteWriteData.p… [email protected], ċ 30 Nov. 2010 10:34v.1 ď

Comments

You do not have permission to add comments.


Recommended