Xfiles - 01 - The Code.1
Xfiles - 01 - The Code.1
“The Code”
TABLE OF CONTENTS
1 INTRODUCTION ............................................................................................................................ 2
1.1 Restriction .............................................................................................................................. 2
1.2 History.................................................................................................................................... 2
1.3 Related documents................................................................................................................ 2
2 IMPLEMENTING SYMBOLS ......................................................................................................... 3
2.1 Introduction ............................................................................................................................ 3
2.2 Goals...................................................................................................................................... 4
2.3 Create the graphical shapes.................................................................................................. 4
2.4 How not to do it ! .................................................................................................................... 5
2.4.1 Creating the symbol using the Wizard .............................................................................. 6
2.4.2 Disadvantage..................................................................................................................... 8
2.5 Coding from ‘scratch’ ............................................................................................................. 8
2.5.1 Introduction........................................................................................................................ 8
2.5.2 Where to put the code ....................................................................................................... 8
2.5.3 Coding the base functionality ............................................................................................ 9
2.5.4 Testing the symbol .......................................................................................................... 10
2.5.5 Making the symbol (code) dynamic................................................................................. 11
2.5.6 Testing the symbol with dollar parameter ....................................................................... 13
2.5.7 Displaying the alarm status ............................................................................................. 15
2.5.8 Displaying quality ............................................................................................................ 16
2.5.9 Enabling / disabling the buttons ...................................................................................... 18
3 CONNECTING DATA .................................................................................................................. 21
3.1 Introduction .......................................................................................................................... 21
3.2 dpGet()................................................................................................................................. 21
3.3 dpConnect() ......................................................................................................................... 22
3.3.1 Connecting multiple ......................................................................................................... 22
3.3.2 Why the DP in the callback ............................................................................................. 23
3.3.3 dpConnect() with variable argument ............................................................................... 24
3.3.3.1 Solution 1 : ‘For dummies’ ..............................................................................................................26
3.3.3.2 Solution 2 : dyn_... ...........................................................................................................................27
3.4 Connecting to more than data ............................................................................................. 29
3.5 dpQueryConnect...() ............................................................................................................ 30
3.5.1 Setting up a query connect.............................................................................................. 30
3.5.2 Examples......................................................................................................................... 32
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 1 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
1 Introduction
This is the first episode in (hopefully) a long range of new adventures. Each one
describing a certain subject in the beautiful world of PVSS.
This first one is describing various techniques related to the PVSS Control language.
Various examples will hopefully help you to create top quality applications.
Agent Mulder
6/7/2008
1.1 Restriction
1.2 History
Author F. Mulder
Version 1
Date 6/7/2008
First version
Document By Description
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 2 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
2 Implementing symbols
2.1 Introduction
The first, and most likely place, where you’ll need ctrl programming are the
symbols/panels in PVSS. Wizards are available to define the dynamics of a graphical
shape. However, a good understanding of the ctrl language helps you to implement
symbols with a maximum performance.
The light assumes a datapoint type ‘Light’ with the following layout:
Note:
A ‘SumAlarm’ is used that combines all the possible alarms in the datapoint. This
makes the coding of the symbol easier.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 3 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Note:
Make some instances of this datapoint type. Throughout this document we’ll assume
that there are datapoints called “light0000” to “light0100”.
2.2 Goals
You should have some goals when implementing symbols.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 4 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Note:
Saving a panel under \objects means that it becomes a symbol that you can drag
onto a panel. Choose ‘View – Catalogue’ to see the symbol
Result would be a symbol that has code in several shapes. Also, the performance
wont be at its best, because the symbol has to do 2 dpConnect()’s. ( Where one
would have been enough )
Please note:
The Wizard is an excellent tool. However, use it wisely !
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 5 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
2.4.1 Creating the symbol using the Wizard
The ctrl wizard is an excellent tool to add code to a symbol. However, if you use it
wrong, then you could get a symbol that has many dpConnect()’s, thus having not
the best possible performance.
In the Ctrl Wizard, choose the option ‘Change color’. Choose the option ‘Background’
and choose ‘Value – dependent’
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 6 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Then select the datapoint element ‘$dp + .Status.On’.
We’ll repeat the same thing for the alarm indicator. Here we again change the
background color. But now we choose the option ‘Alert handling’
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 7 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
2.4.2 Disadvantage
The disadvantage of this method is that the object will have more and more
dpConnect()’s making the total symbol slower.
Also, the symbol has code in several places. This is ok for a very small symbol, but
managing the code becomes more difficult when your symbol becomes more
complex.
the disadvantage of locations (1) and (2) is that it is not very clear where the code is
located. A ‘Colleague’ working on the symbol won’t know where you left the code.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 8 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Note:
An alternative solution would be to add an invisible shape ( example: a small red dot
) to your symbol. This way, you’ll always know where you left the code.
Minor disadvantage : your symbol won’t be ‘wysiwig’ because of the little red dot.
Click on the background of the symbol, and choose the ‘EventInitialize’ method:
The dpConnect() would fail when the database doesn’t match the mentioned
datapoint elements in the symbol. Or, the symbol is trying to connect to
datapoint elements that do not exist.
When the dpConnect() fails, then we need to show this in our symbol.
Typically you do this by assigning some color to the shapes in your symbol.
Note:
When you dpConnect() to N values, then the callback will receive 2*N
arguments. N * (Dp element + value )
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 10 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
□ Open the Para panel and select the dp element ‘light000.on’
□ Type values ‘0’ and ‘1’ and ensure that the symbol switches between yellow
and white ! ( Note: You can type 'true', false', '0' or '1' )
Making the code ‘dynamic’ is done by introducing a dollar parameter into the source
code.
This dollar parameter is like a ‘keyword’. A replacement for this keyword can be
defined when a symbol is dragged into a panel. Any number of keywords can be
defined for a symbol. Of course, more dollar parameters will make the symbol more
flexible but will also mean that you’ll have more to fill in when using the symbol.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 11 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
The dollar parameter can have any meaning you need in the source code. Typically:
you’ll use a dollar parameter to connect the symbol to a particular datapoint. But it is
also possible to use dollar parameters as settings for the symbol.
Example:
Dollar parameter ( Description
example)
$dp To define the name of the datapoint that is being
visualized
$SHOW_ALARM A ‘setting’ for a symbol. Value 1 could mean that the
symbol must show an alarm color.
$TEXT_COLOR A ‘setting’ for the symbol. Defines the color that is to
be used for the text shown in the symbol.
We’ll introduce a dollar parameter $dp that connects our code to one specific
datapoint instance.
There are many standard panels in PVSS ( like the 'RefDef' panels ) that use
$dp or $dpe to indicate a datapoint or datapoint element.
Using $dp in your symbols means that you'll be able to use these standard
panels much easier.
The dollar parameter is like a string replacement in our code. The part that we want
to make dynamic is shown below:
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 12 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
The dollar parameter is basically replacing the text “System1:light000”.
( Note: Make sure not(!) to include the dot just after light000 )
The source code with the dollar parameter replacing “light000” looks like:
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 13 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 14 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
2.5.7 Displaying the alarm status
Our datapoint type “Light” has a sum-alarm in the datapoint element “.SumAlarm”.
The complexity of determining the appropriate alarm status is done by the sum-alarm
mechanism performed by the event manager. Therefore, you do not have to worry
about this yourself in the code of the symbol.
Note:
The help file will show you what attributes you can find in an alert_hdl config under:
\Reference tables\Datapoint configs\_alert_hdl.
We can directly connect to the ‘actual state color’ of the alarm handling. This will give
us the color that is currently on display in the alarm line. We’ll assign the same color
to our little square alarm indicator.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 15 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Let’s look at the code in more detail:
We receive the name of the color, or the actual RGB color value.
The current alarm color can be assigned directly to our little alarm indicator.
You could also decide to hide the alarm indicator when there is no current
alarm. This can be achieved quite easily. You can use the fact that the alarm
color will be an empty string, when there is no active alarm. Therefore, you
could extend the code with:
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 16 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
We’ll extend our dpConnect() to include this quality indication.
We’re adding the attribute _bad to our dpConnect(). This attribute will become
true when the driver and/or event manager determine that the quality of the
value is not good ( driver reports error or event manager sees a range
violation )
Our callback gets 2 more arguments. The boolean bBad will become true
when the value is not good.
We assign a color ‘_invalid’ to our symbol when the quality is not good. We
then do a ‘return’ because performing the rest of the code seems not very
useful.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 17 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Be careful with the ‘return’ statement.Verify that the correct code is being
executed when the quality changes from bad back to good !
This method has one major disadvantage : The buttons won’t be enabled / disabled
when the user logs out ( while a panel with symbols stays open ). A better method is
to handle the state of the buttons as follows:
□ Extend the dpConnect() so that the callback function is called whenever the
user logs in or out.
□ Control the state of the buttons in the callback.
We need to connect to the current user name. That is, the user of the current user
interface. The dpConnect() would look like:
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 18 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
The dpConnect() will receive the name of the current user. However, we’re not
interested in this name and are not using this argument.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 19 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Let’s look at this code in more detail:
This expression evaluates to the datapoint element that holds the user name
logged in to the current user interface.
Example:
_Ui_1.UserName
We receive the current user name but do not really need it. We just need to
connect it so that we are triggered whenever the user logs in or out.
The above example shows that you’d need to extend the dpConnect() so that
the buttons are enabled/disabled the right way. This of course means a bit of
extra work for every symbol you implement.
An easier solution could be to simply change the panel when the user logs in
or out. Example: go back to a panel with a welcome message every time the
user logs out.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 20 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
3 Connecting data
3.1 Introduction
PVSS is event driven. The scripting language contains several options to connect to
data. This chapter will show the methods to connect to one or more datapoint
elements.
This paragraph will show you how to ‘connect’ to data asynchronously. This
means that a ‘callback’ function is triggered when the connected datapoint
elements change.
Make sure not to built in dpGet()’s in your callback since this will highly affect
the performance of your symbol. It is better to extend the dpConnect() (
conect to more values ) than to perform dpGet()’s to get additional values !
3.2 dpGet()
There are basically two ways of getting data : synchronous or asynchronous.
Asynchronous means that you request data, but your script doesn’t wait for it.
Instead, the data will arrive at a later time.
Synchronous means that your script code will wait for the value. This can be done,
for example, with a dpGet() statement.
Example:
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 21 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
3.3 dpConnect()
The most obvious way to get asynchronous data updates is to use the dpConnect().
This statement, which sends a network messages to the event manager, is used to
subscribe to 1 or more values.
The first argument in the dpConnect() is the name of a ctrl function. Any
function name is possible.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 22 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Note: When the dpConnect() is used to request 2 values, then the callback will
contain 2 * 2 = 4 arguments.
This becomes clear when you consider the possibility of using one callback function
for N dpConnect()’s.
Lets assume that we have N datapoints of type Light. We want to send out an email
when one of the lights breaks down.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 23 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
We can then dpConnect() to N Light datapoints, each using the same callback
function:
Our callback function will need to know which datapoint ‘called’ it. This is done by the
following code:
The function dpSubStr will cut out just the datapoint name from the argument strDP
that the callback received.
Lets assume that you have a dpConnect() that sometimes connects to N and
sometimes to M values. This is not possible without a creative solution.
Example:
Let’s assume that we want to have a symbol that displays an analogue value.
Optionally, it can also dpConnect() to a boolean value that makes the symbol visible
or invisible.
The non creative solution would be to have 2 dpConnect() statements. One with just
the analogue value, and one that makes the symbol visible/invisible.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 24 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
This of course has some mayor disadvantages:
□ When you have N optional items to connect to, then you may need 2N
callback functions.
Example:
Lets say that you develop a symbol to enter a float value. You have 2 optional
dollar parameters called "$Visible" and "$Enabled". Optional means that the
engineer may or may not want to use these 2 features.
In this case, having 2 optional features, means that you would need 22 = 4
different callbacks.
□ The symbol will become slower and slower. It is not wise to add more
dpConnects.
□ The total source code will become ‘spaghetti’
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 25 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
3.3.3.1 Solution 1 : ‘For dummies’
As said before, the dpConnect() and its callback function must have a matching
number of arguments. That is : the dpConnect() and the callback must form a
matching pair.
Also, it is not possible to connect to ‘nothing’. The dpConnect() must refer to actual
datapoints.
Our local variable initially refers to a dummy datapoint that we’ve created. The
dummy datapoint should have a value that will give you the desired effect in
your callback function.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 26 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
□
When the symbol requires visibility handling ( bDoVisible == true ) then it sets
the local variable to the name of the actual datapoint.
□ There will always be just one dpConnect() and just one callback !
□ We give a dummy value to the callback that has exactly the right value.
Therefore, it keeps the callback function simple.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 27 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Let’s look at this code in more detail:
When visibility handling is requested, then the name of the datapoint is added
to the dyn_string as well.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 28 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
□
When you pass a dyn_string to the dpConnect() then the callback will require
exactly 2 arguments:
o dyn_string strDP
o dyn_anytype aValue
an array of values.
The dpConnect() can be used to get an update from any attribute of any config.
See the help file under ‘\Reference tables\Datapoint configs’ for a detailed list
of attributes for each possible config.
There’s a large set of attributes that you could connect to. However, there are
probably just a couple of attributes that you’ll encounter frequently.
Attribute Description
Light1.Status:_alert_hdl.._act_state_color The current alarm color
Light1.Status:_alert_hdl.._act_state The current alarm state
Light1.Status:_alert_hdl.._active Alarm enabled or disabled
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 29 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Light1.Status:_address.._reference The actual address string
In general, the attribute _type of a config can be used to check whether the
config is actually being used.
Example:
If you want to check whether alert handling is being used then check:
Light1.Status:_alert_hdl.._type
3.5 dpQueryConnect...()
A dpConnect() will request data from an exact specified number of datapoint
elements. You’ll get exactly the data that you’ve requested. Nothing more and
nothing less.
The dpQueryConnect..() will give you a callback when one or more values, matching
the specified query, change. This means that the callback function will typically
receive a 2 dimensional array of values.
□ It works like a ‘wildcard connect’. Which means that you don’t have to specify
individual datapoints but adress a whole set of datapoints
□ It will even work for a datapoint that has been newly created
□ Updates can be received as a ‘block’. Typically this would mean less network
traffic.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 30 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
Let’s look at this code in more detail:
We start of with a very simple query that gives us the ‘original value’ from all
datapoint elements matching the wildcard ‘*.Status.On’
“valueCB”
Is the name of the callback function that will be called.
“true”
Indicates that we want the initial values of all datapoint elements matching the
query
“MyQuery”
Is an identifier that the callback function receives
“Query”
Is the actual query that we want to execute.
The callback function receives : the identifier of the query plus the 2
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 31 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
dimensional array with the values we’ve requested.
Every element in the array ‘aResult’ contains one ‘record’. The very first
record does not actually contain data. Instead, it tells you what values have
been requested.
3.5.2 Examples
This paragraph shows several example queries:
Returns all datapoints that match *.Status.On that currently have the value 1
Returns all datapoints that match *.Status.On and are of datapoint type “Light” that
currently have the value 1
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 32 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249
A query that returns 2 elements from selected datapoints.
Note:
This will only work when you add the _DPT clause ! Also, you can only specify one
datapoint type
A query to retrieve all elements called *.General.Notes excluding the value in the
master datapoint
Collect the ‘active’ bit of all datapoint elements that have an _alert_hdl config.
Project: XFiles ETM Benelux B.V. Tel: +31 (0)73 - 523 28 28 Author: F. Mulder
A Siemens Company Fax: +31 (0)73 - 523 28 29
Document: XFiles – 1 – Raadhuisstraat 53 [email protected] Date: 6/7/2008
The Code NL-5241BK Rosmalen www.etm.at
Versie: 1 Page 33 of 34
Status: Released BTW nr. NL8115.29.794.B01
Rek. nr. 48.90.70.469 KvK ‘s-Hertogenbosch
ABN AMRO Bank 17150249