show the entry list

WinCC -- Creating HMI configurations -- Using variables  
How do you divide a process tag (16 bits) into 2 internal tags of 8 bits each in WinCC? 
How can you indirectly address a variable via a C script? 
In the case of an FMS connection from WinCC to a controller, how do you address a bit in the controller? 
Converting an integer variable into an ASCII variable in WinCC 
Why are spaces displayed at the beginning of the process-associated value (text) and characters truncated at the end? 
How can I speed up the first call of GetTag or SetTag functions? 
Which logic operations of tags are possible in C scripts? 
How do you apply the functions GetTagMultiWait and SetTagMultiWait for strings in WinCC? 
What do you have to pay attention to in VBScript when linking tags bit by bit and how do you set the highest value bit (Bit 31/Bit 32) in WinCC with VBS? 
How do you use the "SetTagMultiWait()" functions to write multiple WinCC tags? 
How do you use the "GetTagMulti()" functions to read multiple WinCC tags? 
Why does accessing tags - by specifying the tag prefix in the tag name - lead to access errors within the picture window? 
How do you toggle a WinCC variable of the data type "Binary" using VBS (Visual Basic Scripting)? 
Why is the value not displayed correctly when you write a tag via VBS and then read it directly? 
How can you determine the size of the memory for C data types and C tags? 

How do you divide a process tag (16 bits) into 2 internal tags of 8 bits each in WinCC?Go to beginning
Part number:

Instructions
You can use the script below, behind a button, for example, to divide the 16-bit tag.
 

Tag

Description

16-bit

16-bit tag that you want to divide

8-bit_1

1. Subtag 1 where the high byte of the 16-bit tag is to be stored.

8-bit_2

1. Subtag 2 where the low byte of the 16-bit tag is to be stored.

Script listing:

internal value, high, low;

value = GetTagWord ("16-bit");

// Get the 16-bit process value

high = value>>8;

// Filtering high byte of the process value

low = 0x00ff & value;

// Filtering low byte of the process value

SetTagByte ("8-bit_1" , high);

// Save high byte of the process value

SetTagByte ("8-bit_2" , low);

// Save low byte of the process value


How can you indirectly address a variable via a C script?Go to beginning
Part number:


Instructions

This script reads in a structure name from an internal variable "VariableFlag" and adds an instance name to it. The variable value is then read from the final variable.
The following script is triggered by a mouse click on a button.

Program listing:
=============

#include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
char* InstanceNameA;
DWORD VarContA;
// Presetting of internal variable with structure name,
// this can also have happened at a different point
SetTagChar("VariableFlag","TriangleEnvelopeCurve");
// Reservation of memory
InstanceNameA = SysMalloc(200);
// Read in structure name
strcpy(InstanceNameA,GetTagChar("VariableFlag");
// Test output in diagnostic window
printf("Contents Pointer Position 1: %s\r\n", InstanceNameA);
// Add instance name to variable name
strcat(InstanceNameA,".Triangle_1");
// Test output in diagnostic window
printf("Contents Pointer Position 2: %s\r\n", InstanceNameA);
// Read in variable value
VarInhA = GetTagWord(InstanceNameA);
// Test output in diagnostic window
printf("VariableContents: %d\r\n", VarContA);
// Release of reserved memory
SysFree(InstanceNameA);
}
 

In the case of an FMS connection from WinCC to a controller, how do you address a bit in the controller?Go to beginning
Part number:

Description
In your project you are using an FMS connection from WinCC to a controller. You want to address individual bits in the controller by way of this connection. The FMS channel does not support byte or bit transfer. Thus you can only address individual bits in words or double-words in the controller. You have two options for this:

Dynamic Wizard
In the Dynamic Wizard in the Graphics Designer of WinCC you go to the "Standard Dynamics" tab and select the "Setting/Resetting a bit" function.
You can configure this action behind an object in the Graphics Designer. In the dialog you select the trigger, the tag, the action (set/reset) and the bit that you want to change.


Fig. 01

Project functions
Use the project functions described below. These describe the individual bits of an FMS process tag (16-bit or 23-bit).

Application in an action

  1. Create a 16-bit or 32-bit tag in the Tag Management of WinCC under the FMS connection. The bit that you want to address is a bit in this tag.
  2. Incorporate the attached functions into your project.
    Copy the Functions.zip file into a separate folder and then start the file with a double-click. Copy the unpacked files into the Drive:\ProjectName\Library\ directory. Open the Global Scripts editor regenerate the header. The copied functions are now displayed under "Project functions". A detailed description of these functions is given below.


    Fig. 02

  3. Insert an object which must be clicked to set or reset a specific bit. Open the project properties. Switch to the "Event" tab. Select "Mouse" and double-click "Mouse Click". A window opens in which you can edit the action.


    Fig. 03

  4. In the Action window you double-click one of your project functions that have just been inserted.
  5. As the first parameter you specify the tag that you configured in Point 1. You can select this from the tag list.
  6. As second parameter you specify the bit that is to be set or reset.


    Fig. 04

  7. Click "OK". Now the script has been generated.
  8. Click "OK" again to compile and save the action. Now, when you click this object, the bit is set or reset.

