Using RTmain

NI LabWindows™/CVI™ 2012 Help

Edition Date: August 2012

Part Number: 370051V-01

»View Product Info
Download Help (Windows Only)

Use RTmain as the entry-point function for RT DLLs you create using LabWindows/CVI. Use the Edit»Insert Construct»RTmain command to insert the following RTmain code into the program source. The comments indicate where to put the initialization, main program, and cleanup code for the DLL.

#include <windows.h>
#include <cvirte.h>

extern int CVIFUNC RTIsShuttingDown (void);

void CVIFUNC_C RTmain (void)
{

if (InitCVIRTE (0, 0, 0) == 0)

return; /* out of memory */

/* your initialization code */

while (!RTIsShuttingDown ())

{
/* your code */

/* sleep for some amount of time to give the desired loop rate */
/* if you do not sleep lower priority threads will never run */
Sleep (100);
}

/* your cleanup code */

CloseCVIRTE ();

}

The RTIsShuttingDown function initially returns false. The following table describes when RTIsShuttingDown returns true and the behavior of the cleanup code and the real-time target.

Shutdown Method During Development and Debugging After the DLL is Deployed on an RT Target
Select Run»Simulate RT Shutting Down The cleanup code runs to completion.
The real-time target does not reboot.
Not applicable.
Select Run»Abort Execution and Reboot Target The cleanup code is not guaranteed to run to completion.
The real-time target reboots.
Not applicable.
Reboot through MAX The cleanup code is not guaranteed to run to completion.
The real-time target reboots.
The cleanup code runs to completion.
The real-time target reboots.

National Instruments recommends that you use the Simulate RT Shutting Down item to terminate execution while you are debugging.

Run any necessary cleanup code before exiting an RT application. In the cleanup code, free any resources allocated by your application and ensure that any additional threads created by your application have exited. After running your cleanup code, your main thread should exit the RTmain function. Your application is finished when RTmain exits. Exiting RTmain does not cause the RT target to reboot. You can initiate a reboot of the RT target by calling the ANSI C Library function exit after your cleanup code or at any time from any thread in your application. If your application is registered on the RT target as a startup DLL, your application restarts automatically after the RT target reboots.

WAS THIS ARTICLE HELPFUL?

Not Helpful