Sign in to follow this  
Followers 0
Marco8037

Making a function block on TWINCAT

3 posts in this topic

Hello everyone. I am new using Twincat and I have developed a little program that make an output blink all the time. The programme code is attached on file picture_1. I put the Twincat on Run mode and I can test the program running. When In turn ON the variable ENABLE, I can see the output BLINK alternating ON and OFF every 500ms. Now, I would like to make the same programme as a function block, but it is my firs function block and I don't know how to do it. Can someone correct me where I am wrong? To do the function block, I select NEW --> Target system type: PC or CX --> Type of POU: Function Block I have defined as VAR_INPUT the following ones: ENABLE - To turn ON the system (alternating the output ON and OFF) TIME_UP - Where I expect to define the time that the output BLINK is ON TIME_DOWN - Where I expect to define the time that the same output is OFF I have defined the VAR_OUTPUT the following one: BLINK - Where I expect see the the output blinking I have declared all the other variables as a VAR. However I have only one POU of type (FB). I have no one POU as type (PRG) When I try to Rebuild all (compile), it gives me an error with the following message: Error 3551: Task configuration (2): The task 'Standard' must contain at least one program call I don't know what to do to solve the problem, because since I have only one POU of (FB) type, I cannot append a Programm call. Could someone help me please?

Share this post


Link to post
Share on other sites
Hopefully my answer will help, as I have only ever used the Turck Programmable Gateways so not sure if everything is exactly the same. However, if you're trying to create a function block to be used over and over again you have 2 choices. You can export it as an export file and then you can import it every time you need it, or you can create a library file that you can include in your project every time. The biggest difference between these two options is that by doing an export, the function block will always show up in your project list with the rest of the programs functions. If you create a library, the function will be "hidden" unless you go to the library manager. Also, if you need the function block to be locked so another user cannot see the logic inside of it, you will need to create a password protected library. Creating an Export Take the any project you already have written, go to the Project Menu -> Export. Then select the function blocks you want to export, click ok, tell it where to save your exp files. Then you have exp files with the function blocks that can be imported in the same manner into other projects. If you ever need to change the export file, then you create a blank project, import the export file, change it, and re-export it. Creating a Library Create a project as you have with no PLC_PRG (no program blocks), create function blocks that you would like, and go to the file menu -> Save As. Then change the "Save As Type" to "Internal Library .lib". Then when you want to re-use the library, you would go to the "Resources" tab and open the "Library Manager". Right click on the libarary list and "Add Additional Library". Then browse to your newly created library and you'll have access to the function blocks and they will not show up in the project browser. If you need to password protect your library, then you set a password in the Project Menu -> Options -> Passwords when you create your library. If you ever need to change your library, then you can by going to file -> Open -> Then change the "Open as type" to library and browse to your library. Hope this helps!!

Share this post


Link to post
Share on other sites
Hello Nick. Yes it has helped a lot. I can now make my own function blocks. Thank you very much. Best regards.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0