AS4 to AS6 migration script

Hi everyone,
We are excited to announce a new community project designed to help our customers transition from AS4 to AS6 more smoothly. Some community members have started developing a script that analyzes an AS4 project and generates a report highlighting potential changes and issues that may arise during the porting process. Here are some important notes about the script:

• The project is open-source and community-based, not an official B&R project.
• The script may not identify all possible issues.
• Support is limited and depends on the availability of contributors.

We encourage everyone to contribute to the script. The project’s first goal is to collect and document as many conversion issues as possible. Please use the GitHub issue page to report conversion issues or feature requests. The second step is to incorporate these issues into the script and generate a report detailing the necessary adjustments for converting to AS6. The third step is to automate some required steps for the conversion process. There are already a few examples of how this could look in the project’s helpers folder.

This thread can be used for general discussions about the script, but please use the GitHub page for reporting conversion issues or feature requests.

Stephan

22 Likes

I think some users who are not experienced with PYTHON would appreciate an exe file with a simple GUI or output to a text file. Just a tip :wink:

5 Likes

Hi,

Even though I’m not directly involved in the development of the script, I believe in the value it brings to all of us working with Automation Studio.

:rocket: Migrating from AS4 to AS6 can be challenging, and this tool has the potential to make that process much smoother. But for it to be truly effective, we need your input! As Stephan mentioned, sharing the issues you encounter during migration is already an incredibly valuable. Every real-world case helps us improve the script and make it more robust for everyone.

3 Likes

I added a GUI version of the script from Michael.

@Michael thx for sharing

3 Likes

Hi all

I just got info that we now have a GUI for our script. It can be downloaded in the latest releases: here

We are still looking for contribution to report migration issues as well as solving them in the script.

Thank you all!

1 Like

Hi @stephan.stricker

I tried to create a new issue for the migration script but got an error message: “Unauthorized: As an Enterprise Managed User, you cannot access this content”

This is the issue I am trying to raise:

After running the “Create mapp folders” script for an AS 4.12 project, the first line of Cpu.pkg gets changed from
<?xml version="1.0" encoding="utf-8"?>
to
<?xml version='1.0' encoding='UTF-8'?>

Double quotes should be used to surround xml attribute values, not single quotes.

That way this is parsed is one and the same from the Automation Studio side. But as this is written just as plain text it should be quite easy to change.

If you only have an ABB enterprise user and want to raise issues/contribute, you would have to create a “standard” non enterprise User that you can use in parallel on Github.
And then use the account switcher to switch back and forth:

Thanks for that note. For AS the quotes should not make a difference. It seems that the issue with the folders if fixed in AS 6.3 so the question is probably if we should remove the folder detection and remove the script entirely.

Hi,
since we still have a lot of customers using Automation Basic I created a conversion script to Structure Text. This script can be selected from migration tool drop down. If you find any issues with this script please create an issue on GitHub with a detailed description of the problem.

Intended use

This script is intended to convert Automation Basic code to Structured Text code. It can be used as a starting point for porting existing Automation Basic code to Structured Text. However, the generated Structured Text code may require manual adjustments and testing to ensure it works correctly in the target environment.

What will be converted

  • Comments of type (* … *) are converted to // comments in Structured Text.

  • Semicolons are added at the end of each statement in Structured Text.

  • Keywords are converted from Automation Basic syntax to Structured Text syntax. For example, if ... then ... else ... endif is converted to IF ... THEN ... ELSE ... END_IF.

  • Lowercase keywords are converted to uppercase keywords in Structured Text.

  • Hex and binary literals are converted to Structured Text format. For example, $FF is converted to 16#FF and %1010 is converted to 2#1010.

  • Convert select statements from Automation Basic to case statements in Structured Text. The select states must be defined with constant values, otherwise the compiler will raise an error for non-constant case values.

  • Convert loop statements from Automation Basic to for statements in Structured Text.

  • Convert case statements from Automation Basic to case statements in Structured Text.

  • Math functions INC and DEC are converted to + 1 and - 1 respectively.

  • Assignment operator = is converted to := in Structured Text.

  • EXITIF statements are converted to IF … THEN … END_IF statements with a RETURN statement inside.

  • Function block calls are converted to Structured Text syntax.

  • String assignments are converted to Structured Text syntax if variable type can be identified.

Usage

