
RTC
®
5 PC Interface Board
Rev. 1.9 e
6 Developing User Applications
67
innovators for industry
6.2.5 Example Code
The following C source code for a console application
(environment: Win32) illustrates the programming
fundamentals of DLL and RTC
®
5 initialization (for
complete demo programs, see
Necessary sources:
RTC5impl.h
,
RTC5DLL.LIB
(for
implicit linking) or
RTC5expl.h
,
RTC5expl.c
(for
explicit linking). Additionally, the DLL must be called
by the program (see
). If the operating system
does not find the
RTC5DLL.DLL
on program startup, it
will produce a corresponding error message and
terminate the program.
// System header files
#include <windows.h>
#include <stdio.h>
#include <conio.h>
// RTC
®
5 header file for implicitly linking to the RTC5DLL.DLL (for building the executable, also link with the (Visual C
++
)
// import library RTC5DLL.LIB):
#include "RTC5impl.h"
// Alternatively: RTC
®
5 header file for explicitly linking to the RTC5DLL.DLL (for building the executable, link with the file
// RTC5EXPL.OBJ, which you can generate from the source code RTC5expl.c):
//#include "RTC5expl.h"
void __cdecl main( void*, void* )
{
// only for explicitly linking:
// if ( RTC5open() ) // error detected, RTC5open returns 0 for no error
// {
// printf( "Error: RTC5DLL.DLL not found\n" );
// terminateDLL();
// return;
// }
printf( "Initializing the DLL\n\n" );
UINT ErrorCode;
// Initializing the DLL (the following command must be called as the first RTC
®
5 command)
ErrorCode = init_rtc5_dll();
// Following the
command you should include a program code to catch an error during initialization, e.g.
// for the case the desired RTC
®
5 board is not detected, access is denied or for another error (e.g. a version mismatch).
// A corresponding example code is listed on
.
// Initializing the RTC
®
5:
// - Selecting the RTC
®
5 board number 1 as the active RTC
®
5 board for this application
// - If desired: Selecting the RTC
®
4 compatibility mode as operation mode (default: RTC
®
5 mode)
// - Stopping any list running on RTC
®
5 board number 1 (if this board has been used previously by another application,
// a list might still be running. This would prevent
and
from being executed).
// - Calling
for resetting the board, loading the program file, etc. (here also a program code should be
// included to catch possible errors – e.g. file or system errors – during initialization; see
// - Clearing all previous error codes (stop_execution might have created an RTC5_TIMEOUT or RTC5_BUSY error)
// - Configuring the RTC
®
5 board's list memory, default: 4000 storage positions for list 1, 4000 for list 2).
(void) select_rtc( 1 );
set_rtc4_mode();
stop_execution();
ErrorCode = load_program_file( 0 ); // pPath = 0: path of current working directory
if ( ErrorCode )
{
printf( "Program file loading error: %d\n", ErrorCode );
free_rtc5_dll();
return;
}
reset_error( -1 );
config_list( 4000, 4000 );
// Following the above initialization code you can include the program code defining the laser scan process.
// An example code is listed on
// End of main program