You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old April 8th, 2021, 10:24 AM   #1
Anglebert
Member
Zimbabwe

Anglebert is offline
 
Join Date: Apr 2021
Location: Bulawayo
Posts: 3
Question Warning: Using embedded function blocks in functions can lead to unexpected behavior

Hi,

I'm getting a bunch of these warnings when I build the program in Connected Components Workbench. The program is legacy code. The program runs fine but I cannot clear these warnings without changing the program structure. Should I be worried?
  Reply With Quote
Old April 8th, 2021, 10:54 AM   #2
Toine
Member
Netherlands

Toine is offline
 
Join Date: Nov 2016
Location: NL
Posts: 350
Yes. Check if the function blocks maintain state between consecutive calls. If they don't, then you might be fine. But there still is something wrong in the design of your code.

One fundamental difference between function and function block is that the latter maintains state between consecutive calls. If your function block does not require this, then you could (and should) have used a function instead.

Variables declared inside a function do not maintain state between consecutive calls of the function. If the function blocks inside the function require state to be maintained between two calls then your code may not behave as you would expect.

I apologize if the above is confusing. It is somewhat difficult to describe this in a meaningful way if you don't have a good understanding of the underlying conceptual differences between functions and function blocks. Even more so since English is not my mother tongue, I am not a native speaker.
  Reply With Quote
Old April 8th, 2021, 12:03 PM   #3
saultgeorge
Lifetime Supporting Member
United States

saultgeorge is offline
 
saultgeorge's Avatar
 
Join Date: Jul 2015
Location: Detroit
Posts: 381
Quote:
Originally Posted by Toine View Post
Even more so since English is not my mother tongue, I am not a native speaker.
+1 your English is very good. I tutor ESL and it is fine. Somewhat OT I guess, but anyway you have no reason to apologize. Have a great week!!
__________________
"Instant success teaches one nothing. Failure teaches one everything one needs to succeed."
  Reply With Quote
Old April 9th, 2021, 02:50 AM   #4
Anglebert
Member
Zimbabwe

Anglebert is offline
 
Join Date: Apr 2021
Location: Bulawayo
Posts: 3
Thank you very much Toine for the explanation.

I have understood your point, that User Defined Function blocks are best used in situations where you would like to maintain/save the state. This raises another question for me, what is the best place to call a function block within a program, should I call them within the main program block and avoid calling them within functions?. How best should I structure my program when dealing with function blocks, thank you...

Your English is excellent, we are both not native speakers so don't worry....
  Reply With Quote
Old April 9th, 2021, 04:01 AM   #5
Toine
Member
Netherlands

Toine is offline
 
Join Date: Nov 2016
Location: NL
Posts: 350
The only meaningful thing I can say about that in this context is that function blocks should not be called from inside a function, since a function cannot be relied upon to maintain state between calls. Now which way to go from here depends entirely on what is going on in your function and the function blocks inside.

If you do have function blocks inside a function, there are two ways you can go to resolve the potential issues. Which way to go cannot be determined without looking into the details of the function and the function block(s) inside it.

Either the function block actually does not store state between calls. In that case it is not required to be a function block and should be rewritten to be a function instead.

Or the function block does require to maintain state between two calls. Then the function in which it is called should not have been a function so it should be rewritten into a function block.




Thanks saultgeorge and anglebert on the language. It is nice to know one is understandable
  Reply With Quote
Old April 9th, 2021, 08:18 AM   #6
Anglebert
Member
Zimbabwe

Anglebert is offline
 
Join Date: Apr 2021
Location: Bulawayo
Posts: 3
Okay, it's getting clearer now thank you...
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
MPI comunication Manuel Raposo LIVE PLC Questions And Answers 22 July 16th, 2007 07:24 AM
siemens step 5 function blocks stevelawson LIVE PLC Questions And Answers 38 February 20th, 2007 02:26 AM
Function Blocks blackslipper LIVE PLC Questions And Answers 0 January 4th, 2006 08:42 AM
learning function and data blocks (Step7) Pandiani LIVE PLC Questions And Answers 7 April 27th, 2005 10:56 AM
Siemens step 5 function blocks stevelawson LIVE PLC Questions And Answers 1 February 13th, 2004 08:43 AM


All times are GMT -4. The time now is 07:48 PM.


.