Description In this FAQ response we describe how you can write data from WinCC (TIA Portal) Runtime to a file or read data from the file. VBScript (Visual Basic Scripting) is used for implementing these functions. In order to save or read out information in a text file, it must be possible to access the file system of Microsoft Windows CE. Access is made here by means of the "FileSystemObject".
Documentation on VBScript commands Information about the separate VBScript commands is available in the WinCC (TIA Portal) help system in the "Content" tab under " Visualizing processes > Working with system functions and Runtime scripting".
Instructions
The table below describes how to configure saving to and reading from files in WinCC (TIA Portal).
The file formats below are used:
csv
txt
Note
Only internal tags are used in this example. Alternatively, you can also use tags with controller connection.
In this example we demonstrate writing to and reading from files on a memory card. If you use a different storage medium, this must be changed accordingly in the script.
No.
Procedure
1
Create tags
Open the tag editor by means of "Project navigation > HMI_1 > HMI tags > Show all tags".
Add four internal tags with the following designations:
Tag
Data type
bExtension
Bool
szMaterial
WString
nPressure
Int
nTemperature
Int
Bild 02
2
Add objects
Add a new screen named "ImportExportData" under "Project navigation > Screens".
Insert two rectangles in the screen.
Add a symbolic IO field and three conventional IO fields.
Add a button and nine text fields.
Position all the objects and enter the texts below (see Fig. 04).
"Process values"
"Pressure"
"Temperature"
"Material"
"Text file"
"mbar"
"°C"
"Settings"
"Extension"
Create a text list named "Extension" and of the "Value/Range" type.
Add the following entries:
0 => ".txt"
1 => ".csv"
Bild 03
3
Incorporating script, text list and tags
Create a script with the designation "Write_data". For this you go to the project navigation and click "Scripts > VBScripts > Add new VB functions".
Link the "Write_data" script to the "Save file" button under "Properties > Events > Click".
Link the "Extension" text list to the symbolic IO field "Extension".
Link the tags below to the corresponding objects.
Tag/Script
Object type
Object for ...
iPressure
IO field
Pressure
iTemperature
IO field
Temperature
szMaterial
IO field
Material
bExtension
Symbolic IO field
Extension
Bild 04
4
Create script - Part 1
Add the sample code to the "Write_data" script (see Fig. 05).
Note
More information about the VBScript commands is available in the Help system of WinCC (TIA Portal).
Description of the source code
<Lines 10 - 15> Declaration of local tags (only valid in the script).
<Line 18> The "mode" tag is initialized for opening the file (8 = Append).
<Lines 21-29> The "bExtension" tag is a global tag that can be used in the entire WinCC (TIA Portal) project. This tag is used to choose the file extension by means of the symbolic IO field.
Note The "delimiter" tag serves as a separator and must be changed according to the country where applied!
<Line 32> The "On Error Resume Next" instruction is required in case a Runtime error occurs in the script. As soon as such an error occurs the next line containing the error routine is executed automatically. Note If this instruction is missing and an error occurs, the script is terminated.
<Line 35> The "CreateObject("FileCtl.File")" function creates an object that accesses the file system of Windows CE.
<Lines 38-42> The source code includes the error routine for a Runtime error. If a Runtime error occurs, an error message is output in the message window and the script is then terminated.
Note If you use "FileCtl.File", you can only access the file system of Windows CE. If this script is started on a PC with a different operating system, a Runtime error occurs in the script and the script is aborted.
Bild 05
5
Create script - Part 2
<Line 45> Using the "Open" method of the "fo" object created the file specified is opened by means of the "path" (path name) and "mode" parameters.
<Lines 48-52> Error routine that is run if the corresponding file or path name does not exist.
<Lines 55-57> In this section a check is made as to whether the file is new or already available. If the file is new, a header is added.
<Line 60> The "LinePrint" method of the "fo" object writes the text string specified to the opened file. Tag values or return values of methods can also be written to the file.
The "Now" function writes a time stamp to the file.
<Line 63> The "Close" method closes the file.
<Line 66> The "Nothing" key statement is required to separate the object tags that are assigned to the objects with the "Set" command.
<Line 68> Transfers a user-defined system message to the HMI message system.
Bild 06
6
Start Runtime
Transfer the WinCC (TIA Portal) project to the operator panel and start Runtime. Note The script cannot be debugged between the configuration computer and the panel because of the different file systems.
Enter a pressure, temperature and Material.
Confirm with the "Save data" button.
In the symbolic IO field you select ".csv" and click the button again.
Terminate the Runtime of the operator panel.
Bild 07
7
Open text file
If you save both files on the memory card, then you can view them on a PC by means of a card reader and open them with the appropriate program.
Open the file with the ".txt" extension.
Then you can close the file.
Bild 08
Open the file with the ".csv" extension with Excel, for example.
Close the Excel application.
Bild 09
Table 01
Example of reading information from a .txt file or .csv file The table below explains how to read information from a .txt file or .csv file and display it in WinCC (TIA Portal). IO fields are used for the display. For this reason, only the last entry is output.
Note Since the last entry is sought in this example, the script runtime increases with the size of the file. Generally the configuration does not depend on the example described previously. However, components from it are used.
No.
Procedure
1
Connect tags
Open the tag editor by means of "Project navigation > HMI_1 > HMI tags > Show all tags".
Add three internal tags with the following designations:
Tag
Data type
szdate
WString
szString_1
WString
iValue_1
Int
iValue_2
Int
Note
If you cannot use the previous project, then add the "bExtension" tag of the "Bool" type.
Bild 10
2
Add objects
Switch to the "ImportExportData" screen.
Insert a rectangle in the screen.
If not already there, incorporate a symbolic IO field and four conventional IO fields.
Add a button and five text fields.
Position all the objects as shown in Fig. 11 and enter the texts below:
"Date"
"Value_1"
"Value_2"
"String_1"
"Text file"
"Settings" (if not already there)
"Extension" (if not already there)
If not already there, create a text list named "Extension" with the entries below:
0 => ".txt"
1 => ".csv"
Bild 11
3
Incorporating script, text list and tags
Copy the "Write_data" script and change the name to "Read_data" (changes in script are dealt with in point 5).
Link the "Read_data" script to the "Read file" button under "Properties > Events > Click".
If not already done, link the "Extension" text list to the symbolic IO field "Extension".
Link the tags below to the corresponding objects.
Tag/Script
Object
Object for...
szDate
IO field
Date
iValue_1
IO field
Value_1
iValue_2
IO field
Value_2
szString_1
IO field
String_1
Bild 12
4
Change script
Change the "Read_data" script as described below.
Description of the source code
<Lines 10-15> Change the names of the local tags (see Fig. 13).
<Line 18> Change the initialization of the "mode" tag from 8 (Append) to 1 (Input).
<Lines 21-29> Remove the "gap" tag that is no longer needed.
Bild 13
5
Change script
<Lines 54-60> Remove the section in which writing to the file takes place.
<Lines 54-60> Add reading from the file (see Fig. 14).
Bild 14
6
Start Runtime
Transfer the WinCC (TIA Portal) project to the operator panel and start Runtime.
Note
Start the simulation with Script Debugger to debug the script.
Click the "Read data" button.
In the symbolic IO field you select ".csv". Click the button again.
Terminate the Runtime of the operator panel.
Bild 15
Table 02
Download The attachment includes the sample project described.
Note
The source code used in the script can only be used in operator panels with Microsoft Windows CE, because it is not possible to access the file system of other operating systems with this source code.
How do you create a time switch with WinCC flexible?
Description
This FAQ response describes one way you can create a "weekly timer" with WinCC flexible without using program blocks from the PLC.
There are three switching procedures (time intervals) available for each day of the week.
(For example, one for the "early shift", one for the "afternoon shift" and one for the "late shift").
You set the switch-on and switch-off times by way of a "date/time field".
You can select/deselect each switch-on/off time separately.
Once the specified switch-on time is reached, an output signal is set.
This output signal can be transferred to a PLC, to switch on a pump, for example.
Once the specified switch-off time is reached, the output signal is reset.
The following figure shows the Runtime picture created.
Fig. 01
Which operator panels are supported?
The instructions below apply for all operator panels that support scripts. An overview of the functions of the various operator panels is available in Entry ID: 40227286.
In this application we have used an MP 277 Touch.
Please refer to the attached documentation and configuration for details.
The attached download contains a WinCC flexible project with the functions described in the document.
Creation environment The configuration was made with WinCC flexible 2008 SP2.
Downloads
Contents of the downloads
Download
Documentation
The documentation includes all the necessary configuration steps perform the example in the FAQ.
( 733 KB )
Code
The packed file contains the sample MP 277 Touch project.
( 2996 KB )
Additional information
Title
Link
How do you implement a weekly timer for the SIMATIC S7-1200 in STEP 7 V11?
Description Accessing object properties via a script serves as an alternative to configuring object properties from the Properties dialog box.
Some objects cannot be changed in SIMATIC WinCC (TIA Portal) using the available options, resizing rectangles in runtime, for example. These attributes or properties can be changed or dynamized with the aid of scripts.
At the end of the entry is a PDF document and the described sample project ready for downloading.
The PDF document contains a list of objects included by default in WinCC Comfort and WinCC Advanced. In addition, all the properties (attributes) of the objects and the type of access to the properties are listed which can be called using a script statement.
Instructions
In the example below we show how you can change the width and height of a rectangle using a script in Runtime.
The names used for the tags and the objects can be changed separately as required.
The tags do not need a controller connection (only if you want to assign the width and height of the rectangle via the controller).
For better understanding it is useful to open the attached configuration.
No.
Procedure
1
Add a rectangle
Insert an object of the "Rectangle" type into the "Screen_01" screen. Note
The name of the screen will be used later in the script.
Define the size and name of the object.
In this example the rectangle has a width of 100 and a height of 50.
The name of the object is "Rectangle_1". Note
The name of the object (rectangle) will be used later in the script.
Fig. 01
2
Create tags
The width and height of the rectangle are to be changed using a script. Create two internal tags named "RectangleHeight" and "RectangleWidth".
(Project navigation > Operator panel > HMI tags > Standard tag table).
The tags are assigned a start value. In this case, "100" for the width and "50" for the height (Properties > Values > Start value. The reason for this measure is described further here (Link).
Note
The tags will be used later in the script.
Fig. 02
3
Create scripts Two scripts are used in the configuration.
(Project navigation > Operator panel > VB scripts > Add new VB function).
You can specify the names of the scripts as required.
In this example:
Script_01_Rectangle
Script_02_Init_Rectangle
Below we describe the two scripts used in more detail.
4
Script_01_Rectangle Using the "Script_01_Rectangle" script you can change the size of the rectangle.
Create an internal script tag You need an internal script tag to change the properties of an object in WinCC (in this case the properties of a rectangle).
You can specify the name of the tag as required.
In this example: "ObjectRectangle"
Define the object
The "Rectangle_1" object is transferred in the script editor to the "ObjectRectangle" internal tag.
The "HmiRuntime.Screens" statement indicates the screen where the object (rectangle) is located.
The object (rectangle) in the screen in question is accessed explicitly using the "ScreenItems" statement.
In this example:
Set ObjectRectangle = HmiRuntime.Screens("Screen_01").ScreenItems("Rectangle_1"),
Note
Bear in mind that the object must be unique in that screen, this means that the name may not be used by any other object.
However, the same object name may exist in other screens!
Assign to the object (rectangle) the tags for "Height" and "Width"
The "Width" defines the object's width.
The "Height" attribute defines the object's height.
Two tags for "Width" and "Height" have been defined for the rectangle used.
These tags are assigned to the object accordingly.
In this example:
ObjectRectangle.Width = SmartTags("RectangleWidth")
ObjectRectangle.Height = SmartTags("RectangleHeight")
Fig. 03
5
Script_02_Init_Rectangle Using the "Script_02_Init_Rectangle" script you can change the size of the rectangle to a size defined in the script (reset to "initial size").
It is only for resetting the rectangle to the "original size", for example, without having to enter a value beforehand using the IO fields.
The script has exactly the same structure as the "Script_01_Rectangle" script. The only difference is that fixed values are given for the width ("200") and height ("100") of the rectangle.
Fig. 04
6
Tips for creating the script
Autocomplete
Use "Autocomplete" when creating scripts.
Autocomplete is a feature that provides a context-dependent list in a dialog from which you can choose the tags or statements required. Example 1
Enter a "period" after the "...= HmiRuntime" dialog.
A "pop-menu" opens from which you can select from all of the available tags and statements.
Fig. 05
Example 2
Enter a "period" after the "ObjectRectangle" dialog.
A "pop-menu" opens from which you can select from all of the available attributes.
Fig. 06
Add tag
Go to the point where you want to add the tag.
Right-click. A pop-up menu opens.
Select the menu command "Autocomplete > List objects".
Another window opens from which you can select the relevant tag and accept it with the symbolic "OK" button.
Fig. 07
7
Add buttons and IO fields
To specify the width and height of the rectangle you need two IO fields. Two buttons are used to run the scripts.
The internal tags for "width" and "height" are configured respectively at the IO fields
(Properties > General > Process).
The "Change size" button calls the "Script_01_Rectangle" script
(Properties > Events > Click).
The "Standard size" button calls the "Script_02_Init_Rectangle" script
(Properties > Events > Click).
8
Define properties of the "Screen_01" screen The this example is executed using the "Screen_01" screen.
If the size of the rectangle is changed, then this is only present temporarily. If the page is called again, the rectangle resumes the size of the configuration.
If you wish to retain the changed size after a page change, call the "Script_1_Rectangle" script when the "Screen_01" screen is loaded (Properties > Events > Loaded).
The first time the page is called or if no values have been defined yet for the size of the rectangle, then the rectangle is not visible on the page (width and height have the value "Zero").
This can be prevented by defining initial values at the "Width" and "Height" tags (Link).
Fig. 09
9
Notes and tips on configuring
To test the attached configuration you can use a TP1200 Comfort or the simulation from WinCC Comfort or WinCC Advanced.
If you specify a value via the IO fields, then make sure that with this value the current screen width or screen height is not exceeded by the object (rectangle). Otherwise you get a system message (script error). Remedy
In the properties of the "RectangleHeight" and "RectangleWidth" tags you can set a maximum value via "Properties > Range > Settings". This value depends on the position of the object configured.
Error in the script ...
The scripts read out the name of the object (rectangle). If you want to test the configuration in the "PC Runtime Simulation", then before starting Runtime check that the option is enabled under "Runtime Settings > General > Screen > Load name".
The Help system of WinCC (TIA Portal) provides more information about the topic of "VBS object model" (see figure below).
Fig. 10
Table 01
Additional Information (not relevant for this example)
The Help system of WinCC V11 (TIA Portal) provides all the objects in relation to VBS. The designations for the various objects are listed in the table below.
For example, enter "Rectangle" as search term in the index of the information system. As a result you get an overview of the object from which you can then call additional information.
Fig. 11
Basic objects
No.
Object
HMI Runtime Object
1
Line
Line
2
Polyline
Polyline
3
Polygon
Polygon
4
Ellipse
Ellipse
5
Circle
Circle
6
Rectangle
Rectangle
7
Text field
TextField
8
Graphics display
GraphicView
Table 02
Elements
No.
Object
HMI Runtime Object
1
IO field
IOField
2
Button
Button
3
Symbolic IO field
SymbolicIOField
4
Graphical IO field
GraphicIOField
5
Date/time field
DateTimeField
6
Bar
Bar
7
Switch
Switch
8
Symbol library
SymbolLibrary
9
Slider
Slider
10
Pointer instrument
Gauge
11
Clock
Clock
Table 03
Controls
No.
Object
HMI Runtime Object
1
Alarm View
MessageView
2
Trend view
TrendView
3
User Display
UserView
4
Status/Control
StatusForce
5
Sm@rtClient display
SmartClientView
6
Recipe display
RecipeView
7
f(x) trend display
f(x)TrendView
8
System diagnostics display
SystemDiagnosticsView
9
Media player
MediaPlayer
Table 04
Note
Bear in mind that not all objects are available in all operator panels.
Creation environment The screens and downloads in this FAQ were created with WinCC V11.
Downloads
Contents of the downloads
Download
Documentation
Attachment 1 contains a list of objects included by default in WinCC Comfort
and WinCC Advanced. In addition, all the properties (attributes) of the objects and the type of access to the properties are listed which can be called via the script statement of "HmiRuntime.Screens" and "ScreenItems".
Description The MP 377 15" Touch daylight readable is already integrated in the HMI software WinCC flexible 2008 SP3 and WinCC V12 and can be selected in the hardware catalog; it is not necessary to install a supplied AddOn here nor are the procedures described under "Install ProSave Options" necessary.
Requirements If you are using WinCC flexible 2008 SP1 HF2 or WinCC flexible 2008 SP2, you must install the WinCC flexible AddOn in order to be able to select the MP377 15" Touch daylight readable as operator panel in WinCC flexible and ProSave. By installing the AddOn you can also configure the "Set Brightness" function.
Entry ID 28531852 contains possible solutions for working with different versions of WinCC flexible on one system.
Installation
No.
Procedure
1
Depending on the version of WinCC flexible, insert the AddOn CD from the operator panel delivery package in the CD/DVD drive of your PC or download the AddOn and unpack it on your hard disk.
2
Start the installation by double-clicking on the "MP377 Daylight*.msi" file or "Setup.exe".
Version V01.00.01.01_01.05 is located in the "WCF_Addon" folder.
Version V01.00.01.02_01.02 is located in the "WCF2008SP1HF2\WCF_Addon" folder.
Version V01.00.02.01_01.08 is located in the "WCF2008SP2\WCF_Addon" folder.
3
Now follow the instructions of the installation wizard until the installation is completed.
4
Now you can select and configure the Multi Panel 377 15" Touch daylight readable as operator panel in WinCC flexible and ProSave.
Table 02
Configuring the AddOn
More information on configuring the AddOn "Set Brightness" is available in the manual of the MP377 15" Touch daylight readable in Entry ID: 37954241 in the section "Appendix > The Addon 'Set Brightness' > Configure".
Installing ProSave options Proceed as described below to be able to use options with ProSave on the MP 377 15"Touch Daylight.
No.
Procedure
1
Close ProSave.
2
Insert the AddOn CD from the operator panel delivery package in the CD/DVD drive of your PC.
3
Start the "ModifyPii.bat" file from the "Tools" folder with a double-click.
4
Open ProSave.
5
Under "Device Type" select the MP 377 15" Touch Daylight.
6
In the "Options" tab select the option that you want to install and transfer it to the operator panel.
Table 03
Note The MP 377 15" Touch daylight readable is already integrated in the HMI software WinCC flexible 2008 SP3 and WinCC V12 and the procedure described under "Installing ProSave options" is not necessary here.
How do you configure a connection between WinCC flexible Runtime (PC/Panel) and a SIMATIC S7-300/S7400 via PROFIBUS/MPI?
Contents The procedure is given in the attached PDF document with the following contents.
1 Introduction
2 Preliminary Considerations
2.1 When should you use an HMI station and when a PC station?
2.2 Which PROFIBUS CP should you select?
3 Connecting a Panel via PROFIBUS
3.1 Requirements
3.2 Configuration in STEP 7 and WinCC flexible as well as on the panel
4 Connecting WinCC flexible Runtime to SIMATIC S7-300/400 Without
Station Configuration Editor
4.1 Requirements
4.2 Connecting an HMI station
4.3 Connecting a PC station
5 Connecting a WinCC flexible Runtime to SIMATIC S7-300/400 With
Station Configuration Editor
5.1 Requirements
5.2 Connecting an HMI station
5.3 Connecting a PC station
Description For various applications it might be necessary to start a system function of the HMI operator panels during running operation. This can be done either directly in the Control Panel or in Runtime using the "StartProgram" function.
Instructions The "StartProgram" is executed by means of a button with the "Click" event. This function starts the parameterized system function.
No.
Procedure
1
In you project you assign the "Start Program" function to a button.
Parameter
Description
Program name
Name and path of the program that is to be started.
Program parameters
Parameters that are transferred to the program when started. (For example, a file that is to be used.)
Display
Defines the type of display.
Wait for end of program
Defines whether there is to be return to the project after the called program has ended.
The figure below shows an example of how the function parameters are to be entered in ProTool or WinCC flexible.
( 56 KB )
Fig. 01: Configuration of the function
2
For an HMI operator panel with Windows CE 3.0, you use the values from the list below as program parameters.
( 47 KB )
Fig. 02: Parameters of the Control Panel in Windows CE 3.0
Note
You can see which version of Windows CE your panel has in the "System" menu item of the Control Panel.
Remark
The call of the "Transfer" menu itemdepends on the version of Windows CE Image used. "\Windows\transferApl.cpl,0" is used in more recent versions of Image.
3
For an HMI operator panel with Windows CE 5.0, you use the values from the list below as program parameters.
( 39 KB )
Fig. 03: Parameters of the Control Panel in Windows CE 5.0
Note
You can see which version of Windows CE your panel has in the "System" menu item of the Control Panel.
Note Since this involves accessing the system level of the device, this button should be provided with a user authorization. Notes on user administration are given in the table below.
FAQs on the topic of user administration
Entry ID
Tips and tricks on the topic of user administration (WinCC flexible)