Visualizing via an I/O field

You create an I/O field in the Graphics Designer for a visual check of the tags.

  1. Create a 16-bit or 32-bit tag in the Tag Management of WinCC under the FMS connection. The bit that you want to address is a bit in this tag.
  2. You now create an I/O field in the Graphics Designer. In the Properties tab you select "Output" as field type, "Binary" as data format and "1" as output format.


    Fig. 05

  3. Under "Limits" you specify "0" as the low limit value and "1" as the high limit value.


    Fig. 06

  4. Under the Output Value property you open the Dynamics dialog. Select "Bit" as data type. The tag is the one which you have created in Point 1. Also select the bit that you want to address. Under "Result Of The Expression/Formula" you set "1" for "set" and "0" for "not set" for the "Output".


    Fig. 07

  5. Click the "Apply" button to exit the I/O field configuration. Now the I/O field will display the bit from the controller.

Description of the attached functions

ResetWordTagBit

This function resets the selected bit of the selected tag

Parameters

TagName

16-bit tag with the bit that is to be reset

Bit

The bit in the tag that is to be reset


ResetDWordTagBit

This function resets the selected bit of the selected tag

Parameters

TagName

32-bit tag with the bit that is to be reset

Bit

The bit in the tag that is to be reset


SetWordTagBit

This function sets the selected bit of the selected tag

Parameters

TagName

16-bit tag with the bit that is to be set

Bit

The bit in the tag that is to be set


SetDWordTagBit

This function sets the selected bit of the selected tag

Parameters

TagName

32-bit tag with the bit that is to be set

Bit

The bit in the tag that is to be set

Download of the project functions
Functions.zip ( 4 KB )

Project function list
Functions.pdf ( 6 KB )

Converting an integer variable into an ASCII variable in WinCCGo to beginning
Part number:

QUESTION:
How should I proceed to convert an integer number into an ASCII variable in a WinCC script?

ANSWER:
For this, use the string I/O routine "sprintf()".

Here is a WinCC project in which a conversion is demonstrated. Two internal variables with the following properties have been created in the variables list of WinCC:
 

Name

Data type

Inint

32-bit value with sign

outstr

Text variable 16-bit character set

When you start the Runtime, the following window opens:

In the "input integer" field you enter an integer value and acknowledge with the "convert" button. Now the integer value appears as a string in the "output string" field. The C script for the conversion of integers to strings located behind the "convert" button looks like this:

DWORD Val;
char TmpStr[64];

Val = GetTagDWord("inint");
sprintf (TmpStr, "%u", Val);
SetTagChar ("outstr", TmpStr);
printf("\"%s\"\r\n",TmpStr);

The attached ZIP archive contains the WinCC project. The project has been created with WinCC V5.0. Copy the file onto your hard disk and double-click the archive to extract it into a directory.

int2str_1.exe ( 1833 KB )

Why are spaces displayed at the beginning of the process-associated value (text) and characters truncated at the end?Go to beginning
Part number:

Description
An 8-bit text tag is linked to an I/O field in WinCC. The associated value in the AS is to be displayed as such in the Alarm Logging Control and sent with SFB 35. This user-configured text tag is written to the AS as an S7 string. However, this data type has a header of 2 bytes which is not displayed.

Message-associated values are not of the "S7 string" type, but arrays of the CHAR type. The AS then sends the data as additional value as of a specified start address. If this address is put at the start of the above-mentioned text tag, the text including the header is displayed in the Alarm Logging Control. In order to avoid this, you must increase the start address by 2 bytes.

Example
In the Tag Management, the string variable "varOtto" is configured with the address DB10.DBB16. If you write this variable with the text "anna", you have the following text as of DB10.DBB16:
"0A 04 a n n a". If you assign the parameter SD_n := P#DB10.DBX16.0 CHAR 4, when a message arrives, it transfers the header and two following characters, in this case therefore:
"0A 04 a n"
. In order to display the associated value correctly, you must set the following parameter: SD_n := P#DB10.DBX18.0 CHAR 4.

Fig. 1: Variable "varOtto" in the WinCC Tag Management, in the Step 7 data block and in the variable table ( 277 KB )  

Keyword:
Message configuration, Message-associated value

How can I speed up the first call of GetTag or SetTag functions?Go to beginning
Part number:

Instructions
In your scripts you use the internal GetTag or SetTag functions. In the functions you access tags that are not used by any objects in the picture. The first access to the tag takes a lot longer than the subsequent accesses.

Cause
Before you can access a tag, the tag has to be logged onto the WinCC data manager for updating.
If objects are dynamized in the process display with tags, then the Graphics Runtime knows which tags a process display needs. In this way all the tags used can be logged on for updating as soon as the display opens.
If a tag is not used in the picture and you access the tag in a script, the tag is not yet available. It first has to be logged on for updating, which is why the first access takes longer.

