Skip to content

Here you can find tipps & Tricks working with simatic ax & code

License

Notifications You must be signed in to change notification settings

simatic-ax/tipps-and-tricks

Repository files navigation

Tips & Tricks with AX Code

Snippets

Simple snippet example

{
    "comment_snippet": {
    "scope": "st",
    "prefix": ["comment, snippet"],
    "body": [
        "/// Block description 2",
        "/// $(1|place here the comment of method)",
        "/// Return value: $2",
        "${name:default}"
    ],
    "description": "Add an Comment;"
    }
}

Result:

snippet1

Loop snippet

{
    "loop":
    {
        "prefix": ["loop"],
        "scope": "st",
        "body":[
            "VAR_TEMP",
            "\t index : ${1|INT,LINT|};",
            "END_VAR",
            "FOR index :=  ${1|INT,LINT|}#${2|0,1,X|} TO ${3:EndValue} DO",
            "\t;",
            "END_FOR;"
        ],
    "description": "create a loop section with VAR_TEMP;"
    }
}

Result:

snippet2

Import global variables

Importing global variables into the VAR_EXTERNAL section of a POU

import

Format ST code

format

Documentation

Currently not productive; it might not always work

Documentation link

docu-link

Further information: Documentation Link

Inline Documentation

In SIMATIC AX you can add comments to your methods or functions with ///

inline-doc

Nice shortcuts

A complete overview of the shortcuts in VS Code/AX Coce you'll find here: VS Code shortcuts

Add selection to next Find match (CTRL+D)

ctrl_d

Insert cursor (Alt+Click)

alt_click

Search & Replace with Regex

regex

Useful search&replace patterns when you want to migrate SCL Code (exported from TIA Portal) into ST:

Search field Replace field Example
Remove all # for variables of a SCL source #([A-Za-z]) $1 #statVariable --> statVariable
Remove all { S7_SetPoint := 'False' ... } {[A-Za-z0-9 :=';_.]*} Bin2 { S7_SetPoint := 'False'} : "typeStatisticsBin"; --> Bin2 : "typeStatisticsBin"
Remove "name" "([A-Za-z]*)" $1
TIA-Type to ST-Type TYPE "([A-Za-z0-9_]*)" TYPE $1 :
Remove " in type declaration "([A-Za-z0-9_]*)" $1

thats's not a migration guide and it's still manual necessary. But it can make the life easier.

Further information

AX Code Documentation

Documentation Link

VS Code Documentation

Snippets collection on GitHub

PLC Open templates

Markdownlint-cli

This workspace will be checked by the markdownlint-cli (there is also documented ho to install the tool) tool in the CI workflow automatically.
To avoid, that the CI workflow fails because of the markdown linter, you can check all markdown files locally by running the markdownlint with:

markdownlint **/*.md --fix

License and Legal information

Please read the Legal information

About

Here you can find tipps & Tricks working with simatic ax & code

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published