Event handler function - userBlockEvent()

The userBlockEvent() function is called at block events, such as block repaint, end of time step, and simulation end.

LPSTR PASCAL userBlockEvent(HWND h, int msg, WPARAM wp,LPARAM lp)

This function lets you save and restore mixed data types. Note that the arguments are the same as Windows or Windows NT event functions.

Embed calls your function with the following messages:

Message

Description

VBF_FRAME_END

Reserved.

WM_VSM_ADD_CONNECTOR

Signals a user-request for a connector to be added to a block.
wp:    Current count
lp:      1 if input
           0 if output

WM_VSM_ALLOC_VEC_OUTPUT

This event is generated after inputs are allocated. This event allows user DLL to allocate vector outputs.
wp:    0
lp:      Block handle

WM_VSM_BLOCK_INFO

Used for writing a custom optimizer.

WM_VSM_BLOCK_LABEL

Provides a block label. Return a null terminated string for label under block.
wp:    0
lp:      Block handle

WM_VSM_BLOCK_PLACED

Signals that a block has been placed in the diagram.
lp:      Block handle

WM_VSM_BLOCK_SETUP

This event is generated only if there is no userBlockPC() function defined for the block. This event is generated when you right-click the block.
wp:    Internal ID
lp:      Block handle

WM_VSM_CAN_ACCEPT_ALTERNATE_TYPE

Checks if block inputs can accept alternate data type. Returns 0 if NO, 1 if YES.
wp:    Data type
lp:      Block handle

WM_VSM_CHECKPOINT_STATE

Signals a user-request to checkpoint system states; that is, set the checkpoint buffer to the current state value.

WM_VSM_CONNECTOR_NAME

Returns string of connector label name. Null if no label is desired.
wp:    Port number (negative if output)
lp:      Block handle
          

WM_VSM_CREATE

Is called when a user block is created. You can return flags to customize block treatment. (For more information, see “Return flags for WM_VSM_CREATE,” below.)
wp:    0 if create from file
           1 if create from menu
           2 if create from clipboard
lp:      Block handle

WM_VSM_DEL_CONNECTOR

Signals a user-request for a connector to be deleted from a block.
wp:    Current count
lp:      1 if input
           0 if output

WM_VSM_DESTROY

Is called when user block is destroyed.
lp:      Block handle

WM_VSM_FILE_CLOSE

Reserved.

WM_VSM_FILE_READ

Signals that block and all its parameters have been read in from file.
lp:      Block handle

WM_VSM_GET_BANNER_STR

Reserved.

WM_VSM_GET_BLOCK_BITMAP

Reserved.

WM_VSM_GET_BLOCK_NAME

Provides a block with a custom name. Return a null terminated string that contains the new name. The name may contain newline characters.

 

WM_VSM_GET_CODEGEN_ALLOC_STRING:

Returns C code for file scope declarations used in WM_VSM_GET_CODEGEN_STRING and WM_VSM_GET_CODEGEN_START_STRING.
wp:    0
lp:      Block handle

WM_VSM_GET_CODEGEN_BACKGROUND_TASK

Returns text of background function.
wp:    0
lp:      Block handle

WM_VSM_GET_CODEGEN_END_STRING

Returns C code string to execute after simulation terminates.
wp:    0
lp:      Block handle

WM_VSM_GET_CODEGEN_INCLUDE_STRING

Sent during code generation. If used, returns text of include file line; otherwise, null.

WM_VSM_GET_CODEGEN_PORT_STORAGE

Returns C code to supply result value on output pin wp.
wp:    Output pin
lp:      Block handle

WM_VSM_GET_CODEGEN_POST_END_STRING

Sent after all WM_VSM_GET_CODEGEN_END_STRING

WM_VSM_GET_CODEGEN_POST_START_STRING

 

Sent after all WM_VSM_GET_CODEGEN_START_STRING.

WM_VSM_GET_CODEGEN_START_STRING:

Returns C code for block initialization.
wp:    0
lp:      Block handle

WM_VSM_GET_CODEGEN_STRING

Returns C code string for main time step function. %1 expands to code for input pin 1; %2 expands to code for input pin 2, and so on.
wp:    0
lp:      Block handle

WM_VSM_GET_CODEGEN_TARGET

Reserved.