Remedy

  • Create invisible objects in the picture.
  • Dynamize the Properties of these objects with a tag that you use in scripts.
    Example:
    Add a text field and dynamize the colors with a tag each.

The result is that as soon as the picture opens, all the tags required are available. This then makes the first calls of the GetTag and SetTag functions just as fast as the subsequent calls.

Keywords
Time reduction, Tag requesting

 

Which logic operations of tags are possible in C scripts?Go to beginning
Part number:

Description
All logic operations that are permissible in C are possible. The table below shows a number of examples.
 
Logical operators Function
 = = Comparison for equality
 ! = Comparison for inequality
 && AND operation of two conditions
 || OR operation of two conditions
! Negation

Truth table
 
Cond. 1 Cond. 2 ! (to Cond. 1)   = =     ! =     &&     ||  
0 0 1 1 0 0 0
0 1 1 0 1 0 1
1 0 0 0 1 0 1
1 1 0 1 0 1 1

Note
Please note that the operators "&" and "|" link bit by bit and the operator "=" creates an assignment.
More information on creating C scripts is available in the manual "WinCC Scripting" or in a C programming reference book.

How do you apply the functions GetTagMultiWait and SetTagMultiWait for strings in WinCC?Go to beginning
Part number:

Instructions  
The memory required for strings is reserved by the function GetTagMultiWait itself via SysMalloc
The strings are stored in the memory reserved in this way with SysMalloc.
The initial addresses of the individual strings are returned to the calling function (e.g. the user script).

The call parameter triple for strings must have the following format:

  • For GetTagMultiWait
    String format  %s
    WinCC tag  Name of the WinCC text tag
    C tag  Reference to a char pointer (i.e. the address of the pointer tag)

     

  • For SetTagMultiWait
    String format  %s
    WinCC tag  Name of the WinCC text tag
    C tag  char pointer (initial address of the string)

Example for copying values

char* string;                                              //pointer to string
char* string_array[2];                                //2 pointers to strings

GetTagMultiWait("%s%s%s", 
"text_tag_8bit_1",     &string,
"text_tag_8bit_2",     &string_array[0],
"text_tag_8bit_3",     &string_array[1]);

SetTagMultiWait("%s%s%s",
"text_tag_8bit_4",     string,
"text_tag_8bit_5",     string_array[0],
"text_tag_8bit_6",     string_array[1]);

What do you have to pay attention to in VBScript when linking tags bit by bit and how do you set the highest value bit (Bit 31/Bit 32) in WinCC with VBS?Go to beginning
Part number:

Configuration Notes:
When linking one or more 32-bit tags bit by bit in WinCC Global Script / VBScript, there is overflow and the script is aborted if the highest value bit (Bit 31) is set in one of the tags.

Example:
If VBScript is used to display in the picture the status of specific bits of a double-word, then there is an incorrect display if Bit 31 is set in the double-word.

Remedies:
Make sure that Bit 31 is not being used or is not set when you apply bit-by-bit operations (e.g. "And" operator) to double-word tag. You should check a 32-bit tag for the status of the highest value bit before the first bit-by-bit processing and if necessary, change it. Using the "greater than or equal to" query you can determine whether Bit 31 of a 32-bit tag is set. If the value of the 32-bit tag is greater than or equal to 231, then Bit 31 is set. In this case, you can subtract the value 231 from the value of the 32-bit tag to reset Bit 31. In this way the other bits can be evaluated correctly. The following figure shows a VBScript that makes this procedure clear. In this example, the status of Bit 0 of a 32-bit tag for dynamization is used. If Bit 0 is set, the background color of an object is set to the value "green", otherwise to the value "gray".


Fig. 01

The following VBScript uses the method described above to transfer the values of the bits of a 32-bit tag to a bit field. Then, in the bit field you can correctly call and process the separate bits.

WinCC_VBOverflowBit31_vbs.pdf ( 9 KB )

The following download provides this script also as a text file.

WinCC_VBOverflowBit31.zip ( 6 KB )

Keywords:
VBS, Visual Basic Script, Bit 31, Bit 32, MSB

How do you use the "SetTagMultiWait()" functions to write multiple WinCC tags?Go to beginning
Part number:

Instructions:
In WinCC Global Script C there are by default several "SetTagMulti()" functions available for writing the values of multiple WinCC tags:

  • BOOL SetTagMultiWait(const char* pszFormat, const char* pszTag, void vValue, ...)
  • BOOL SetTagMultiStateWait(DWORD* pdwState, const char* pszFormat, const* pszTag, void vValue, ...)

These functions are so-called "Wait" functions, i.e. they write the tag values directly to the PLC and not to the picture of the WinCC Data Manager. The number of parameters of these functions is variable; they depend on the number of tags to be written.

