In this article, I want to highlight a useful and fairly new TwinCAT feature: Stand-alone PLC projects. As usual, Beckhoff’s InfoSys provides a good explanation of how to set up and run such a project from scratch. However, there is little information on why the separation might be a good idea, how to separate an existing project, and some of the pitfalls you might encounter.
This article was first published on the AllTwinCAT blog.
A stand-alone PLC project “makes it possible to separate system, motion and I/O configuration from PLC development at project level”. In other words, the separation can prevent the configuration of one machine from influencing the other. For example, one issue we faced was that on our production machine, we divided tasks over several cores, whereas in our development environments, we often ran all tasks on a single core. It happened a few times that the development environment’s configuration was (partially) uploaded on the production machine, where it caused several issues, as you can imagine.
The problems of the example above were probably caused by an incorrect merge of the combined project. Because the .tsproj file of the combined project contains so much information, which also changes when you, for example, change your target system, it is difficult to avoid mistakes when merging the .tsproj files from different systems.
That’s why separating the projects is a good idea. Creating a separate PLC project from scratch is fairly straightforward but possible only from version 4022.0. First, you create a stand-alone PLC project. Then you create a separate TwinCAT project, where you import the TMC file from the stand-alone project. After that, you can assign the tasks you created in the stand-alone PLC project to the system tasks in the TwinCAT project. Then, you activate your configuration in the TwinCAT project, and you can log into the PLC from the stand-alone project.
Separating an existing TwinCAT 3 project that includes the PLC project is also possible. To do that, you first create a stand-alone project, much like above. You go to File > New Project > TwinCAT PLC Project and select an appropriate name for your project and save location and click OK.
Then select “Empty PLC project” in the following screen. The name doesn’t matter because this project will be replaced by an existing one in the next step. Click OK.
Then right-click on the PLC project and select “Change Project…”. Select the .plcproj file of the PLC project that you want to import.
Then select the appropriate option for what to do with the PLC project files. After clicking on OK, all the files of the selected PLC project should show up in your stand-alone project.
There is one thing that is not copied, and those are custom events. Custom events in a combined project are stored in the .tsproj file and can be found under SYSTEM > Type System > tab Event Classes. I’m not sure what the appropriate way is to get them in the new stand-alone project, but it can be done by copying the events from the combined project’s .tsproj file into the .tsproj file of the stand-alone PLC project.
At this point, I wanted to discuss some problems you might encounter with the creation of a stand-alone project. However, I couldn’t recreate issues I had with a previously combined project, which was later split into a stand-alone PLC and a TwinCAT 3 project. For those who are also experiencing issues, I’ll briefly go into them here.
The issues we faced had to do with custom events. Somehow, whenever we added a custom event to our stand-alone PLC project, they were not added to the .tsproj file but only in the .tmc file (after building, of course). So, whereas .tmc files can typically be added to the .gitignore file, this was not the case for this project.
Related to this issue is that whenever this problematic stand-alone PLC solution file was opened, the custom event classes were not loaded automatically. Only after manually reloading the project file, the event classes would show up.
Perhaps these issues were caused by the fact that the original combined project was created with an older TwinCAT version? Anyway, maybe you’ve experienced similar issues or have some experience with setting up stand-alone projects.
If you have encountered similar issues or have experience with setting up stand-alone projects, please share your insights in the comments below. Your input can help others who are working with stand-alone PLC projects and facing challenges during the process.