0

Alright, so I'm learning codesys in school and I'm using Function-Blocks. However they didn't seem to update when updating local variables, so I made a test, the one you can see below. As you can see, in the FB below, "GVL.sw1" becomes True, but "a" doesen't. Why does it not become True? I tested a friends code and his worked just fine, but mine doesen't...

https://i.stack.imgur.com/IpPPZ.png

Axroxx
  • 53
  • 4

2 Answers2

1

Comment from reddit

You are showing the source code for a program called "main". You have a task running called "Main_Task". The program and task are not directly related.

Is "main" being called anywhere.

So i added main to the "main task" and it worked. I have no idea why it didn't work in the real assignment but maybe I'll solve it now that i have gotten this far.

Axroxx
  • 53
  • 4
0

In your example you have 2 programs (PRG): main and PLC_PRG.

Creating a program doesn't mean that it will be executed/run. For that you need to add the program to a Task in the Task Configuration. Each Task will be, by default, executed on every cycle according to the priority they are configured with (you could also have them be executed on an event and etc. instead). When a Task is executed, each program added to that Task will be executed in the order they are placed (you can reorder them any time).

With that said, if you look at your Task Configuration, the MainTask only has the program PLC_PRG added, so only that program will run. The main program that you are inspecting is never even run.

Guiorgy
  • 1,405
  • 9
  • 26