Parameters:
The following parameters are transferred to the "SetTagMulti()" function:

  • DWORD* pdwState (only for SetTagMultiStateWait())
    The user of the "SetTagMulti()" function must make an array available for DWORD tags (reserve memory). The pointer to the first element of the field is transferred to the "SetTagMulti()" function. The "SetTagMulti()" function continuously writes the Tag Status of the WinCC tags written to the address transferred.
     
  • const char* pszFormat
    The user of the "GetTagMulti()" function must make a string available (reserve memory) and initialize it with the format information for the WinCC tags to be written. The pointer to the first element of the string is transferred to the "SetTagMulti()" function.
     
  • const char* pszTag
    "pszTag" is a pointer to the first element of a string that contains the name of a WinCC tag to be read.
    The user of the "SetTagMulti()" function must transfer a "pszTag" string for each tag to be written.
     
  • void vValue
    "vValue" is the tag whose value is written to the WinCC tag.
    The user of the "SetTagMulti()" function must transfer this parameter for each tag to be written.
    The actual data type for this parameter depends on the data type of the WinCC tag to be written. See the table below for the possible data types.

Return value:
Die "SetTagMulti()" function returns the value "TRUE" when the function itself has been run through without error. If an error occurs during program processing, e.g. the value "ZERO" is transferred to at least one parameter or the format string contains invalid format specifications, the "SetTagMulti()" function returns the value "FALSE". The function does not check whether the tag has been written without error. For this reason you cannot use the return value to check whether the writing of WinCC tags was really successful or not. Therefore you should use the "SetTagMultiStateWait()" function and the associated Tag Status for error evaluation.

Information on the quality of WinCC tags (Tag Status) is available in the WinCC Information System under:

  • "Communication > Communication - Diagnostics > Quality of Tags > Tag Status"

General information on how the "SetTag()" functions work is available in the WinCC Information System under:

  • "Working with WinCC > ANSI-C for Creating Functions and Actions > ANSI-C function descriptions > Internal functions > tag > set > Functionality of the SetTag functions"

The following table describes the possible format specifications in the format string and indicates which format specifications can be used with which WinCC and C data types.
 
Format WinCC data type C data type
"%d" Integer WinCC tags
  • Binary tag
  • Signed 8-bit value
  • Unsigned 8-bit value
  • Signed 16-bit value
  • Unsigned 16-bit value
  • Signed 32-bit value
  • Unsigned 32-bit value
32-bit tag (4 bytes)
The format specification "%d" is used to write the value to an integer WinCC tag. Regardless of the size of the WinCC tags, there must always be 4 bytes of memory reserved, because otherwise the "SetTagMulti()" function writes an incorrect value to the WinCC tag. Entry ID: 26710239 describes how to determine the size of the memory required for a C tag. Possible data types include:
  • BOOL
  • DWORD
  • int
  • long

Examples:

  • In order to write the value to an unsigned 8-bit value WinCC tag, you can use a C tag with the data type DWORD and transfer this tag to the "SetTagMulti()" function.
  • In order to write the value to a signed 8-bit value WinCC tag, you can use a C tag with the data type "int" or "long" and transfer this tag to the "SetTagMulti()" function.

Warning!
When using a WinCC tag of the data type "Unsigned 32-bit value" (DWORD), the highest value bit (Bit 31) must not be set, because in this case the SetTagMulti() function does not write the desired value to the tag, the old value is retained. An error is displayed in the Tag Status.

"%f" Floating-point WinCC tags
  • Floating-point number 32-bit IEEE 754
  • Floating-point number 64-bit IEEE 754
"double" or "float" tag
The format specification "%f" is used to write a value to a floating-point WinCC tag. You can use a "float" or a "double" tag for the C tag.

Example:
In order to write the value to a floating-point 32-bit WinCC tag, you can use a C tag with the data type "double" or "float" and transfer this tag to the "SetTagMulti()" function.

Note:
If the "GetTagMulti()" and "SetTagMulti()" functions are used in a C action to read, process and then rewrite specific WinCC tags, for example, then it is best to use the data type "double" for floating-point tags, because in this case the "GetTagMulti()" function only processes the "double" data type correctly.

"%s" Text WinCC tags
  • Text tag 8-bit character set
  • Text tag 16-bit character set

"char*" tag (pointer to a character)
The format specification "%s" is used to write a value to a WinCC text tag. The user must reserve the complete memory for the C string. The address to the first element of the string is transferred to the "SetTagMulti()" function.

