PLC programming using TwinCAT 3 tutorial – part 7

Dear existing & future PLC software developers, I have published part 7 of my free PLC programming using TwinCAT 3 tutorial.

In this part we will go back to basics of IEC 61131-3 and structured text and look into instructions. This will cover IF/ELSE, CASE-switches and FOR/WHILE-loops. We will utilize our knowledge to write a CSV (comma separate value) event logger by using a state machine.

  • Share on:

3 Comments, RSS

  1. Žiga

    How would you go about having just 1 logger in a code that is ran in lets say 2 seperate programs. I have a similar project, where i have 2 programs, in which i have FBs in which i use persistent data storage. But i only want to have 1 persistent data storage funciton block for obvious reasons of not wanting to overlap storage from different FBs since it always stores to the same file. I use the beckhoff’s FB_WritePersistentData which is used inside the FB that implements the interface for data storage.

    – I create a FB that implements the interface.
    – I cyclicly run (lets call it fbStorePersistent) it in MAIN.
    – I inject the interface into the FBs in my 2 programs that I want to use the data storage
    – Since I only want a single fbStorePersistent (we could call it a service I guess?), I decleare and run it in main, and i pass it to the 3 programs via reference VAR_IN_OUT
    – The compiler issues a warning for accessing to VAR_IN_OUT from external context (inside the Programs) for each of the FBs that are going to use the data storage interface

    If I run the fbStorePersistent in MAIN before the other 2 programs which will implement this FB in their respective FBs, is it valid to ignore the message since we are sure that there will always be a reference to it? I am assuming this is the issue because of the FB_init which is a method and will access the VAR_IN_OUT passed to the function blocks ?

    LINK (the issue is described at the bottom of the page):

    Maybe I went about this the wrong way, but I hope you understand what I am trying to achieve.

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.