Handling of Data Points
In order to process the values of data point elements (DPE) in a script, these have to be read from the process image first and must be passed to a local variable. Calculation and assignment take place through the variables of the script. These must be passed to the data point elements if needed. The most important functions are:
dpGet(string dpe, anytype val, ...) // Read from DPE
dpSet(string dpe, anytype val, ...) // Write from DPE
Both commands can read several data points at once and pass them to a corresponding number of variables. These are one-time accesses that return corresponding answers exactly for the call time.
main()
{
float val1, val2;
bool val3;
string dpeXY;
dpGet("Drive04.state.speed", val1);// Read the value of the data
point
//element to the variable val1
val1 = val2 + 20;
dpeXY = "Drive04.cmd.speed"; // Assignment of the string
// of a DPE to a variable
dpSet(dpeXY, val2); // Set the data point element
// "Drive04.cmd.speed" to the
// value of the variable val2
dpGet("Drive04.state.speed", val1, // Call with several DPEs
"Drive05.cmd.setpoint", val2,
"Drive06.state.on", val3);
dpSet("Drive04.cmd.speed", val1, // Call with several DPEs
"Drive05.cmd.setpoint", val2,
"Drive06.cmd.on", !val3); // ! Inversion of the value
}
Naturally a data point element you want to access through CONTROL also has to exist. This applies particularly to the access to configs/attributes since not all configs are available on each data point element. Appropriate errors are output at runtime first and are noted in the log viewer or in the log file.
A summarization of several read or write operations into one call as shown in the lower part of the upper example, is always recommendable and improves the performance.
The following short script for clicked in a graphic object "Button" would switch the operating status "Manual mode" for the valve V03 of our example. The state of the manual mode command will be changed through each [leftMouseClick] and through the device simulation also the shown actual value.
main()
{
bool manualMode;
dpGet("V01.state.manual",manualMode);
dpSet("V01.cmd.manual",!manualMode); // '!' inverts the set value
}
In contrast to the unique access functions used so far, the most applications demand a permanent update of displays and reporting. Since WinCC OA works totally event oriented, corresponding functions are also available.
main()
{
dpConnect(string callBackFunction,[bool noInit], string dpe
[,...]);
}
callBackFunction(string dpe, anytype value,...)
{
// ... executed actions when the value of 'dpe' is changed
}
The above function registers the value changes of the data point element defined through 'dpe' at the Event Manager. As soon as the value changes, the corresponding control script will be returned and thedefined call-back-function will be called. The following script forinitializefor a rectangle, changes the background color depending on the state of the binary data point elementV03.state.manualofthisexampleproject.
main()
{
dpConnect("showStateCB", "V03.state.manual");
}
showStateCB(string dpe, bool man)
// per registered DPE a string variable for the name and a
//suitable type for the value are declared
{
if (man)
this.backCol = "yellow"; //If 'man' == TRUE, the background color will be
//yellow,
else
this.backCol = "grey"; //otherwise grey
}
The function dpConnect() can access several data point elements or attributes simultaneously. Independent from what value has changed, the call back function will be executed. When declaring the call back function, you have to provide a data point name and value pair as parameter for each registered element. For more information, see online help dpConnect().