System_Language/ C_and_CPP / Custom C
Block Name: Custom_C
Code File Location: VisualSim/jni/GenericJNIActor
o This block is used to import a file containing a set of functions written in C/C++ code. To use this block, configuration files must be updated.
There are two files located in $VS/bin directory called vsconf.bat and vsconf.sh, and the two startup scripts in $VS directory called VisualSim.sh and VisualSim.bat. Use the .bat file for windows users and .sh for all forms of UNIX (Linux, Solaris, MAC OS etc.). Follow the below table to fill in the required information.
VisualSim.bat |
1. set VS_C_Library= (Base path to where all the source code will be placed. The default within the VisualSim install will be C:\VisualSim\VS800\UserNativeC. |
vsconf.bat |
1. SET VSDIR=(This is the path to the compiler). For example, "C:\Program Files\Microsoft Visual Studio 9.0\VC" |
VisualSim.sh |
1. set VS_C_Library= (Base path to where all the source code will be placed. The default within the VisualSim install will be User/VisualSim/VS800/UserNativeC |
vsconf.sh |
1. export CC=g++ |
Windows: VisualStudio 2008, 2010 and 2013. Support for Borland compiler is also available.
If you use Visual Studio Express, be advised that Microsoft's Platform SDK (PSDK) is not included with the Visual Studio Express installation. You will need to install it separately and configure Visual Studio to use it (follow Microsoft's directions for this).
Linux and UNIX: g++ 4.0.x.
The following steps must be taken to construct a block to import code into a VisualSim model. To understand the block usage, look at the simple example.
Output C and C++ Type: The following table shows the C\C++ Argument types and their equivalent VisualSim types.
Equivalent VisualSim Types |
|
char[] |
string |
char |
string |
short, long |
long |
double |
double |
bool |
boolean |
int[], short[] |
{int} |
long[] |
{long} |
double[] |
{double} |
{ Name=char[5]; Id=int} (Available only for the C block output) |
general |
Table 2: C\C++ Arguments and Equivalent VisualSim Types
Note: { Name=char[5]; Id=int} is representation for the C\C++ structure like the one below:
struct Example{
char Name[ ];
int Id; };
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 to see what can be added.
If you need to access multiple files, this is also specified in the Wrapper file. You can add more includes also trigger specific functions based on the input values.
The output can return a struct or Data Structure to VisualSim. All input ports must be basic C++ types.
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. Else a java.lang.null exception will be received. The block name will be changed to Library Directory + "I" + "C+ file name.
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 mst be commented out: *.cpp, *.java, *.h, Jni*.cpp and Jni*.h.
If you have multiple instances of the same C code in a single model, they will each need to have their own .dll/.so. This means that the Block Icon Name must be unique for each block even though the internal parameter refers to the same file. This is irrespective of the hierarchical block that each one is part.
Parameter |
Explanation |
Type |
libraryDirectory |
The directory that will hold the generated and intermediate files. Make sure you have an unique file for each model. |
string |
nativeFunction |
The name of the native library and the cpp file name. The cpp or c extension is not required. |
string |
Created with the Personal Edition of HelpNDoc: Create iPhone web-based documentation