Using Arrays
Creating a Custom_C block that calls a C function which returns and outputs Integer Arrays
The following section explains
the steps involved in creating a VisualSim model namely “IntegerArray”.
A similar approach can be followed for creating a Custom_C block that
returns double array or long array.
This model demonstrates how to
access an “Array in C” using Custom_C block. This IntegerArray model
inputs an integer array to the Custom_C block through an input port and
displays the same array using one of the output ports.
The C code for the function is available in the file “IntegerArray.c” under VS_C_Library/Integer
directory of VisualSim. The tool does not generate this file and it
should be made available by the Designers who wish to interface their
code with VisualSim.
Steps for Creating IntegerArray Model
- Open the VisualSim Block Diagram Editor and place the Custom_C block in the canvas. Custom_C is located in Full Library > System_Language > C_and_CPP > Custom_C directory.
- Right click the Custom_C block and select Customize > Configure or press Ctrl+E to configure the block as shown below:
Figure 1. Configuring the Custom_C block
- Right click the Custom_C block and select Configure Arguments. Add the following arguments:
Figure 2: C\C++ Arguments Configuration for IntegerArray
Note: Specify the array size except for the char type while using Arrays as C\C++ Arguments.
- Now click Interface > Generate Wrapper for code generation and compilation.
- Now a new folder named “IntegerArray” is automatically created under the VS_C_Library directory.
- Successful
compilation of the source files creates a
Jni<libraryname>I<return argument name>.dll file under
the blocks directory. The file extension “. Dll” indicates that the file is
a dynamic link library (dll).
Note:
Open the “vsout.txt” file under the libraryDirectory to check for
errors caused by an unsuccessful compilation process. These could help in
correcting any mistakes in the interface C code.
- The blocks directory is provided under VS_C_Library directory to hold “. Dll” files, which are in PATH.
- Now drag and drop a Monitor Value block from Results > TextDisplay to view the output. Similarly the Const input block can be obtained from Full Library > Math Operations > Math and Trig.
- Add an Untimed Digital Simulator to the canvas from Full Library > Model > Simulator > Untimed Digital. Double click the Untimed Digital Simulator to change the number of iterations from 0 to 1. Finally, connect the blocks as shown in Figure 3 below.
- Press Ctrl+R or press the run button to execute the IntegerArray Model.
- The following figure shows the IntegerArray model and its output.
Figure 3. IntegerArray Model