Documentation

Create Custom Blocks

You can create custom Receive and Transmit blocks to use with hardware currently not supported by the Vehicle Network Toolbox™.

Vehicle Network Toolbox blocks use a custom CAN data type. To use the blocks you create with other Vehicle Network Toolbox blocks, register this custom CAN data type.

To use the custom data type defined in the Vehicle Network Toolbox, write a C++ S-function.

    Note:   You must use a C++ file type S-function (.cpp) to create custom blocks. Using a C-file type S-function (.c) may cause linker errors.

To register and use the custom CAN data type, in your S-function:

  1. Define the IMPORT_SCANUTIL identifier that imports the required symbols when you compile the S-function:

    #define IMPORT_SCANUTIL
  2. Include the can_datatype.h header located in[MATLABROOT]\toolbox\vnt\vntblks\include\candatatype at the top of the S-function:

    #include "can_datatype.h"

      Note:   The header can_message.h included by can_datatype.h is located in [MATLABROOT]\toolbox\shared\can\src\scanutil\.

  3. Link your S-function during build to the scanutil.lib located in the [MATLABROOT]\toolbox\vnt\vntblks\lib\<ARCH> directory. The shared library scanutil.dll, is located in the [MATLABROOT]\bin\<ARCH>

  4. Call this function in mdlInitializeSizes to initialize the custom CAN data type:

    mdlInitialize_CAN_datatype(S);
  5. Get custom data type ID using ssGetDataTypeId:

    dataTypeID = ssGetDataTypeId(S,SL_CAN_MESSAGE_DTYPE_NAME);
  6. Do one of the following:

    • To create a receive block, set output port data type to CAN_MESSAGE:

      ssSetOutputPortDataType(S, portID, dataTypeID );
    • To create a transmit block, set the input port to CAN_MESSAGE:

      ssSetInputPortDataType(S, portID, dataTypeID );

For more information on S-functions, see S-Function Basics.

Was this topic helpful?