Custom_C Block

Parent Previous Next

VisualSim                                                                                                                               

Custom_C Block

Block Overview

This block is used to interface with a file containing a set of functions written in C/C++ code. To use this block, configuration files must be updated.

Block Setup

The following steps must be taken to construct a block to import code into a VisualSim model:

  1. Drag a Custom_C block from System_Language > C_and_CPP directory.
  2. Enter the LibraryDirectory. This is relative to the VS_C_Library that was set in VisualSim script file. This uses the "." as a separate rather than slashes.
  3. Enter the NativeFile directory and name. This uses forward slash "/" as a separator. This can be relative to the VS_C_Library or the absolute path if located elsewhere.
  4. Add the Ports using Customize > Ports.  There is one port for each input variable sent to the code and one output for each variable being returned.
  5. Next Right-click the block and select Configure Argument. For each port, add the 4 information. There must be at least one OutputKind selected as a return. The C++ data types supported are listed in Custom-Coded Block- C/C++. The Name must match the port name and the Function Name is the function that the input or output is associated with.

Notes

If additional logic needs to be specified between the block port and the function, you can add this to the generated cpp wrapper file. Look at the Master-Slave Example in (VisualSim/VS/demo/Interfaces/VS_C_Library/Slave/MasterSlave1.xml) to checkout what can be added.

If you need to access multiple files, this is also specified in the Wrapper file.  You can add more that also includes trigger specific functions based on the input values.

The output can return a struct or Data Structure to VisualSim.  All input ports must be tokens.

The following requirements must be maintained.

File names must not contain _.

The block "Customize Name" must match the Library Directory parameter. If the block name does not change by itself, then the user must change the block name. Else a java.lang.nullexception is received.

If multiple c or cpp files are located in the same directory, then the $VS/bin/vsmake.{sh,bat} must be updated. All the delete lines must be commented out: *.cpp, *.java, *.h, Jni*.cpp and Jni*.h.

 

Parameter

 

 

Explanation

 

libraryDirectory

The directory that holds the generated and intermediate files. Make sure you have an unique file for each model.

nativeFunction

The name of the native library and the cpp file name. The cpp or c extension is not required.

 

 

 

Created with the Personal Edition of HelpNDoc: Free CHM Help documentation generator