WM_VSM_GET_CODEGEN_TIME_STEP_STRING

Reserved.

WM_VSM_GET_CONNECTOR_TYPE

Puts a data type on a connector. If you do not handle the message, the connector type is T_DOUBLE. The connector types that can be returned are: T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_ULONG,T_CHAR, T_UCHAR, T_SHORT, T_USHORT, T_STRING, T_MAT_DOUBLE, T_MAT_COMPLEX, T_POINTER, T_COMBO_ITEM, T_SCALED_INT, T_COMPLEX, and T_LAST.
wp:    Connector index. If positive, it is an input; if negative, it is an output.
lp:      Block handle
Returns: Connector Type

WM_VSM_GET_CONNECTOR_TYPE_STR

Supplies the text string of the pointer. The string returned should provide good indication of the data structure pointed to. For example, “cv::Mat*” is a pointer to an OpenVision image.
wp:    Port number. If positive, it is an input; if negative, it is an output.
lp:      Block handle.
Returns: Data type string for port – used by T_POINTER.

WM_VSM_GET_DEFAULT_IN_VAL

Reserved.

WM_VSM_GET_IGNORE_MENU_GRAYING

Returns TRUE if block should not be grayed in the Viewer.
wp:    0
lp:      Block handle

WM_VSM_GET_OBJ_CLASS

Reserved.

WM_VSM_GET_OUT_SIG_VEC

Reserved.

WM_VSM_GET_PARAM

Reserved.

WM_VSM_GET_PARAM_DESC

Provides a data descriptor for saving and restoring data. Return a text string that describes your data by following these formatting guidelines:
i   2-byte integer
I   4-byte integer
f   4-byte float
F   8-byte float
c   Single-byte character

All of the above format characters can take an optional count suffix, which is enclosed in square brackets. For example, to save two 8-byte floats and a 32-character string in C, use the following string notation:

“F [2] c[32]”

In Fortran, the string notation is:

‘F [2] c[32]’ c

WM_VSM_GET_PARAM_STR

Returns pointer to parameter strings with a semi-colon separator. wp:                0
lp:      Block handle

WM_VSM_GET_SEARCH_STR

If the block has searchable string, it returns it.
lp:      Block handle

WM_VSM_INFO

Reserved.

WM_VSM_IS_VEC_CONNECT

This event is generated when user attempts to connect a block. User returns a value. If the value is 1, the vector or matrix input or output is allowed. If the value is 0, scalar input or output is allowed.
wp:    If positive, it is an input; if negative, it is an output
lp:      Block handle

WM_VSM_PIN_CONNECTED

Informs the block event handler that a connection has been made of the given data type.
wp:
    If positive, it is an input; if negative, it is an output
lp:      Data type

WM_VSM_POST_SIM_START

This event is generated after all simulation start messages.
wp:    0
lp:      Block handle

WM_VSM_PRE_SIM_START

This event is generated after simulation-wide VSE_PRE_SIM_START and before any other block receives WM_VSM_SIM_START.
wp:    Run count
lp:      Block handle

WM_VSM_PUT_PARAM

Reserved.

WM_VSM_RETAIN_STATE_RESTART

Restarts with retained states.
lp:      Block handle

WM_VSM_SET_SEARCH_STR

Sets a new block string.
lp:      Block handle

WM_VSM_SIM_END

Reserved.

WM_VSM_SIM_RESET

This message is sent on simulation reset when the user presses the RESET button.
wp:    Block string
lp:      Block handle

WM_VSM_SIM_RESTART

Signals restart due to continue or single step.
lp:      Block handle

WM_VSM_SIM_START

This event is sent on simulation start-up or restart.
wp:    Run count
lp:      Block handle

WM_VSM_SNAP_STATE

Signals a user-request to snap system states; that is, set the initial condition to the current state value.

WM_VSM_STOP_SIM

Signals that Embed has stopped, either by user or time expiration.
wp:    1 if single step
lp:      Pointer to parameter vector

WM_VSM_SUPPRESS_WARN_UNCONNECT

Checks to suppress the unconnected input warning message. Return 1 if suppression is desired.
wp:    Port number (negative if output)
lp:      Block handle

WM_VSM_WINDOW_HANDLE

This event is generated on Embed start-up.
wp:    0
lp:      Main window handle