12/3/2019 4:14 PM | |
Joined: 9/23/2005 Last visit: 8/13/2024 Posts: 4347 Rating:
|
Hi, Introduction As from the TIA V16, there was the introduction of the WinCC Unified. This is an engineering platform for HMI Comfort Unified and for WinCC Unified PC. It brings many news regarding the WinCC Advanced / WinCC Professional. WinCC Unified uses JavaScripting as scripting language. It is different as the scripting language of the WinCC Basic/Confort/Advanced/Professional (VB, C) and it is natural that the user needs some helps to changes the mindset to the new language. I open this post to collect and share general TIP’s for WinCC Unified Scripting and help these users. First contact with JavaScript TIP: for a first contact on JavaScripting, I suggest to access the sitehttps://javascript.info. It is not direct to WinCC Unified particularities, but it has a tutorial divided in topics that could be used as getting started. TIP: the manual "SIMATIC WinCC WinCC Engineering V16 - Runtime Unified" (https://support.industry.siemens.com/cs/br/pt/view/109773780/en), chapter 7 "Programming scripts (RT Uni)" give an good overview and show specific topics regarding JavaScript in WinCC Unified environment. In special, chapter "7.5 Examples (RT Uni)' give exaples of scripts. The same contends are also avaliable in the TIA V16 System Help. TIP: the Application & samples "SIMATIC WinCC Unified - Tips and Tricks for Scripting (JavaScript)" (https://support.industry.siemens.com/cs/br/pt/view/109758536/en) shows an overview of important tips about the topic, and include also a programm style guide. Helpers TIP: snippets: with the right mouse click on the scripting editor area you can access the menu with code snippets (logics like if..else or HMI Runtime specific general used functions). It helps to type text and to get know how the syntaxes works. TIP: intellisense: pressing ctrl + space on the scripting editor area will open list with usable keywords that could be used (match) in the mouse focus position. This list is also called if you type a “.” after an object that has sub items. TIP: converting system function: it is possible to call system functions on an event and convert it to JavaScript (not vice-versa) by clicking on the button “Converts the function list to a script”. IT is also to possible to call a System function inside a scripting. Both technics could be used as helper to develop scripting, where it is necessary just to adapt a system function to a specific target. TIP: in the top/left side of the script editor there is a button the check the syntaxes Scripting types The WinCC Unified JavaScript could be configured as global or local. Local Scripting Local scprits are linked to one specific screen object, in the object properties or in the object events. Although local scripts belong just to their own object, there is a global definition area where definitions can be shared with all screen objects to which the object belongs. TIP: In the script editor there is a button on upper side that changes between "Global definition" and "Script functions" Global Scripting E.g. the scripts are local, that means, belongs only to the property or event where it is created. Scripts / constants defined in Project tree, under scripts, Global modules are global, i.e. could be used everywhere, like a system function, since it is imported in a Screen global definition area. TIP: before to write codes, thinks carefully where makes more sense to place them: in a Global module (i.e. belongs to whole device), in a Screen global definition (i.e. belongs to all objects of a specific screen) or directly on an object event/property. TIP: on the top side of the object scripting editor there is a button that switch between Global definition and script function. This is a way to go to global screen definitions. How to read / write a tag: HMI tags are not only free text but else linked to the database, so a change in the tag definition is automatically match in the scripts. A tag has several properties / values that could be read, like this own value (obvious), but also to the signal quality, etc. So, the tag name could not be used directly in the java script without to refer to with value/property it is pointed. TIP: Tags name could be drag & dropped from the tag table’s Project tree / details view to the scripting, but it could not be used directly in the code without auxiliary codes. To create an object use Let / tag references, for example: Let myObjectReference = Tags (“tag name”); ‘make reference to a tag as object in the java scripting To read / write use object.read / object.right, for example: Let myTagValue = myObjectReference.read(); ‘read the value of a tag and save the value on the create variable myObjectReference.write(0); ‘write zero to a tag It is possible to operate tags directly, without an reference object. Here, for example, the contends of the HMI_Tag_2 is copied to HMI_Tag_1 Tags("HMI_Tag_1").Write(Tags("HMI_Tag_2").Read()); How to invert a bit You can use a compound a read / write tag with the logical operand not (!) to invert a bit in this simple way, like this example: let tag1 = Tags("myTag"); tag1.Write( ! (tag1.Read() ) ); How to change an object property of a screen (snippets>HMI Runitme>Screen> Change screen item property in current screen) Screen.Items(“object name”).’property name’ = value ; Debugging There are two helper tools for scripting debugging in WinCC Unified: Debugger and Trace viewer Debugger:It is activated in runtime manager and can be accessed by web browser. There is two independent web pages: one for screens debugging and the other one for schedule degugging. Both are called by localhost, but each one has an own port number. (URL http://localhost:”port number”, e.g.http://localhost:9222andhttp://localhost:9224) The ports numbers are defined in the SIMATIC Runtime Manager, on the Runtime Settings (gear), tab Script Debugger settings (it should also be enabled and saved in the first time). With this one it is possible to debugging scripting in the run timing inserting break points and monitoring the values of the tags during the script’s execution, for example. The debugger shows a list of active scripting on the screen. It should be reloaded on screen change. Trace Viewer:The Trace Viewer show system messages and the messages wrote in the scripting by the instruction “HMIRuntime.Trace(“text”)”. The Trace Viewer is installed with WinCC Unified at C:\Program Files\Siemens\Automation\WinCCUnified\bin\RTILtraceViewer.exe. |
Last edited by: Denilson Pegaia at: 12/07/2019 22:28:55Last edited by: Denilson Pegaia at: 12/22/2019 13:38:23Last edited by: Denilson Pegaia at: 01/05/2020 12:11:19Last edited by: Denilson Pegaia at: 01/05/2020 12:12:31Last edited by: Denilson Pegaia at: 01/05/2020 12:59:49Last edited by: Denilson Pegaia at: 01/05/2020 13:05:45Last edited by: Denilson Pegaia at: 01/05/2020 13:06:58Last edited by: Denilson Pegaia at: 01/06/2020 14:57:41Last edited by: Denilson Pegaia at: 01/08/2020 17:43:00Last edited by: Denilson Pegaia at: 02/24/2020 01:04:52Last edited by: Denilson Pegaia at: 02/24/2020 01:09:46Last edited by: Denilson Pegaia at: 09/22/2020 11:50:26Last edited by: Denilson Pegaia at: 11/27/2020 11:34:41the FAQ 10958536 include now a style guide Denilson Pegaia |
|
This contribution was helpful to
31 thankful Users |
1/8/2020 5:53 PM | |
Joined: 9/23/2005 Last visit: 8/13/2024 Posts: 4347 Rating:
|
Script Example 1 = Dynamizing the position of an object TIP: the description original description about link object to tags doesn't match with the script. they was fixed in the project AttachmentScriptExample1.zip (2096 Downloads) |
Denilson Pegaia |
|
1/8/2020 5:54 PM | |
Joined: 9/23/2005 Last visit: 8/13/2024 Posts: 4347 Rating:
|
Script Example 2 = Reading and writing tag values
AttachmentScriptExample2.zip (2017 Downloads) |
Denilson Pegaia |
|
1/8/2020 5:55 PM | |
Joined: 9/23/2005 Last visit: 8/13/2024 Posts: 4347 Rating:
|
Script Example 3 = Change language TIPs:
AttachmentScriptExample3.zip (1399 Downloads) |
Last edited by: Denilson Pegaia at: 01/12/2021 12:00:03added IO field to show the actuall language code Last edited by: Denilson Pegaia at: 01/26/2021 10:57:19Last edited by: Denilson Pegaia at: 01/26/2021 11:00:15Denilson Pegaia |
|
1/8/2020 5:56 PM | |
Joined: 9/23/2005 Last visit: 8/13/2024 Posts: 4347 Rating:
|
Script Example 4 = Dynamically changing the output format of an object TIP: the example description refer to local script global definition and not to a really script global definition TIP: the german comment was translate in this example. AttachmentScriptExample4.zip (1726 Downloads) |
Denilson Pegaia |
|
1/8/2020 5:57 PM | |
Joined: 9/23/2005 Last visit: 8/13/2024 Posts: 4347 Rating:
|
Script Example 5 = Setting the alarm filter more information is available in the application example https://support.industry.siemens.com/cs/ww/en/view/109760056 AttachmentScriptExample5.zip (1538 Downloads) |
Last edited by: Denilson Pegaia at: 07/03/2020 12:25:50Denilson Pegaia |
|
1/8/2020 5:58 PM | |
Joined: 9/23/2005 Last visit: 8/13/2024 Posts: 4347 Rating:
|
Script Example 6 = Creating an alarm subscription
AttachmentScriptExample6.zip (1480 Downloads) |
Denilson Pegaia |
|
1/8/2020 5:58 PM | |
Joined: 9/23/2005 Last visit: 8/13/2024 Posts: 4347 Rating:
|
Script Example 7 = Reading and writing binary files
AttachmentScriptExample7.zip (1551 Downloads) |
Denilson Pegaia |
|
1/8/2020 6:00 PM | |
Joined: 9/23/2005 Last visit: 8/13/2024 Posts: 4347 Rating:
|
Script Example 8 = Reading and writing text files
AttachmentScriptExample8.zip (1724 Downloads) |
Denilson Pegaia |
|
Follow us on