HomeAwzTechVisual Basic and C-Action Script WinCC: How to Write Script

Visual Basic and C-Action Script WinCC: How to Write Script

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).

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

BV ACTION SCRIPT FOR PART MOVEMENT

——————————————————————————————————————–

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);

}


User Administration configuration WinCC Siemens HMI

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

VB Action script for ANIMATION TRIGGER CONFIGURATION WinCC Siemens HMI

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.


Run time deactivaation

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

GLOBAL SCRIPT FOR INCREMENT AND DECREMENT SWITCH WinCC Siemens HMI

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:-

Recent Posts

Popular Posts

Wonderware Intouch 10 Cracked

Wonderware IntouchInTouch software leaps onto your screen with breakthrough technology, amazing graphic capabilities, and comprehensive functionality delivered with Wonderwareโ€™s legendary ease of use. Wonderwareโ€™s...

How to Install Intouch License: Download, Types, Features, Working

Intouch LicenseWonderware is a powerful and widely-used software platform that is used by many businesses and organizations to streamline their operations and increase efficiency....

FactoryTalk View 12: Overview

FactoryTalk View version 12.00 release summaryFactoryTalkยฎ View Site Edition (SE) design improvementsFactoryTalkยฎ View Studio modernizationFactoryTalk View Studio usability enhancementsOrganize graphic displays in foldersSupport remark for numeric entryNew redundant server licenseFactoryTalk...

Popular Softwares

Wonderware Intouch 10 Cracked

Wonderware IntouchInTouch software leaps onto your screen with breakthrough technology, amazing graphic capabilities, and comprehensive functionality delivered with Wonderwareโ€™s legendary ease of use. Wonderwareโ€™s...

Download RSLogix 500 v12

RSLogix 500 is a programming software developed by Rockwell Automation for programming and configuring Allen-Bradley PLCs (Programmable Logic Controllers). It is part of the...

Download RSLogix 500 v11

RSLogix500 Rockwell softwareRSLogix 500 is a software program developed by Rockwell Automation that is used to design, program, and test control systems based on...

FIND MORE