Behavior in the case of configuration errors:
Below are descriptions of the behavior in selected configuration error cases:

  • Access to a WinCC variable that is not created in the WinCC Tag Management
    If you use the "SetTagMultiWait()" or "SetTagMultiStateWait()" function to access a tag that is not created in the WinCC Tag Management, then an "OnErrorExecute" error message ("Tag unknown, timeout or conversation failed - Tag not found") is generated in the Global Script diagnostics window or "APDIAG" output window. The Tag Status contains the information that an access error has occurred.
     
  • Using a C data type with less than 4 bytes of memory to read a WinCC integer
    If you use a C tag that occupies less than 4 bytes of memory (e.g. BYTE, WORD, char or short) to write the content of a WinCC integer, then most likely an incorrect value will be written to the WinCC tag, because the function always writes 4 bytes. The Tag Status displays an error ("Format limit exceeded").
     
  • Access to an unsigned 32-bit WinCC value where the highest value bit (Bit 31) is set
    If you want to write the content of a C tag of the data type "DWORD" to a WinCC tag of the data type unsigned 32-bit ("DWORD") where Bit 31 is set, then the "SetTagMulti()" function does not write the value to the WinCC tag. No "OnErrorExecute" error message is generated in the Global Script diagnostics window or "APDIAG" output window. The Tag Status contains the information that an error has occurred ("Format limit exceeded").
    Remedies:
    • If possible, make sure that Bit 31 of the unsigned 32-bit WinCC tag is never set.
    • If the 32-bit WinCC tag is an external WinCC tag, then in the WinCC Data Manager you can configure the Upper Limit: 2147483648 (hexadecimal 0x80000000) for this tag.


      Fig. 01


      Violation of the upper limit configured is then displayed in the Quality Code and Tag Status and can be processed.
       
    • Use the function "SetTagDWordXXX()".
    • In the Tag Management you create the WinCC tag as a signed 32-bit value and use the data type "DWORD" for the C tag.
       
  • Defective structure of the format string
    • A format specification is invalid with regard to the data type actually used
      Below is a list of cases where the format specification is invalid and the function is aborted with the return value "FALSE":
      • The format specification "%s" or "%f" is used to write an integer.
      • The format specification "%s" or "%d" is used to write floating-point number.
      • The format specification "%f" is used to write a text tag.
      Below is the description of a case where the format specification is invalid and the function is terminated with the return value "TRUE". However, here an undesired value is written. The Tag Status contains no information that an access error has occurred.
      • The format specification "%d" is used to write a text tag.
         
    • The format string contains too many format specifications
      If the parameters (pszTag, vValue) necessary for all the format specifications in the format string parameters are not transferred to the "SetTagMulti()" function, then an "OnErrorExecute" error message ("Tag unknown, timeout or conversation failed - Tag not found") is generated in the Global Script diagnostics window or "APDIAG" output window. The Tag Status contains the information that an access error has occurred.

      Note:
      If more parameters (pszTag, vValue) than specified in the format string are transferred, then the values specified with the format string are written correctly. The values for which there are no format specifications in the format string are not written. The Tag Status for these tags contains the information that an access error has occurred. No "OnErrorExecute" error message is displayed in the Global Script diagnostics window or "APDIAG" output window.

Sample configuration: Dynamic structure of the format string
If many tags are to be written with the SetTagMulti() function, the structure of the format string becomes unclear. You can no longer quickly see with the naked eye whether there are enough format specifications in the format string and whether the format specifications are valid for the data types used. In order to avoid structure errors in the format string, it is also possible to configure the format string during runtime. The information regarding which tags are to be written with the SetTagMulti() function can be stored in a field. Here, each field element represents a structure that contains the information required (format specification, WinCC tag name and associated C tag).

Below is a script for downloading (PDF and text files), which demonstrates this procedure.

WinCC_SetTagMulti_c.zip ( 7 KB )

WinCC_SetTagMulti_c.pdf ( 10 KB )

The following two figures show the external and internal WinCC tags in the Tag Management, which are written in the sample script with the "SetTagMultiStateWait()" function.


Fig. 02
 


Fig. 03
 

The script can be called as a C action in a picture (e.g. mouse-click event for a button).
The following figure shows the content of the WinCC tags at runtime. The WinCC tags are displayed in the picture via the direct tag link to the "Output Value" property of the I/O fields. At the same time, the output window of the diagnostics tool "APDIAG" is displayed containing the values written.


Fig. 04
 

Note:
The script was created with WinCC V6.2.

How do you use the "GetTagMulti()" functions to read multiple WinCC tags?Go to beginning
Part number:

Instructions:
In WinCC Global Script C there are by default several "GetTagMultiWait()" functions available for determining the values of multiple WinCC tags:

  • BOOL GetTagMultiWait(const char* pszFormat, const char* pszTag, void* pvValue, ...)
  • BOOL GetTagMultiStateWait(DWORD* pdwState, const char* pszFormat, const* pszTag, void* pvValue, ...)
  • BOOL GetTagMultiStateQCWait(DWORD* pdwState, DWORD* pdwQC, const char* pszFormat, const* pszTag, void* pvValue, ...)

These functions are so-called "Wait" functions, i.e. they evaluate the tag values directly from the PLC and not from the picture of the WinCC Data Manager. The number of parameters of these functions is variable; they depend on the number of tags to be read.

