Jad Sebti
Hi,

I've been working with OPENPLC for a time now. And I've made work some individual programms.
Right now I'm trying to activate my outputs with memories in a Ladder program and I cannot link it to my grafcet progam.

I've been trying Global (external) values but each time I have a beremiz error. 

Thank you for your help. 
Quote 0 0
thiagoralves
I would strongly recommend against global variables. If not used correctly, they can create more problems than solutions, and are sometimes viewed as "digital hot-glue". If you still want to create global variables, this is how you do it: https://openplc.discussion.community/post/how-to-use-global-variables-10399118?highlight=global&pid=1310476150

I believe your biggest issue is that you haven't understood yet the concept of POUs from IEC 61131-3. You have created 3 programs, where instead you should have created only one main program and have the other subroutines created as function blocks or functions. This is the right way to do. Then, to link the variables from your subroutines to your main program, you just drop the subroutine block on your main program and all input and output variables will appear as pins to connect the variables.
Quote 0 0
Oysterguys
Hello, I'm having a similar problem. I have a GRAFCET and i'm using variable action block to indicate in which step I am. I'd like to use these steps variable as input for ladder logics. After reading this post I figured something like this would work. I dont understand why X2 isnt linked to MONPOU0.X1 . thanks for your timely and square answers Mr Alves.ss3.png  ss5.png 
Quote 0 0
thiagoralves
It is hard to debug your program from a screenshot... Can you attach the full code here?
Quote 0 0
Oysterguys
It's a modified version of jad's project.
Thanks again
Quote 0 0
thiagoralves
You're trying to add a function block to a SFC program. You can't do this. The compiler is ignoring your monPOU block in the SFC program and it never gets executed. SFC can only contain state machine chart logic. Functions and function blocks are meant for Ladder, FBD and Structured Text programs.

Also, since you're using Ladder for your monPOU block, the correct way of having x2 and x3 to receive the value of x1 in ladder logic is:
Capture.png 
Quote 0 0
Oysterguys
Is it possible to make my SFC Interact with ladder logic?

I'm trying to convert a schneider code that use a main SFC with ladder logic running in parallel. The ladder has "step variables" that allow it to
know the state of the SFC.

Thank you Mr.Alves
Quote 0 0
thiagoralves
Create the SFC as a function block (not as a main program) and then drop it in the ladder logic program. Then you can connect all ladder logic variables to the inputs and outputs of your SFC block.
Quote 0 0
Oysterguys
I tried what you told me to do and it work fine for a ''Proof of concept'' 2 step SFC with very basic ladder logic. When I try to convert the actual, way bigger, SFC    I get a weird beremiz python crash. I added the project to my message.
    ss6.png 

My project wouldn't be possible without your timely and helpful answer, and I thank you for that.
Quote 0 0
Oysterguys
Hello, i'm still working on it,  i'm starting to think that maybe openPLC has limits to the amount of variables or tho the size of a single POU?
Quote 0 0
thiagoralves
There isn't any known limitation in how big your program can be. I've seen reports from people saying that the editor got quite sluggish with really large ladder diagrams (1000 elements or so). The recommendation for that is to just break down the main program in sub functions.

About the error you're facing, I opened your program on my machine and couldn't reproduce this problem. Can you provide step-by-step details on how to reproduce the error?
Quote 0 0
Oysterguys
So you were able to simulate/compile it? When we press compile or debug the program become unresponsive and we have to force close it (on windows 10 and 7)


Thank you
Quote 0 0
thiagoralves
Ah, so the problem is when you tried to compile it? I checked it, and in fact, when the compilation process starts, it hangs on the internal compiler MatIEC. Usually these things happen when there is a compilation loop going on (a variable or process that depends on another variable or process that depends on the initial variable or process). A quick look at your program showed me that you have a function block called "urgence" that has an input variable also called "urgence". This is a loop situation, as the compiler is trying to insert the function block inside itself forever.

There might be other errors as well, I haven't fully checked it. Just wanted to give you heads up with that.
Quote 0 0
thiagoralves
After renaming all multiple "urgence" variables and function blocks, and also adding two variables that were used but never declared in your general program (SB_INTERGRAFCET and SB_FIRSTRUN) I can confirm that your code compiles and runs on the simulator. Attached is the modified and working project.
Quote 0 0