Library placeholders allow to reference multiple versions of the same library in a PLC project. This situation can be helpful if a library has to be updated in an existing project due to new functions, but the update turns out to give an older FB a changed behavior.Continue reading “IEC 61131-3: Different versions of the same library in a TwinCAT project”
IEC 61131-3: Abstract FB vs. Interface
Function blocks, methods and properties can be marked as abstract since TwinCAT V3.1 build 4024. Abstract FBs can only be used as basic FBs for inheritance. Direct instantiation of abstract FBs is not possible. Therefore, abstract FBs have a certain similarity to interfaces. Now, the question is in which case an interface and in which case an abstract FB should be used.Continue reading “IEC 61131-3: Abstract FB vs. Interface”
IEC 61131-3: Exception Handling with __TRY/__CATCH
When executing a program, there is always the possibility of an unexpected runtime error occurring. These occur when a program tries to perform an illegal operation. This kind of scenario can be triggered by events such as division by 0 or a pointer which tries to reference an invalid memory address. We can significantly improve the way these exceptions are handled by using the keywords __TRY and __CATCH.
Continue reading “IEC 61131-3: Exception Handling with __TRY/__CATCH”
IEC 61131-3: Parameter transfer via FB_init
Depending on the task, it may be necessary for function blocks to require parameters that are only used once for initialization tasks. One possible way to pass them elegantly is to use the FB_init() method.
Continue reading “IEC 61131-3: Parameter transfer via FB_init”
IEC 61131-3: The generic data type T_Arg
In the article The wonders of ANY, Jakob Sagatowski shows how the data type ANY can be effectively used. In the example described, a function compares two variables to determine whether the data type, data length and content are exactly the same. Instead of implementing a separate function for each data type, the same requirements can be implemented much more elegantly with only one function using data type ANY.Continue reading “IEC 61131-3: The generic data type T_Arg”
IEC 61131-3: Unit-Tests
Unit tests are an essential tool for every programmer to ensure functioning of his software. Software bugs cost time and money, so you need an automated solution to find these bugs and preferably before the software is used. Unit tests should be used wherever software is professionally developed. This article is intended to provide a quick introduction and allow an understanding of the benefits of unit tests.Continue reading “IEC 61131-3: Unit-Tests”
IEC 61131-3: Extend UNION via inheritance
In the post IEC 61131-3: Additional language extensions, I briefly described the UNION. A reader comment has pointed out to me the possibility, that a UNION can also be expanded by EXTENDS. Since this simplifies the handling of a UNION and the norm does not indicate that, I would like to introduce this possibility in a (very) short post. Continue reading “IEC 61131-3: Extend UNION via inheritance”
IEC 61131-3: Parameter transfer via parameter list
Parameter lists are an interesting alternative for transferring parameters to PLC libraries. Strictly speaking, these are global constants (VAR_GLOBAL CONSTANT) whose initialization values can be edited in the Library Manager.
Continue reading “IEC 61131-3: Parameter transfer via parameter list”
IEC 61131-3: Additional language extensions
The focus of my post has been the object-oriented extensions so far. But there are several general, usually not so far-reaching innovations within TwinCAT 3. Below, they are briefly described.Continue reading “IEC 61131-3: Additional language extensions”
IEC 61131-3: Methods, Properties and Inheritance
Object-oriented programming (OOP) is a proven way of keeping the complexity of software systems in check. Until recently the preserve of languages such as C++, Java and C#, IEC 61131-3 introduces the concept to PLC programming.
Continue reading “IEC 61131-3: Methods, Properties and Inheritance”