

If you choose to put that code in an action called from the function block's primary code that's fine, because it has the same variable scope as the function block it is called from. I would just pass the address of whatever variable(s) to the instance of the function block when you call it, and internal to the function block and its code you access that memory space and do whatever you please to it. Yes, you can use an action inside a function block because ultimately that function block is just some code and variables, so the purpose of the action being called by the function block's primary code is again just a means of code organization.Ĭreating a reference variable at the program level, setting it equal to the address of some function block right before calling the function block, then calling the function block, followed by the function block calling the action, the action then reads the address just set, and accesses the function block and its variables that way To add to that, do you know if it's possible inside a function block to get access to function block itself, like a 'this' type keyword other languages might have? This would make it slightly more convenient to pass an address of the current function block around to other actions or function blocks. I'm new to this so if that's a ridiculous way to do this just let me know. I could potentially see doing something like creating a reference variable at the program level, setting it equal to the address of some function block right before calling the function block, then calling the function block, followed by the function block calling the action, the action then reads the address just set, and accesses the function block and its variables that way. There is probably a better way to do this, but. This may not make any sense to do, but would it be possible to call an action inside a function block? I see an action has access to the variables of the program, but not sure how/if it would be possible to access function block variables from inside an action. That's a great response and your example use cases make a lot of sense. Not that I’ve done this, but an example could be calling an action with a bunch of structured text calculations from a ladder routine. If it wasn’t organized this way, you’d have a ton of code all in 1 routine and the sequence at a glance would be harder to break down into its individual steps and the code associated with them.Īs the help states too, they allow you to write chunks of code in one language and call it from a routine written in another language. They can be powerful for state machines/CASE statement sequences so your debugging of the sequence is all high level until you drill down into a specific step’s code, at which point you open that step’s action. In this way you can call this code wherever you like throughout your main routine, and only have to change the action code in one place while being able to give the action a name that is sensical like Initialize_Outputs or something. I have primarily used them where I have duplicate code that I use in various places, but not to an extent where a function or function block are warranted, like changing the state of a handful of IO. I have used them only in structured text, and it is worth noting as the help says that in other languages there are qualifiers that affect how the action works. Please click "report" on spam Related sub-reddits:Īctions are indeed just another method of organizing code. (*) At mods' discretion, certain self-promotion submissions from people who contribute to this sub in other ways may be allowed and tagged with the "Self-promo" flair

Job offers and requests go to the weekly thread.No shit posts (memes - pictures with superimposed text - are OK).

If asking a question, ask the actual question, fully yet concisely, right in the title.Be civil: do not insult no all-caps, no excessive "!" and "?", please.Job announcements (oustide the monthly job thread).Single Board computers: r/Raspberry_pi, r/Arduino, r/linux_devices, r/linuxboards.Hardware design that does not include a PLC for electronic circuits: /r/AskElectronics.PLC internship, employment and education questions.Homework help but make it clear it's homework.This sub is dedicated to discussion and questions about Programmable Logic Controllers (PLCs): "an industrial digital computer that has been ruggedized and adapted for the control of manufacturing processes, such as assembly lines, robotic devices, or any activity that requires high reliability, ease of programming, and process fault diagnosis." On topic subjects
