This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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.


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:

  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"


    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:

  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 );

Related Topics

Was this topic helpful?