Jump to content

PyBlockFunction Help in Python BLock

Recommended Posts

Hello Guys,


While checking the PyCustomBlock, the skeleton python code  has this section:

import hwx.activate.apis
import numpy
def PyBlockFunction(block,flag):
	apis = hwx.activate.apis
	if flag == apis.vssBlockInitializeFlag():
	elif flag == apis.vssBlockReinitializeFlag():
	elif flag == apis.vssBlockTerminateFlag():
	elif flag == apis.vssBlockOutputUpdateFlag():

I try to find the description and parameter meanings of PyBlockFunction, vssBlockOutputUpdateFlag, vssBlockInitializeFlag but there no info inside the Help

Please share some info if you know.





Share this post

Link to post
Share on other sites

Hi Thinh,


If you take a look at the C, Oml and Python Custom Blocks, you will se that they have a similar structure, telling about these flags and logics. 


Basically the flag is the way that the simulator tells the block what operation needs to performe (usually these jobs consists in updating some of the fiels of the block structure).


Regarding to Initialization, generally speaking it is not used (once the states are usually initializated during evaluation), unless you have to read an write data from files on this code, or even if you require dinamically allocated memory. With respect to Reinitialize, you should think that right after the initialization, the inputs to the block may change from one call to the next, and this state it imposes constraints at the initial time, if successful, these call lead to the convergence of the states and inputs. In the Terminate, the simulator calls each block's computational function, this is useful to flush buffered data  for closing files that have been opened by blocks ate the beginning or during the simulation. Finally, the OutputData requests the output of the block! 


As you can see, this explatation is more based on "internal" computational functions, what I'd like to tell you that, depending on your model (mostly of them) you can simulate just using OutputData. I'm attaching an example model that you can see it.


Hope this helps.





Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...