Embedding an Interpreter via Call Library Function Block

To build a function prototype for a shared libraryŚcalled DLLs on the Windows platform, a prototype in LabVIEW must be built and then all the details of the code must be filled in. When allowing LabVIEW to generate this C source code, it should be ensured that the basic syntax of the code in the shared library will be valid. The process of building a library project is specific to each Integrated Development Environment (IDE) and each operating system. The compiler/platform combinations can be used to build shared libraries for use in LabVIEW: Microsoft Visual C/C++ on Windows, gnu C/C++ on Unix, and Metroworks CodeWarrior on Macintosh

A call library function block for the script function func().
#include "extcode.h" #include <stdio.h> #include <string.h> #include <stdlib.h> #include <embedch.h> #include <windows.h> typedef struct { int32 dimSize; float64 elt[1]; } TD1; typedef TD1 **TD1Hdl; __declspec (dllexport) void CallDll(TD1Hdl sinH, TD1Hdl angH){ ChInterp_t interp; int status; char *argvv[]={"embedch.ch", NULL}; int32 len; float64 *sinElmtp, *angElmtp; MgErr mgError=noErr; len = (*sinh)->dimSize; /* number of rows in a and result */ sinElmtp = (*sinH)->elt; angElmtp = (*angH)->elt; /* initialize embedded Ch */ Ch_Initialize(&interp, NULL); /* run an Embedded Ch program indicated by argvv */ status = Ch_RunScript(interp, argvv); status = Ch_CallFuncByName(interp, "fun", NULL, sinElmtp, angElmtp, len); Ch_End(interp); }

The Call Library Function node supports a large number of data types and calling conventions. It can be used to call functions from most standard and custom-made libraries. Each function in a DLL must be explicitly exported to make it available to LabVIEW. The _declspec (dllexport) keyword should be used to export a function in Windows. By declaring with the dllexport keyword, a module definition file is not needed. The function prototype for building a call library function block for the VI described in the previous section is as follows.

__declspec (dllexport) void CallDLL(TD1Hdl sinH, TD1Hdl angH);

The following information must be provided to build a call library function block.

1. Function name as it appears in the library

2. Function prototype

3. Library or module in which the function resides

4. Calling conventions of the function

5. Thread-safe status of the function

Configuring the call library function node.

The call library function block consists of paired input/output terminals with input on the left and output on the right. The return value for the function is returned in the right terminal of the top pair of terminals of the node. If there is no return value, the output terminal on the right is unused. Each pair of terminals corresponds to a parameter in the function's parameter list. A value is passed to the function by wiring to the left terminal of a terminal pair. The value is read of a parameter after the function call by wiring from the right terminal of a terminal pair. The call library function node can be used to configure the function. When loading the library that built via Library Name or Path, the function name will show in the panel, the parameters can be added that will be used in the function depending on the variable type.

LabVIEW users frequently want to access the 32-bit Windows platform API (the Win32 API). In Win32 environments, various DLLs permit the application to interact with the operating system and graphical user interface. However, these APIs are readily available in a Ch script.

Main Page