Using Booleans and Strings
Create a Custom_C block that calls C functions that return a Boolean and output a String
- YearInfo () function takes date (string) as input and outputs the day (string) for the date.
- BoolCheck () function takes date (string) as input. It returns a boolean value as ‘true’ if input date is a leap year and 'false' if is not a leap year.
- The C code for the above
functions is available in the file “YearInfo.c” under
VS_C_Library/YearInfo 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.
Construction Steps
- Open VisualSim IDE and drag the Custom_C block from Full Library > System_Language > C_and_CPP to the Block Diagram Editor.
Figure 1: Configuring the Custom_C block
- The parameter
libraryDirectory is the directory name for the block that is
created under the base directory. The base for the libraryDirectory of
the block is always set to VS_C_Library directory. Just the directory
structure within this level is sufficient.
- The parameter nativefiles
could specify the location of the “.C” files which contain the
definitions for the C functions that the Designers wish to interface
with VisualSim. The absolute path for the file should be specified when
they are located outside the libraryDirectory. Use only forward slash
‘/’ while specifying absolute path because the tool permits only
forward slash to maintain platform independence.
- The parameter nativeLibrary should specify the same name as the libraryDirectory.
- Right click the Custom_C block and select Configure Arguments and add the following arguments:
Figure 2: C\C++ Arguments Configuration for YearInfo
Note: Specify the array size except for the char type while using Arrays as C\C++ Arguments.
- Click the VisualSim menu Interface > Generate Wrapper for interface generation and compilation of source files. Refer Figure 6.
- A new folder named
“YearInfo” is automatically created under VS_C_Library directory
if it does not exist. In case if the files in the respective folder
already exist, then it is replaced with the new files.
- Successful
compilation of the sources 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 a 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 the PATH.
- Drag the MoniterValue result block from Result > Text. Similarly the Const input block from Full Library > Math Operations > Math and Trig. Control-click to create the relation.
- Connect all the blocks as shown in the Figure 3.
- Add an Untimed Digital Simulator
(located under Full Library -> Model->Simulator). Double-click
the Untimed Digital simulator and change the number of iterations from
0 to 1.
- To run YearInfo model, click the run button or Press Ctrl+R. The expected result looks similar to the one shown below.
Figure 3. Result of YearInfo Model