Call the script with an complete Automation Studio project folder as argument. The script will search for all .ab files in the folder and its subfolders and convert them to .st files. You can also call the script with a single .ab file as argument to convert only that file.

Example command line usage:


python ab_2_st_converter.py path/to/project_or_file

Command-Line Options

The script supports various command-line switches to disable specific conversion functions. This can be useful when certain conversions are not desired or when you want to run conversions incrementally.

Disabling Conversion Functions

| Switch | Description |

|--------|-------------|

| --no-manual | Disable manual fix notices for unsupported keywords (GOTO, type casts) |

| --no-comment | Disable comment conversion (block comments (* *) to line comments //) |

| --no-keywords | Disable keyword replacements (e.g., ENDIFEND_IF) |

| --no-uppercase | Disable uppercase conversion for keywords (e.g., trueTRUE) |

| --no-numbers | Disable number format conversion (e.g., $FF16#FF, %10102#1010) |

| --no-select | Disable SELECT/STATE/WHEN/NEXT to CASE transformation |

| --no-loop | Disable LOOP/ENDLOOP to FOR/END_FOR conversion |

| --no-math | Disable INC/DEC math function conversion |

| --no-exitif | Disable EXITIF to IF...THEN...EXIT...END_IF conversion |

| --no-semicolon | Disable automatic semicolon insertion at end of statements |

| --no-functionblocks | Disable function block syntax fix (FUB removal) |

| --no-string-adr | Disable conditional ADR wrapping for string assignments |

| --no-string-adr-whitelist | Disable ADR wrapping in whitelisted function arguments (strcpy, memcpy, etc.) |

| --no-equals | Disable = to := assignment operator conversion |

Examples

Convert a project with all default conversions:


python ab_2_st_converter.py path/to/project

Convert a file but skip semicolon insertion and uppercase conversion:


python ab_2_st_converter.py path/to/file.ab --no-semicolon --no-uppercase

Convert a project but disable all string-related ADR conversions:


python ab_2_st_converter.py path/to/project --no-string-adr --no-string-adr-whitelist

Show help with all available options:


python ab_2_st_converter.py --help

Edge case

There are a few Automation Basic constructs that can not be converted automatically to Structured Text. If the conversion script encounters these constructs, it will add a comment starting with ### CONVERSION ERROR ###. Search for these comments after conversion to identify code that requires manual intervention. Below is a list of known corner cases with an explanation and an example code snippet.

Inline function block calls

In Automation Basic you can call function blocks inline as part of an expression. For example:


TON(diff_err_pos,time,diff_str_pos,dif_pos);

This type of call is not supported in Structured Text. You have to create an instance of the function block and call it separately:


my_ton_instance(IN := diff_err_pos, PT := time);

dif_pos := my_ton_instance.Q;

Since the script can not determine the name of the function block instance during conversion, this code can not be converted automatically.

String conversion

In Automation Basic the address of a string and the string itself are interchangeable. For example, you can assign a string variable to another string variable like this:


str_value = 'Hello World'

The variable str_value can be of type STRING or of type UDINT. Both assignments are valid. Structure Text is more strict about types. You have to use the ADR function to get the address of a string:


str_value := 'Hello World'; // str_value must be of type STRING

udint_value := ADR('Hello World'); // udint_value must be of type UDINT

The script will try to identify the variable type and convert the code accordingly. However, if the variable type cannot be determined during conversion this code can not be converted automatically.

Variable casting

In Automation Basic you can cast variables by using the datatype as a function like this:


time_diff := REAL(fub_timebase)*1e-6;

In Structured Text you have to use a cast function that considers the datatype your converting from:


time_diff := DINT_TO_REAL(fub_timebase, REAL) * 1e-6;

Since the source datatype cannot be determined during conversion, this code can not be converted automatically.

Loop without condition

This code snippet can not be converted automatically. Use REPEAT…END_REPEAT or WHILE…END_WHILE instead.


loop

exitif (X < param[i+2]) or (i>=((2*n)-4))

i = i + 2

endloop

GOTO statements

GOTO statements are not supported in Structured Text. You have to refactor the code to use structured control flow instead.

6 Likes

Hi @stephan.stricker , how application module are handled in migration script? based on discussion here Community Thoughts: Application Modules - #29 by kovarj mappServices are not supported for application module in AS6. Can we add this to information to report? or is it already there?