Is it possible to declare shared variables between different PLC programs? I currently have a C++ program and a C program that I would like to implement some mechanism for inter-process communication. If I declare a variable as _GLOBAL in a shared package. Would this variable be a single instance shared across both programs, or would it be 2 different instances?
to avoid confusion in regards to that, I recommend one of two global variables using the var files: put either both programs into the same package and create a package global variable file there or use a project wide global var file and declare the variable there.
That way it’s always clear that only that one variable exists - since there is always only one place it’s declared in.
If you insist on doing it via “_GLOBAL”, the answer is… well, easily to be determined with only a small example project and the simulation. I’ll not spoiler the answer
Thanks. I am trying to add the global variable into the global.var file of my project. I am getting another error due to another global variable in the globarvar.h file that I include in the C++ file. The error is “array type has incomplete element type”. Does anyone know how to resolve it? I presume we need to include <globalvar.h> in the file where we use the global variable?
Using the default include mechanism, you don’t have to add header files manually for globals or var files at all.
Your code should already have this:
Right click on the AsDefault.h and click “Open header file” - you should hopefully see, what I mean. (You can dive in even deeper to see what else is included automatically)
For your issue, unfortunately this isn’t enough for me to see what you are doing.
Maybe not including those auto-generated header files manually already solved it (since it also takes care of the proper inclusion order) does the trick