zhouw
Hello! I am using OpenPLC, which is very awesome. Thanks for your great contribution.
But lately, I met some problems. 

I've downloaded Helloworld project from  http://www.openplcproject.com and now trying to edit it using PLCopen Editor(latest version 1.2 for linux). For some reasons, I need to create two (or more)programs(using LD language) in one project. I've tried to create another program based on Helloworld project and added some variables into that program. Then I specified the locations of those variables(eg.%QX0.0). PLCopen Editor successfully generated ST file. But when I uploaded that ST file to OpenPLC Server, the server told me that there were redefinitions. What‘more, the server said ‘program compiled without errors’ but it did not update PLC program(it still runs the previous PLC program).

It seems like that locations specified in program2 conflict with those specified in program1. I need to use those locations(eg.%QX0.0) in program2 and program1. But I don't know how to solve these conflicts. Can you tell me how to fix these conflicts? I am new to PLC and LD language. 

Thank you so much! My program and some screenshots are pasted below.  Screenshot from 2018-02-03 15-59-12.png  Screenshot from 2018-02-03 15-58-47.png  Screenshot from 2018-02-03 15-58-11.png 

p.s. English is not my mother language, so please ignore spell and grammar mistakes. 
Reply 0 0
thiagoralves
First, you need to make sure that there is an instance and a task associated with your new program for it to run. Just go to Config0->Res0 on the left panel to see the instances and tasks window. You will see that there is one task created for the hello world program that runs every 50ms. You will need to create another task similar to that one for your new program. Also, you will need to create an instance that associates the task with the program.

About the variable conflict, having two different programs to work with the same variable is tricky. They can go into a racing condition which is a big problem in computer programs, so beware. The right way to do this is to setup a global variable. You setup global variables in the same screen you setup the tasks and instances (Config0->Res0). The first upper portion of the window is for you to create your global variables. Create your global variable by clicking on the green plus sign ("+"). Then, for each program that you want to use that variable, just add a variable with the same name and select External for the Class. Make sure that the type also matches your global variable otherwise you will get a type mismatch error during compilation.

I can see a racing condition happening on your example. For the first cycle, one program is trying to setup %QX0.0 to false and the other is trying to set it up to true. Since you can't have both at the same time, you will see %QX0.0 oscillating between false and true.
Reply 0 0
zhouw
thiagoralves wrote:
First, you need to make sure that there is an instance and a task associated with your new program for it to run. Just go to Config0->Res0 on the left panel to see the instances and tasks window. You will see that there is one task created for the hello world program that runs every 50ms. You will need to create another task similar to that one for your new program. Also, you will need to create an instance that associates the task with the program.

About the variable conflict, having two different programs to work with the same variable is tricky. They can go into a racing condition which is a big problem in computer programs, so beware. The right way to do this is to setup a global variable. You setup global variables in the same screen you setup the tasks and instances (Config0->Res0). The first upper portion of the window is for you to create your global variables. Create your global variable by clicking on the green plus sign ("+"). Then, for each program that you want to use that variable, just add a variable with the same name and select External for the Class. Make sure that the type also matches your global variable otherwise you will get a type mismatch error during compilation.

I can see a racing condition happening on your example. For the first cycle, one program is trying to setup %QX0.0 to false and the other is trying to set it up to true. Since you can't have both at the same time, you will see %QX0.0 oscillating between false and true.


Hi, thiagoralves. Thanks for your quick and patient reply. How hard-working man you are!
I've tried to add instance and task for the program I created. I do that by means of imitating Helloworld project. However, the redefinition error remains. I don't know whether I did that wrong. My project is attached below. I will keep trying.
As for the race problem, thanks for your kind and patient remind. I will set some FLAGs to ensure that two programs won't be executed at the same time(please forget the example project I posted. It's just an example.).
Thanks for your patient reply again!
zip  test2Programs.xml.zip      
Reply 0 0
thiagoralves
The redefinition error appears because you should use a global variable as I explained before. 
Reply 0 0
zhouw
thiagoralves wrote:
The redefinition error appears because you should use a global variable as I explained before. 


Thank you. I see. I will use other methods to do that. Thanks for your patient reply again.
Reply 0 0
thiagoralves
I fixed your program. That’s the right way to do it. You shouldn’t create another resource to add your second task, all your tasks must be placed on the same resource. Also, I added a global variable as I explained before on both programs. I don’t know if it has the functionality you wanted due to the racing condition I mentioned, but at least it compiles and runs just fine.
Reply 1 0
Reply