Real-Time Workshop    

Building the MEX-File and the Driver Block

This section outlines how to build a MEX-file from your driver source code for use in Simulink. For full details on how to use mex to compile the device driver S-function into an executable MEX-file, see External Interfaces/API in the MATLAB online documentation. For details on masking the device driver block, see "Using Masks to Customize Blocks" in Using Simulink.

  1. Your C S-function source code should be in your working directory. To build a MEX-file from mydriver.c type
  1. mex builds mydriver.dll (PC) or mydriver (UNIX).

  1. Add an S-Function block (from the Simulink Functions & Tables library in the Library Browser) to your model.
  2. Double-click the S-Function block to open the Block Parameters dialog. Enter the S-function name mydriver. The block is now bound to the mydriver MEX-file.
  3. Create a mask for the block if you want to use a custom icon or dialog.

  Writing an Inlined S-Function Device Driver Source Code for Inlined ADC Driver