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:

5 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):
    https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/9007201785048459-2.html&id=

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

  2. Harry Mulder

    Hello Jakob,

    Let me first say how much I enjoy your videos! It’s fantastic that you do this by yourself, and then make it free to all. What you say is very clear and concise, which makes your videos very understandable.

    You can see from my email address that I work for Beckhoff; I’ve only been here just over a year. In my case, I have a background in traditional PLCs (Omron), but TwinCAT is completely different! There’s not a lot of introductory material to TwinCAT, as you’ve mentioned several times.

    Two comments about this video:
    1) Is there a reason you don’t enable Autostart of the boot project? It’s useful setting for live applications, but it may as well be enabled when testing, saving a step and making things less confusing.
    2) At 51:23 in the video, you seemed surprised that your fbFilePuts() didn’t immediately write to the disk. But from my understanding, virtually all file systems will buffer write commands, and only “flush” (i.e. actually write to disk) when they have to eg: the buffer gets full, the file is closed, a flush operation is specifically called, etc. They do this to improve performance – computers can write to memory many times faster than they can write to disk.
    There’s plenty of info available on flush, here’s what StackOverflow says: https://stackoverflow.com/questions/7127075/what-exactly-is-file-flush-doing

    Thanks again Jokob and please keep the good videos coming.

    • Hi Harry. Happy you find my content useful. Yes the automation industry has to get better at sharing knowledge openly. To answer your questions:
      1. The reason is that IF any of my viewers get in a situation where they do a mistake that makes the system blue-screen, the auto-start will (or at least did) make the system get stuck in an infinite loop of restart. But for a production system, then yes you should definately enable the autostart.
      2. You are correct, I had a moment of black-out, but I guess these are just the stuff that happens when you do content “live”/unscripted 🙂 But that also makes me get feedback, like you give me now 🙂

      Thanks for your feedback, really appreciate it!

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.