Parameters:
The following parameters are transferred to the functions:

  • DWORD* pdwState (only for GetTagMultiStateWait() and GetTagMultiStateQCWait())
    The user of the "GetTagMulti()" function must make an array available for DWORD tags (reserve memory). The pointer to the first element of the field is transferred to the "GetTagMulti()" function. The "GetTagMulti()" function continuously writes the Tag Status of the WinCC tags read to the address transferred.
  • DWORD* pdwQC (only for GetTagMultiStateQCWait())
    The user of the "GetTagMulti()" function must make an array available for DWORD tags (reserve memory). The pointer to the first element of the field is transferred to the "GetTagMulti()" function. The "GetTagMulti()" function continuously writes the Quality Code of the WinCC tags read to the address transferred.
  • const char* pszFormat
    The user of the "GetTagMulti()" function must make a string available (reserve memory) and initialize it with the format information for the WinCC tags to be read. The pointer to the first element of the string is transferred to the "GetTagMulti()" function.
  • const char* pszTag
    "pszTag" is a pointer to the first element of a string that contains the name of a WinCC tag to be read.
    The user of the "GetTagMulti()" function must transfer a "pszTag" string for each tag to be read.
  • void* pvValue
    "pvValue" is an address where the "GetTagMulti()" function stores the content of the WinCC tags read.
    The user of the "GetTagMulti()" function must transfer an address for each tag to be read.

Return value:
The "GetTagMulti()" function returns the value "FALSE" when the value "ZERO" is transferred to at least one of the parameters, otherwise it returns the value "TRUE". For this reason you cannot use the return value to check whether the reading of WinCC tags was really successful or not. Therefore, you should use the "GetTagMultiStateWait()" or "GetTagMultiStateQCWait()" function and use the Tag Status or the Quality Code for error evaluation.

Information on the quality of WinCC tags (Tag Status and Quality Code) is available in the WinCC Information System under:

  • "Communication > Communication - Diagnostics > Quality of Tags > Tag Status"
  • "Communication > Communication - Diagnostics > Quality of Tags > Quality Codes of Tags"

General information on how the "GetTag()" functions work along with examples is available in the WinCC Information System under:

  • "Working with WinCC > ANSI-C for Creating Functions and Actions > ANSI-C function descriptions > Internal functions > tag > get > Functionality of the GetTag functions"

The following table describes the possible format specifications in the format string and indicates which format specifications can be used with which WinCC and C data types.
 
Format WinCC data type C data type
"%d" Integer WinCC tags
  • Binary tag
  • Signed 8-bit value
  • Signed 8-bit value
  • Unsigned 8-bit value
  • Unsigned 16-bit value
  • Signed 32-bit value
  • Unsigned 32-bit value
32-bit tag (4 bytes)
The format specification "%d" is used to write the value of an integer WinCC tag to a C tag. Regardless of the size of the WinCC tags, there must always be 4 bytes of memory reserved, because the GetTagMulti() functions always write 32 bits (4 bytes) to the target address specified when the "%d" format specification is used. Entry ID: 26710239 describes how to determine the size of the memory required for a C tag. Possible data types include:
  • BOOL
  • DWORD
  • int
  • long

Examples:

  • In order to read the value of an unsigned 8-bit value WinCC tag, you can create a C tag with the data type DWORD and transfer the address to this tag to the "GetTagMulti()" function.
  • In order to read the value of a signed 8-bit value WinCC tag, you can create a C tag with the data type int or long and transfer the address to this tag to the "GetTagMulti()" function.

Warning!
When using a WinCC tag of the data type "Unsigned 32-bit value" (DWORD), the highest value bit (Bit 31), because in this case the GetTagMulti() function generates a conversion error and returns the value 0.

"%f" Floating-point WinCC tags
  • Floating-point number 32-bit IEEE 754
  • Floating-point number 64-bit IEEE 754
"double" tag
The format specification "%f" is used to write the value of a floating-point WinCC tag to a C tag. There must be 8 bytes of memory reserved, because the GetTagMulti() functions always write 64 bits (8 bytes) to the target address specified when the "%f" format specification is used. The "double" data type must be used.

Example:
In order to read the value of a floating-point 32-bit IEEE 754 WinCC tag, you must create a C tag with the data type "double" and transfer the address to this tag to the "GetTagMulti()" function.

"%s" Text WinCC tags
  • Text tag 8-bit character set
  • Text tag 16-bit font
  • Text reference

"char*" tag (pointer to a character)
The format specification "%s" is used to write the value of a WinCC text tag or WinCC text reference tag to a C tag. The user must reserve the memory for a "char" pointer. The address to this pointer tag is transferred to the "GetTagMulti()" function. The GetTagMulti() function reserves the necessary memory for storing the content of the WinCC text tag itself, stores the content of the WinCC text tag in the memory reserved and writes the address of the reserved memory to the address transferred.

Example:
In order to read the value of a WinCC text tag, you must create a C tag with the data type "char*" (pointer) and transfer the address to this tag to the "GetTagMulti()" function. (...oh, a pointer to a pointer!).

