AS6 ST OOP – How to share a class across multiple programs?

Hi everyone,

I’m currently working with Automation Studio 6.7.1.5 and trying to understand how ST OOP classes can be shared across multiple programs within the same project.

I would like to declare a class only once (for example, LogManager) and make it accessible from any program in my project, including its public methods, properties, and members.

Ideally, I would like to declare a global instance and access it from different programs:

// Program A
gLogger.Info(...);

// Program B
gLogger.Warning(...);

// Program C
gLogger.Error(...);

However, it seems that .cls files must belong to an ST OOP Program and that classes are only accessible within their containing program.

My questions are:

  1. Is there a way to declare an ST OOP class at the project level so it can be used by multiple programs?

  2. Can I declare a global instance of an ST OOP class and access its public methods from different programs?

  3. If this is not currently supported, is there a recommended workaround or any plan to support it in future AS6 versions?

I’m trying to build a modular, reusable architecture without having to duplicate class definitions or create separate ST OOP programs just to expose functionality.

Thanks in advance for your help!

Hello! I’m not privy to any future features, so anyone with updated knowledge, please correct me.

OOP ST gets tran-spiled to C++. My understanding as of today is that it has the same rules as C++, which is that objects cannot cross task boundaries. There are memory constraints that make this the case in the current underlying C++ implementation where each task has its own heap, which makes memory management across tasks separate. I don’t know if there are other reason or if there are plans to change this, but you do need be careful with any work arounds, which there are many, with varying degrees of acceptability.

To communicate across tasks you can use global variables, just like any other task, but not with OOP objects. If you have used C++ it is a very similar pattern, with OOP ST having the benefit of supporting the watch window and other B&R services out of the box.

As far as sharing classes across tasks, (I assume, but have not tried) that you can reference the ST files in your task so that you have one source and the others can use the same code, but again, they are not in fact the same actual class, so they can’t directly communicate since it’s essentially a copy of the class. In your case of the logger, the reference file could work fine, but it wouldn’t be a global, each would get their own instance and it would mainly be a wrapper that talks to the global structure scope, or in the case of a logger, just a wrapper around the event logging system.

Hope this help!

Hi,

Thanks for your response!

I’m trying to find a way to call methods associated with a POU, similar to how it works in CODESYS.

In CODESYS, a POU can contain input, output, and in-out variables, as well as methods defined separately within the POU.

I’d also like to organize my source files into folders, similar to the project structure available in CODESYS.

Is there a way to achieve these two things in B&R Automation Studio?

Thanks for your help!

Best regards,
Steve

I think we need to distinguish between a class and an object.

A class is a definition of data structure with code to work with this data.

With file references this definition can be shared and different objects can be instantiated from it.

Each object lives then independendly from the other objects.

From a global perspective each object in B&R’s current ST OOP implementation is just a data structure, so no member function that can be called (only locally).

Hi,

Thanks for your response!

After more than 30 years of programming experience across different languages and paradigms, including:

  • Hardware Description Languages: VHDL, Verilog, etc.

  • Procedural Programming: C, Assembly, etc.

  • Object-Oriented Programming: C++, C#, etc.

  • Structured Text (ST)

I’m accustomed to organizing code using a clear separation between:

  • Definition files: Containing structures, enumerations, constants, variables, functions, classes, properties, etc.

  • Implementation files: Containing the actual implementation of functions, classes, methods, etc.

  • Declaration files: Where I can declare variables and instantiate the types, function blocks, or classes defined elsewhere.

What I’m trying to achieve in Automation Studio is something similar to what I’ve used in other development environments.

Ideally, I would like to:

  1. Define and implement a module only once, using dedicated definition and implementation files.

  2. Instantiate and use that module from a declaration file, such as <Name>.var, without duplicating its code.

  3. Organize related files into folders, allowing me to group modules and components into a clean, reusable exportable structure.

  4. Ideally, package these modules into precompiled libraries that could simply be linked to other projects, without having to include or recompile the source code each time.

My goal is to build a modular, reusable, and maintainable architecture, where each component is clearly separated from the application code that uses it.

I would appreciate knowing whether Automation Studio supports this approach and, if so, what the recommended project structure would be.

Ultimately, having the ability to create and distribute compiled libraries with well-defined public interfaces would be the ideal solution, allowing us to reuse components across multiple projects while keeping their implementation encapsulated.

Thanks for your help!

Best regards,

Beamcut.zip (33.6 KB)

I’ve created a very simple test case, but I’m getting the following error:

ST OOP is not yet supported for libraries, but it will be supported in upcoming versions.

It seems that enumerations as class mebers are not yet supported …

Unfortunately, we are running a bit behind schedule with the development of ST OOP. This may come as a surprise to some.
However, we have integrated C++ very well into the existing runtime system over the years.
We therefore felt that we didn’t need object-oriented programming in IEC since we had already integrated the market-leading language.

We are well on our way to correcting this, and Automation Studio 6.9 will bring us another step forward in December.

I am in a similar situation to the original poster. Before diving into C++, I would like to know if there are similar limitations compared to ST OOP:

  • Are C++ classes supported? Can they be stored in libraries?

  • Can class instances/objects be instantiated globally so that they are accessible throughout the entire project?

Coming from a Beckhoff TwinCAT 3 background, I took full ST OOP (interfaces, methods, properties) for granted.

Hello Stephan,

with ST OOP, the current state is that not everything has been implemented at the language level yet.

This is not the case for C/ C++. The GNU C++ compiler runs in the background, so there are no real language limitations.

However, the runtime system behaves somewhat differently. As soon as you leave the C++ language level (e.g., watch window, trace, OPC UA, connection with the IEC language environment, etc.), C++ objects no longer exist.

Instead, in AR there are only IEC variables and datatypes. An ‘object’ would be currently implemented as plain structure that does not support method calls.

If you can accept breakpoints in software development then everthing is there since GDB works in background.

Possible approaches include:

  • Writing the entire project in C++. If debugging via breakpoints is not possible, copy or reference the data to IEC variables.
  • Writing individual tasks in C++ and connecting them to other tasks via a standard IEC variable interface. Two separate C++ tasks can communicate using pointers (IEC variables) and thus reference actual C++ objects.
  • Writing function blocks in C++ and using them in IEC languages through the standard IEC function block interface.

I think the online help is a good place to start: ANSI C/C++