Right-click the CIN and select Create .c File from the shortcut menu to create a .c file in the style of the C programming language. The .c file describes the routines you must write and the data types for parameters that pass to the CIN.
For example, a call to a CIN takes a 32-bit signed integer as an input and returns a 32-bit signed integer as an output, as shown in the following illustration.
The following code excerpt is the initial .c file for the CIN in the illustration above:
/* CIN source file */
#include "extcode.h"
MgErr CINRun(int32 *numIn, int32 *numOut);
MgErr CINRun(int32 *numIn, int32 *numOut) {
/* Insert code here */
return noErr;
}
You can write eight routines for the CIN in the illustration above. The CINRun routine is required and the others are optional. If an optional routine is not present, LabVIEW uses a default routine when building the CIN.
The preceding .c file is a template in which you must write C code. The extcode.h file, which is in the labview\cintools directory, is automatically included because it defines basic data types and a number of routines that can be used by CINs. extcode.h also defines some constants and types whose definitions might conflict with the definitions of system header files. The labview\cintools directory also contains hosttype.h, which resolves the differences between definitions in extcode.h and definitions in system header files. hosttype.h also includes many of the common header files for a given platform.
Always use #include "extcode.h"at the beginning of your source code. If your code needs to make system calls, also use #include "hosttype.h" immediately after #include "extcode.h"and then include your system header files. hosttype.h includes only a subset of the .h files for a given operating system. If the .h file you need is not included in hosttype.h, you can include it in the .c file for your CIN after you include hosttype.h.
LabVIEW calls the CINRun routine when it is time for the node to execute. CINRun receives the input and output values as parameters. The other routines, CINLoad, CINSave, CINUnload, CINAbort, CINInit, CINDispose, and CINProperties, are housekeeping routines. The housekeeping routines are called at specific times so you can take care of specialized tasks with your CIN. For example, LabVIEW calls CINLoad when it first loads a VI. If you need to accomplish a special task when your VI loads, put the code for that task in the CINLoad routine. The following example code shows how to put the code for a task in the CINLoad routine:
CIN MgErr CINLoad(RsrcFile reserved) {
Unused (reserved);
/* Insert code here */
return noErr;
}
In general, you only need to write the CINRun routine. Use the other routines when you have special initialization needs, such as when your CIN must maintain some information across calls and you want to preallocate or initialize global state information. The following example code shows how to fill out the CINRun routine in the .c file for the CIN in the illustration above to multiply a number by two:
CIN MgErr CINRun(int32 *num_in, int32 *num_out) {
*num_out = *num_in * 2;
return noErr;
}
Refer to Passing Parameters to CINs for information about and examples of how LabVIEW passes data to a CIN.
After you create a .c file, compile the CIN source code.