Behavior in the case of configuration errors:
Below are descriptions of the behavior in selected configuration error cases:

  • Access to a WinCC variable that is not created in the WinCC Tag Management
    If you use the "GetTagMultiStateWait()" or "GetTagMultiStateQCWait()" function to access a tag that is not created in the WinCC Tag Management, then an "OnErrorExecute" error message ("Tag unknown, timeout or conversation failed - Tag not found") is generated in the Global Script diagnostics window or "APDIAG" output window. The Tag Status and Quality Code contain the information that an access error has occurred.

    Warning!
    In this case, the "GetTagMultiWait()" function does not generate an "OnErrorExecute" error message in the Global Script diagnostics window or "APDIAG" output window.
     
  • Using the C data type "float" to read a WinCC floating-point number
    If the content of a WinCC tag of the data type "floating-point number 32-Bit IEEE 754" is to be written to a C tag of the data type "float", then the "GetTagMulti()" function returns the value "0.0" as a floating-point value. There is no error display in the Global Script diagnostics window or "APDIAG" output window. The Tag Status and Quality Code contain no information that an access error has occurred.
     
  • Using a C data type with less than 4 bytes of memory to read a WinCC integer
    If you use a C tag that occupies less than 4 bytes of memory (e.g. BYTE, WORD, char or short) to read the content of a WinCC integer, this can lead to undefined behavior of the system or plant, because in this case the GetTagMulti() function writes to memory areas it is not supposed to.
     
  • Access to an unsigned 32-bit WinCC value where the highest value bit (Bit 31) is set
    If you want to write the content of a WinCC tag of the data type unsigned 32-bit value ("DWORD") to a C tag of the data type "DWORD", then the "GetTagMulti()" function returns the value "0" (hexadecimal 0x00000000) as integer. An "OnErrorExecute" error message ("Tag unknown, timeout or conversation failed - OLE conversation failed") is generated in the Global Script diagnostics window or "APDIAG" output window. However, the Tag Status and Quality Code contain no information that an access error has occurred.

    Remedies:
    • If possible, make sure that Bit 31 of the unsigned 32-bit WinCC tag is never set.
    • If the 32-bit WinCC tag is an external WinCC tag, then in the WinCC Data Manager you can configure the Upper Limit: 2147483648 (hexadecimal 0x80000000) for this tag.


      Fig. 01
       

      Violation of the upper limit configured is then displayed in the Quality Code and Tag Status and can be processed.
       
    • Use the function "GetTagDWordXXX()".
    • In the Tag Management you create the WinCC tag as a signed 32-bit value and use the data type "DWORD" for the C tag.
       
  • Defective structure of the format string
    • A format specification is invalid with regard to the data type actually used
      If a format specification is used in the format string, which is not permissible for a specific data type, then an invalid value is returned. An "OnErrorExecute" error message ("Tag unknown, timeout or conversation failed - OLE conversation failed") is generated in the Global Script diagnostics window or "APDIAG" output window. However, the Tag Status and Quality Code contain no information that an access error has occurred.

      Example:
      This error occurs, for example, when a WinCC text tag with the format specification "%d" is read.
       
    • The format string contains too many format specifications
      If the parameters (pszTag, pvValue) necessary for all the format specifications in the format string parameters are not transferred to the "GetTagMulti()" function, then an "OnErrorExecute" error message ("Tag unknown, timeout or conversation failed - Tag not found") is generated in the Global Script diagnostics window or "APDIAG" output window. The Tag Status and Quality Code contain the information that an access error has occurred.

      Note:
      If more parameters (pszTag, pvValue) than specified in the format string are transferred, then the values requested with the format string are determined correctly. The values for which there are no format specifications in the format string are not determined. The Tag Status and Quality Code for these tags contain the information that an access error has occurred. No "OnErrorExecute" error message is displayed in the Global Script diagnostics window or "APDIAG" output window.

Sample configuration: Dynamic structure of the format string
If many tags are to be read with the GetTagMulti() function, the structure of the format string becomes unclear. You can no longer quickly see with the naked eye whether there are enough format specifications in the format string and whether the format specifications are valid for the data types used. In order to avoid structure errors in the format string, it is also possible to configure the format string during runtime. The information regarding which tags are to be read with the GetTagMulti() function can be stored in a field. Here, each field element represents a structure that contains the information required (format specification, tag name and target address).

Below is a script for downloading (PDF and text files), which demonstrates this procedure.

WinCC_GetTagMulti_c.zip ( 1 KB )

 WinCC_GetTagMulti_c.pdf ( 10 KB )

The following two figures show the external and internal WinCC tags in the Tag Management, which are read in the sample script with the "GetTagMultiStateQCWait()" function.


Fig. 02
 


Fig. 03
 

The script can be called as a C action in a picture (e.g. mouse-click event for a button).
The following figure shows the content of the WinCC tag at runtime. The WinCC tags are displayed in the picture via the direct tag link to the "Output Value" property of the I/O fields. At the same time, the output window of the diagnostics tool "APDIAG" is displayed containing the values read.


