Creating Model Callback Functions
Block Callback Parameters
This table lists the parameters for which you can define blockcallback routines, and indicates when those callback routines areexecuted. Routines that are executed before or after actions takeplace occur immediately before or after the action.
| Parameter | When Executed |
|---|---|
| When the block is copied or cut to the system clipboard. | |
| When the block is closed using the close_system command.The CloseFcn is not called when you interactivelyclose the block, when you interactively close the subsystem or modelcontaining the block, or when you close the subsystem or model containingthe block using close_system. | |
| Before the simulation continues. | |
| After a block is copied. The callback is recursive forSubsystem blocks (that is, if you copy a Subsystem block that containsa block for which theCopyFcn parameter is defined,the routine is also executed). The routine is also executed if anadd_block commandis used to copy the block. | |
| After a block or line is deleted in a subsystem. If theblock has a DeleteFcn orDestroyFcn,those functions are executed prior to the DeleteChildFcn.Only Subsystem blocks have aDeleteChildFcn callback. | |
| After a block is graphically deleted, e.g., when yougraphically delete the block, invokedelete_block onthe block, or close the model containing the block. When theDeleteFcn iscalled, the block handle is still valid and can be accessed usingget_param.The DeleteFcn callback is recursive for Subsystemblocks. If the block is graphically deleted by invokingdelete_block orby closing the model, after deletion the block is destroyed from memoryand the block'sDestroyFcn is called. | |
| When the block has been destroyed from memory, e.g.,when you invoke delete_block on either the blockor a subsystem containing the block or close the model containingthe block. If the block was not previously graphically deleted, theblock'sDeleteFcn is called prior to the DestroyFcn.When the DestroyFcn is called, the block handleis no longer valid. | |
| When an error has occurred in a subsystem. Only Subsystemblocks have an ErrorFcn callback. For more information,seeSubsystem Error Function Callback. | |
| Before the block diagram is compiled and before blockparameters are evaluated. | |
| After the block diagram is loaded. This callback is recursivefor Subsystem blocks. | |
| Before the block diagram is closed. When the model isclosed, the block's ModelCloseFcn is called priorto itsDeleteFcn. This callback is recursive forSubsystem blocks. | |
| When the block is moved or resized. | |
| After a block's name and/or path changes. When a Subsystemblock's path is changed, it recursively calls this function for allblocks it contains after calling its ownNameChangeFcn routine. | |
| When the block is opened. This parameter is generallyused with Subsystem blocks. The routine is executed when you double-clickthe block or when anopen_system command is calledwith the block as an argument. The OpenFcn parameteroverrides the normal behavior associated with opening a block, whichis to display the block's dialog box or to open the subsystem. | |
| Before closing a subsystem containing the block or whenthe block is made part of a new subsystem using thenew_system command (see new_system in the online Simulink softwarereference) or the Create Subsystem itemin model editor's Edit menu. The ParentCloseFcn ofblocks at the root model level is not called when the model is closed. | |
| After the simulation pauses. | |
| After the block diagram is saved. This callback is recursivefor Subsystem blocks. | |
| PreCopyFcn | Before a block is copied. The callback is recursive for Subsystemblocks (that is, if you copy a Subsystem block that contains a blockfor which thePreCopyFcn parameter is defined,that routine is also executed). The block'sCopyFcn iscalled after all PreCopyFcn callbacks are executed,unless thePreCopyFcn invokes the error commandeither explicitly or via a command used in anyPreCopyFcn.The PreCopyFcn is also executed if an add_block commandis used to copy the block. |
| PreDeleteFcn | Before a block is graphically deleted, e.g., when the usergraphically deletes the block or invokesdelete_block onthe block. The PreDeleteFcn is not called whenthe model containing the block is closed. The block'sDeleteFcn iscalled after the PreDeleteFcn unless the PreDeleteFcn invokestheerror command either explicitly or via a commandused in the PreDeleteFcn. |
| Before the block diagram is saved. This callback is recursivefor Subsystem blocks. | |
| After the block diagram is compiled and before the simulationstarts. In the case of an S-Function block,StartFcn executesimmediately before the first execution of the block's mdlProcessParameters function.See S-Function Callback Methods for more information. | |
| At any termination of the simulation. In the case ofan S-Function block, StopFcn executes after theblock'smdlTerminate function executes. See S-Function Callback Methods for more information. | |
| When a block deletion is undone. |
本文详细介绍了Simulink环境中各种块回调函数的功能及其执行时机,包括复制、删除、初始化等操作时触发的不同回调函数,并解释了它们如何帮助用户定制模型的行为。
98

被折叠的 条评论
为什么被折叠?



