Action Scripts
ActionScript is a programming language used to create interactive and dynamic animations, games, and applications for the web and mobile devices. It is a derivative of the programming language JavaScript and is often used in conjunction with Adobe Flash and Adobe Flex.
In the context of WinCC, ActionScript can be used to create custom scripts that can interact with the WinCC environment. For example, an ActionScript script can be used to read data from a WinCC variable and display it on a Flash animation. This can be useful for creating interactive operator interfaces or custom visualization applications.
To use ActionScript in WinCC, you will need to have a good understanding of the language and be familiar with the WinCC software. There are many resources available online that can help you learn ActionScript and how to use it with WinCC.
Visual Basic Script in WinCC
In addition to the C script, WinCC also provides the VBScript program language as a programming interface in order to make the WinCC Runtime environment dynamic.
Target Group of the Documentation
This documentation is aimed at project engineers with experience of Visual Basic or WinCC Scriptings (C) used to date.
Application Options
VBScript (VBS) provides access to tags and objects of the graphical Runtime system at Runtime and can execute picture-independent functions:
- Tags: Tag values can be read and written in order, for example, to specify tag values for the PLC by clicking the mouse when positioned on a button.
- Objects: Object properties can be made dynamic using actions and actions can be triggered by events influencing objects.
- Picture-independent Actions: Picture-independent actions can be triggered cyclically or according to tag values, e.g. for the daily transfer of values into an Excel table.
VBS can be used at the following points in WinCC:
- In the Global Script Editor: This is used to configure picture-independent actions and procedures. The procedures can be used in picture-dependent and picture-independent actions. Several procedures are compiled in a topic-related
module. - In Graphics Designer: Picture-dependent actions can be configured with which the properties of graphic objects can be made dynamic or caused to respond to events in Runtime.
- In user-defined menus and toolbars: Here you configure procedures called in
Runtime using the menu and toolbars.
Note Updating Changed Configuration in Runtime A changed VB script that is connected with “Menus and toolbars”
is only updated after Runtime is restarted. If you change the properties of “Menus and toolbars” in Runtime, the changes are only applied in the following cases:
- After a picture change, if the configuration change does not affect the basic picture.
- When you load another configuration file and reload the modified configuration file.
Registered Tags in Menus and Toolbars
The registered tags in the scripts of “Menus and toolbars” remain registered
when you unselect the picture. If you read indirectly from a process mapping the
tags are registered and unregistered again when you unselect the picture.
However, registered tags in the scripts of “Menus and toolbars” remain
registered when you unselect the picture.
Application Scenarios
VBS can be used in Runtime, for example:
- to configure setpoint value specification for tags for the operation of a graphic object in order to define a value for the PLC by clicking a mouse, for example.
- to configure switching the Runtime language for the operation of a graphic object.
- to configure the change of color, e.g. cyclically (flashing) or to display statuses (motor on).
Apart from the specific WinCC applications, the general functionality of VBS can also be used to customize the Windows environment, e.g.:
- to transfer data to another application (e.g. Excel).
- to start external applications from WinCC.
- to create files and folders.
The automation objects in your environment are available with which to customize the Windows environment.
Note All the objects supplied with the Windows Script Host (WSH) from Microsoft can be integrated in the environment using the standard VBS method CreateObject. However, there is no direct access to the WSH object itself using VBS from WinCC. There is no guarantee nor WinCC support for the VBS functionality with regard to its adaptation to the Windows environment. |
Limits to Other Programming Languages in WinCCVBS and C VBScript can be used in WinCC parallel to C-Script, but do not mix the script types:
- VBScripts and C-scripts can be configured within a picture and project.
- C-scripts cannot be invoked in VBScripts and vice versa.
- VBS provides internal interfaces to tags and picture objects while the C environment enables access to other WinCC subsystems (e.g. the report system).
- NB Designer OMRON HMI Youtube Tutorial Videos
- DOPSOFT DELTA HMI Youtube Tutorial Videos
- Wonderware Intouch Youtube Tutorial Videos
- GT Designer MITSUBISHI HMI Youtube Tutorial Videos
- WinCC Siemens HMI Youtube Tutorial Videos
- FACTORY TALK VIEW Youtube Tutorial Videos
VBS and VBA
VBA is used in WinCC Configuration during the configuration in order to adapt
Graphics Designer to your individual requirements and to simplify and automate
configuration. VBA programs only run in the WinCC configuration environment.
As opposed to VBA, VB scripts only run in WinCC Runtime and, from there,
enable access to graphic objects and tags. Objects and pictures can be neither
created nor modified on a permanent basis in VBS, as opposed to VBA.
The main language-related differences between VBA and VBS are e.g.:
- VBS was developed for use on the Internet, VBA for the automation of software
applications. - The data type of VBS tags is always VARIANT. VBA, on the other hand,
differentiates the individual data types such as INT, DOUBLE, STRING, etc. - Certain language constructs from VBA have been removed from or added to
VBS. - Errors are handled differently in VBS compared to VBA.
A complete list of the differences between VBA and VBS is provided in the
Appendix in “Basic Principles of VBScript”.
Procedures, Modules, and Actions
VBS in WinCC allows the use of procedures, modules, and actions to make the
Runtime environment dynamic:
- Procedures: Codes are stored in procedures which are then used at several
points in the configuration. Retrieve the code or another procedure in an action
by invoking the procedure name. Procedures can be created in WinCC with or
without return values. Procedures do not have their own trigger, they are always
retrieved by an action. - Modules: It is advantageous to compile related procedures to units in
modules. Create modules for procedures, for example, which must be used in a
specific picture or belong to a specific topic, such as auxiliary mathematical
functions or database access functions. - Actions: Actions are always activated by a trigger, namely a triggering
event. Actions are configured in graphic object properties, in events that
occur on a graphic object or globally in a project. Codes used several times can
be called, in the form of procedures, in actions.
BV ACTION SCRIPT FOR PART MOVEMENT
PART MOVEMENT WinCC Siemens HMI:-https://youtu.be/2VLQT-bJK1s
——————————————————————————————————————–
LEFT direction
Dim obj1
Set obj1 = ScreenItems(โControl1โ)
obj1.Left = obj1.Left โ 10
If obj1.Left =< 500 Then
obj1.Left = 900
End If
RIGHT direction
Dim obj1
Set obj1 = ScreenItems(โControl1โ)
obj1.Left = obj1.Left + 10
If obj1.Left => 900 Then
obj1.Left = 500
End If
UP direction
Dim obj1
Set obj1 = ScreenItems(โControl1โ)
obj1.Top = obj1.Top โ 10
If obj1.Top =< 50 Then
obj1.Top = 150
End If
DOWN direction
Dim obj1
Set obj1 = ScreenItems(โControl1โ)
obj1.Top = obj1.Top + 10
If obj1.Top => 150 Then
obj1.Top = 50
End if
C-ACTION Script for Option Group
Watch on YouTube:-FUNCTION OF OPTION GROUP WinCC Siemens HMI
——————————————————————————————————————–
if (value == 1)
{
SetTagBit(โop1โ,1);
SetTagBit(โop2โ,0);
SetTagBit(โop3โ,0);
SetTagBit(โop4โ,0);
SetTagBit(โop5โ,0);
}
if (value == 2)
{
SetTagBit(โop1โ,0);
SetTagBit(โop2โ,2);
SetTagBit(โop3โ,0);
SetTagBit(โop4โ,0);
SetTagBit(โop5โ,0);
}
if (value == 4)
{
SetTagBit(โop1โ,0);
SetTagBit(โop2โ,0);
SetTagBit(โop3โ,1);
SetTagBit(โop4โ,0);
SetTagBit(โop5โ,0);
}
if (value == 8)
{
SetTagBit(โop1โ,0);
SetTagBit(โop2โ,0);
SetTagBit(โop3โ,0);
SetTagBit(โop4โ,1);
SetTagBit(โop5โ,0);
}
if (value == 16)
{
SetTagBit(โop1โ,0);
SetTagBit(โop2โ,0);
SetTagBit(โop3โ,0);
SetTagBit(โop4โ,0);
SetTagBit(โop5โ,1);
}
C-ACTION Script for CheckBox
Create checkbox Watch on YouTube:-FUNCTION OF CHECK BOX WinCC Siemens HMI
——————————————————————————————————————–
if (value == 1)
{
SetTagBit(โlamp1โ,1);
SetTagBit(โlamp2โ,0);
SetTagBit(โlamp3โ,0);
SetTagBit(โlamp4โ,0);
SetTagBit(โlamp5โ,0);
}
if (value == 2)
{
SetTagBit(โlamp1โ,0);
SetTagBit(โlamp2โ,1);
SetTagBit(โlamp3โ,0);
SetTagBit(โlamp4โ,0);
SetTagBit(โlamp5โ,0);
}
if (value == 3)
{
SetTagBit(โlamp1โ,0);
SetTagBit(โlamp2โ,0);
SetTagBit(โlamp3โ,1);
SetTagBit(โlamp4โ,0);
SetTagBit(โlamp5โ,0);
}
if (value == 4)
{
SetTagBit(โlamp1โ,0);
SetTagBit(โlamp2โ,0);
SetTagBit(โlamp3โ,0);
SetTagBit(โlamp4โ,1);
SetTagBit(โlamp5โ,0);
}
if (value == 5)
{
SetTagBit(โlamp1โ,0);
SetTagBit(โlamp2โ,0);
SetTagBit(โlamp3โ,0);
SetTagBit(โlamp4โ,0);
SetTagBit(โlamp5โ,1);
}
C Action Script User Administration configuration
YouTube-User Administration configuration WinCC Siemens HMI
WinCC AlarmControl is a message window used to display message events. All messages are displayed in a separate message line. The content of the message line depends on the message blocks to be displayed.
c-action script for login button
————————————-
#pragma code (โuseadmin.dllโ) #include โPWRT_api.hโ #pragma code() PWRTLogin(โcโ);
——————————————————————————————————————–
c-action script for logout button
————————————–
#pragma code (โuseadmin.dllโ) #include โPWRT_api.hโ #pragma code() PWRTLogout();
VB Action script for ANIMATION TRIGGER CONFIGURATION
YouTube:-ANIMATION TRIGGER CONFIGURATION WinCC Siemens HMI
——————————————————————————————————————–
TRIGGERED OBJECT SCRIPT
If item.Left < 800 Then
item.Left = item.Left +2
HMIRuntime.Trace โAnimationtriggerโ & vbCrLf
Else
item.Left = 70
End If
——————————————————————————————————————–
START BUTTON
Dim objani
Set objani = ScreenItems(โobj nameโ)
objani.ActivateDynamic โLeftโ, โCycleTime125msโ
——————————————————————————————————————–
STOP BUTTON
Dim objani
Set objani = ScreenItems(โobj nameโ)
objani.DeactivateDynamic โLeftโ
USER ARCHIVE | RECIPE CONTROLWinCC/User Archives Overview
Option for SIMATIC WinCC for managing data sets in user archives that contain related data. WinCC and its automation partners (e.g. a SIMATIC S7 controller) write these data sets and exchange them if required. A license is only required for the server (or single-user system). The WinCC/User Archives option can also be used in the context of the WinCC/WebNavigator
Tags
โโโโโโโโโโโโโโโโโโโโโโโโโ
@UA_Recipe_ID Signed 32-bit value @UA_Recipe_Job Signed 32-bit value @UA_Recipe_String Text tag 8-bit character set
@UA_Recipe_Data1 Floating-point number 64-bit IEEE
@UA_Recipe_Data2 Floating-point number 64-bit IEEE
@UA_Recipe_Data3 Floating-point number 64-bit IEEE
โโโโโโโโโโโโโโโโโโโโโโโโโ-
UPLOAD Data to Archive
โโโโโโโโโโโโโโโโโโโโโโโโโโ
#pragma code(โkernel32.dllโ); void GetLocalTime(SYSTEMTIME* lpst); #pragma code(); SYSTEMTIME date; UAHCONNECT hConnect; int a = GetTagWord(โ@UA_Recipe_IDโ); char* b = GetTagChar(โ@UA_Recipe_Stringโ); double c = GetTagDouble(โ@UA_Recipe_Data1โณ); double d = GetTagDouble(โ@UA_Recipe_Data2โณ); double e = GetTagDouble(โ@UA_Recipe_Data3โณ); GetLocalTime (&date); if ( uaConnect( &hConnect ) ) { UAHARCHIVE hArchive; if ( uaQueryArchiveByName( hConnect, โRecipeโ, &hArchive ) ) { if ( uaArchiveOpen( hArchive ) ) { uaArchiveSetFieldValueLong( hArchive, 0, a ); uaArchiveSetFieldValueString( hArchive, 1, b ); uaArchiveSetFieldValueDouble( hArchive, 2, c ); uaArchiveSetFieldValueDouble( hArchive, 3, d ); uaArchiveSetFieldValueDouble( hArchive, 4, e ); uaArchiveSetFieldValueDate( hArchive, 5, &date ); if ( uaArchiveInsert( hArchive ) ) { printf( โInsert (%d) successfull.rnโ, a ); } else { printf( โInsert (%d) failed.rnโ, a ); } uaArchiveClose( hArchive ); } else { printf( โOpen failed.rnโ ); } uaReleaseArchive( hArchive ); } else { printf( โQuery failed.rnโ ); } uaDisconnect( hConnect ); } else { printf( โConnect failed.rnโ ); }
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
Delete Data from Archive
โโโโโโโโโโโโโโโโโโโโโโโโโโ-
UAHCONNECT hConnect; char filter[80] = โโ; int a = GetTagWord(โ@UA_Recipe_IDโ); if ( uaConnect( &hConnect ) ) { UAHARCHIVE hArchive; if ( uaQueryArchiveByName( hConnect, โRecipeโ, &hArchive ) ) { if ( uaArchiveOpen( hArchive ) ) { sprintf ( filter, โ%s%iโ, โID = โ, a ); if ( uaArchiveDelete( hArchive, filter ) ) { printf( โDelete: %s successfull.rnโ, filter ); } else { printf( โDelete failed.rnโ ); } uaArchiveClose( hArchive ); } else { printf( โOpen failed.rnโ ); } uaReleaseArchive( hArchive ); } else { printf( โQuery failed.rnโ ); } uaDisconnect( hConnect ); } else { printf( โConnect failed.rnโ ); }
โโโโโโโโโโโโโโโโโโโโโโโโโโโ-
You can delete, change or create a new record without the Control.
Therefore the UserArchives have JobTags.
1. Enter the ID for the record you want to execute.
2. Enter the Job:
6 = Read a record from the process
7 = Write record to process
8 = Delete the record Or click on the Buttons. They will do step 2 for you.
C-Action Script for RUNTIME DEACTIVATION BUTTON CONFIGURATION
YouTube:-RUNTIME DEACTIVATION BUTTON CONFIGURATION WinCC Siemens HMI
Screen text
Are you sure to deactivate the runtime session?
If you agree push the โDeactivateโ button.
C-Action Script DEACTIVATION BUTTON
โโโโโโโโโโโโโโโโโโโโโโโโโโ-
{
char szDeaktivatePicture [260];
char* pszObjectname = NULL;
HWND hWnd = NULL;
int i = 0, j = 0, n = 0;
char pic_name[256] = โโ;
char obj_name[260] = โโ;
memset(szDeaktivatePicture , 0, 260);
strncpy (szDeaktivatePicture, lpszPictureName,259);
pszObjectname = strrchr(szDeaktivatePicture, โ.โ);
if (pszObjectname)
*pszObjectname = โ;
hWnd = FindWindow(โWinCCExplorerFrameWndClassโ,NULL);
if (hWnd)
{
DeactivateRTProject ();
}
else
{
DMExitWinCC();
}
// Close Dialog
n = strlen( lpszPictureName );
if (255 < n)
n = 255;
for ( i = n; i > 0; iโ )
if ( lpszPictureName[i] == โ.โ )
{
strncpy( pic_name, lpszPictureName, i );
strcpy( obj_name, &lpszPictureName[i+1] );
for ( j = 0; j < (n-i); j++)
if ( obj_name[j] == โ:โ )
{
obj_name[j] = โ;
break;
}
SetVisible(pic_name,obj_name,FALSE);
break;
}
}
โโโโโโโโโโโโโโโโโโโโโโโโโโ-
CANCEL BUTTON
โโโโโโโโโโโโโโโโโโโโโโโโโโ-
{
int i = 0, j = 0, n = 0;
char pic_name[256] = โโ;
char obj_name[260] = โโ;
n = strlen( lpszPictureName );
if (255 < n)
n = 255;
for ( i = n; i > 0; iโ )
if ( lpszPictureName[i] == โ.โ )
{
strncpy( pic_name, lpszPictureName, i );
strcpy( obj_name, &lpszPictureName[i+1] );
for ( j = 0; j < (n-i); j++)
if ( obj_name[j] == โ:โ )
{
obj_name[j] = โ;
break;
}
SetVisible(pic_name,obj_name,FALSE);
break;
}
}
GLOBAL SCRIPT FOR INCREMENT AND DECREMENT SWITCH
YouTube Video:-INCREMENT AND DECREMENT SWITCH WinCC Siemens HMI
VB Script for INCREMENT BUTTON:-
โโโโโโโโโโโโโโโโโโโโโโโโโโ-
โdefining VB Variable
Dim VBVar
โReading tag value
Set VBVar = hmiruntime.Tags(โtag nameโ)
VBVar.Read
โChainging Value
VBVar.value = VBVar.value + 1
โwriting back to tag
VBVar.write
โโโโโโโโโโโโโโโโโโโโโโโโโโ-
VB Script for DECREMENT BUTTON:-
โโโโโโโโโโโโโโโโโโโโโโโโโโ-
โdefining VB Variable
Dim VBVar
โReading tag value
Set VBVar = hmiruntime.Tags(โtag nameโ)
VBVar.Read
โChainging Value
VBVar.value = VBVar.value + 1
โwriting back to tag
VBVar.write
Useful Links:-