Fig. 04
 

Note:
The script was created with WinCC V6.2.

Why does accessing tags - by specifying the tag prefix in the tag name - lead to access errors within the picture window?Go to beginning
Part number:

Description:
This behavior is due to the picture window property "Tag Prefix". Information on this is available in the WinCC Online Help "WinCC Information System -> Working with WinCC -> VBS for Creating Procedures and Actions -> VBS Reference -> Characteristics -> T -> TagPrefix Property".

The tag prefix is prefixed to all tags in the picture window object. If the tag prefix is used both for the tag connection and for the "Tag Prefix" property of the picture window, the tag name is made up of both prefixes. The tag prefix is then double in the variable name. The access error then occurs when an attempt is made to access this tag.

Entry ID 23690358 contains an example of how to use the tag prefix.

How do you toggle a WinCC variable of the data type "Binary" using VBS (Visual Basic Scripting)?Go to beginning
Part number:

Instructions
Using the script below you can toggle the value of a tag of the "Binary" data type.

If HMIRuntime.Tags("BinaryTag1").Read = 0 Then
   HMIRuntime.Tags("BinaryTag1").Write 1
Else
   HMIRuntime.Tags("BinaryTag1").Write 0
End if

Note
If you want to toggle a property that expects a Boolean value, you must not use the script above. Use the script below instead.

ScreenItems("Button1").Visible = Not ScreenItems("Button1").Visible

Why is the value not displayed correctly when you write a tag via VBS and then read it directly?Go to beginning
Part number:

Description:  
You have, for example, the code lines below in a VBS and realize this does not always work.

HMIRuntime.Tags("NewTag_2").Write HMIRuntime.Tags("NewTag_1").Read
HMIRuntime.Tags("NewTag_3").Write HMIRuntime.Tags("NewTag_2").Read
HMIRuntime.Tags("NewTag_4").Write HMIRuntime.Tags("NewTag_3").Read
HMIRuntime.Tags("NewTag_5").Write HMIRuntime.Tags("NewTag_4").Read

In the case above the values are read and written via the tag image. In order to be sure the tag was read before it was written, you can use a synchronous read and write job. Therefore, change the read jobs from "Read" to "Read(1),1" - as in the following example.

HMIRuntime.Tags("NewTag_2").Write HMIRuntime.Tags("NewTag_1").Read(1) ,1
HMIRuntime.Tags("NewTag_3").Write HMIRuntime.Tags("NewTag_2").Read(1) ,1
HMIRuntime.Tags("NewTag_4").Write HMIRuntime.Tags("NewTag_3").Read(1) ,1
HMIRuntime.Tags("NewTag_5").Write HMIRuntime.Tags("NewTag_4").Read(1) ,1

Remark:
Synchronous read and write jobs are equivalent to GetTagxxxWait and SetTagxxxWait from the world of ANSI C. The disadvantage of these functions is that they take longer because they are dependent on the coupling and the AS. The further processing of scripts is stopped until an answer is received from the AS. Thus, they can lead to a loss in performance, and hence they should be used only in exceptional cases. Asynchronous write and read jobs are considerably more effective because these are processed via the image. Reading and updating of tags are here two procedures that run separately. 
Synchronous jobs should only be used, if it must be ensured that the tag was written or read prior to further processing of the script. 

Note:
Refer to the descriptions of GetTag and GetTagWait given in the WinCC Information System under:

  • WinCC V6.0 "Working with WinCC > ANSI-C for Creating Functions and Actions > Function Descriptions > Internal Functions >tag > get > GetTagBit > How the GetTag functions work"  
  • WinCC >= V6.2 "Working with WinCC > ANSI-C for Creating Functions and Actions > Internal Functions >tag > How the GetTag functions work"  

How can you determine the size of the memory for C data types and C tags?Go to beginning
Part number:

Instructions:
You can use the "sizeof()" operator in Global Script C to determine the memory of C tags and the size of C data types. For this, you can configure a C action in a C action in the picture (e.g. C action for the mouse click event behind a button), which uses the sizeof() operator.

"sizeof(data type)" or "sizeof(tag)"

The "sizeof()" operator provides the size of a tag or a data type in bytes. This can be displayed with the "printf" statement in the Global Script diagnostics window or "APDIAG" output window.

The following two figures show how the "sizeof()" operator is used and the associated outputs in the diagnostics window in order to determine the size of specific C data types.

( 7 KB )
Fig. 01

( 12 KB )
Fig. 02

 Entry ID:26712000   Date:2012-04-12 
I regard this article....as helpfulas not helpful                                 






























related links
Why do read and write jobs someti ...
How can I access a specific bit o ...
SITRANS F Communication Modules ...
User Manual T400 Axial Winder
Execution of ProTool functions
mySupport
My Documentation Manager 
Newsletter 
CAx-Download-Manager 
Support Request
To this entry
Print
Create PDF 
Send to a friend
QuickLinks
Compatibility tool 
Help
Online Help
Guided Tour