|
Each example shows first the Matlab-code
and second the code you would
need to perform the same actions using the C-programming
language. Please select the sample you want to view:
|
View Matlab-file and C-file on this page |
Matlab-file |
C-file |
sample1 |
sample1.m |
sample1.c |
sample2 |
sample2.m |
sample2.c |
sample5 |
sample5.m |
sample5.c |
sample7 |
sample7.m |
sample7.c |
sample8 |
sample8.m |
sample8.c |
sample9 |
sample9.m |
sample9.c |
sample10 |
sample10.m |
sample10.c |
sample20 |
sample20.m |
sample20.c |
|
|
Matlab-code for sample20:
%Name: SAMPLE20.M
%Description:
% OPTOTRAK Sample Program #20.
% 1. Determine the system configuration and generate the
% external NIF configuration file, system.nif.
% 2. Load the system of transputers with the appropriate
% transputer programs based on the external file,
% system.nif.
% 3. Initiate communications with the transputer system.
% 4. Disconnect the PC application program from the transputer
% system.
% 5. Set the API to use the internally generated and stored
% system NIF configuration.
% 6. Determine the system configuration and store the
% NIF information internally.
% 7. Load the system of transputers with the appropriate
% transputer programs based on the internal NIF configuration.
% 8. Initiate communications again with the transputer system.
% 9. Disconnect the PC application program from the transputer
% system again.
%Just to be on the save side, we first reset all Matlab functions:
clear functions
%Settings:
LogFileName = 'CfgLog.txt';
%Determine the system configuration in the default manner
%without any error logging. This writes the file system.nif
%in the standard ndigital directory.
fprintf('Determining system configuration using system.nif.\n');
optotrak('TransputerDetermineSystemCfg');
%Load the system of transputers using the file system.nif.
fprintf('Loading & initializing transputer system...\n');
optotrak('TransputerLoadSystem','system');
%Wait one second to let the system finish loading.
pause(1);
%Initialize the transputer system.
optotrak('TransputerInitializeSystem',{'OPTO_LOG_ERRORS_FLAG'})
%Shutdown the transputer message passing system.
optotrak('TransputerShutdownSystem')
%Set the API to use internal storage for the system
%configuration.
fprintf('\nDetermining system configuration using internal strings.\n');
optotrak('OptotrakSetProcessingFlags',{'OPTO_USE_INTERNAL_NIF'});
%Determine the system configuration again, but this time
%with error logging.
optotrak('TransputerDetermineSystemCfg',LogFileName);
%Load the system of transputers - no argument defaults to the
%internal NIF configuration.
fprintf('Loading & initializing transputer system...\n');
optotrak('TransputerLoadSystem');
pause(1);
%Initialize the transputer system again in the usual manner.
optotrak('TransputerInitializeSystem',{'OPTO_LOG_ERRORS_FLAG'})
%Shutdown the transputer message passing system.
optotrak('TransputerShutdownSystem')
%Exit the program.
fprintf('\nProgram execution complete.\n');
|
|
Corresponding C-code for sample20:
/*****************************************************************
Name: SAMPLE20.C
Description:
OPTOTRAK Sample Program #20.
1. Determine the system configuration and generate the
external NIF configuration file, system.nif.
2. Load the system of transputers with the appropriate
transputer programs based on the external file,
system.nif.
3. Initiate communications with the transputer system.
4. Disconnect the PC application program from the transputer
system.
5. Set the API to use the internally generated and stored
system NIF configuration.
6. Determine the system configuration and store the
NIF information internally.
7. Load the system of transputers with the appropriate
transputer programs based on the internal NIF configuration.
8. Initiate communications again with the transputer system.
9. Disconnect the PC application program from the transputer
system again.
*****************************************************************/
/*****************************************************************
C Library Files Included
*****************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef _MSC_VER
void sleep( unsigned int uSec );
#elif __BORLANDC__
#include <dos.h>
extern unsigned _stklen = 16000;
#elif __WATCOMC__
#include <dos.h>
#endif
/*****************************************************************
ND Library Files Included
*****************************************************************/
#include "ndtypes.h"
#include "ndpack.h"
#include "ndopto.h"
/*****************************************************************
Name: main
Input Values:
int
argc :Number of command line parameters.
unsigned char
*argv[] :Pointer array to each parameter.
Output Values:
None.
Return Value:
None.
Description:
Main program routine performs all steps listed in the above
program description.
*****************************************************************/
void main( int argc, unsigned char *argv[] )
{
char
pszLogFileName[] = "CfgLog.txt",
szNDErrorString[MAX_ERROR_STRING_LENGTH + 1];
/*
* Determine the system configuration in the default manner
* without any error logging. This writes the file system.nif
* in the standard ndigital directory.
*/
fprintf( stdout, "Determining system configuration using system.nif.\n" );
if( TransputerDetermineSystemCfg( NULL ) )
{
fprintf( stderr, "Error in determining the system parameters.\n" );
goto ERROR_EXIT;
} /* if */
/*
* Load the system of transputers using the file system.nif.
*/
fprintf( stdout, "Loading & initializing transputer system...\n" );
if( TransputerLoadSystem( NULL ) )
{
goto ERROR_EXIT;
} /* if */
/*
* Wait one second to let the system finish loading.
*/
sleep( 1 );
/*
* Initialize the transputer system.
*/
if( TransputerInitializeSystem( OPTO_LOG_ERRORS_FLAG ) )
{
goto ERROR_EXIT;
} /* if */
sleep( 1 );
/*
* Shutdown the transputer message passing system.
*/
TransputerShutdownSystem();
/*
* Set the API to use internal storage for the system
* configuration.
*/
fprintf( stdout,
"\nDetermining system configuration using internal strings.\n" );
OptotrakSetProcessingFlags( OPTO_USE_INTERNAL_NIF );
/*
* Determine the system configuration again, but this time
* with error logging.
*/
if( TransputerDetermineSystemCfg( pszLogFileName ) )
{
fprintf( stderr, "Error in determining the system parameters.\n" );
goto ERROR_EXIT;
}
/*
* Load the system of transputers - the null string defaults to the
* internal NIF configuration.
*/
fprintf( stdout, "Loading & initializing transputer system...\n" );
if( TransputerLoadSystem( NULL ) )
{
goto ERROR_EXIT;
} /* if */
sleep( 1 );
/*
* Initialize the transputer system again in the usual manner.
*/
if( TransputerInitializeSystem( OPTO_LOG_ERRORS_FLAG ) )
{
goto ERROR_EXIT;
} /* if */
sleep( 1 );
/*
* Shutdown the transputer message passing system.
*/
if( TransputerShutdownSystem() )
{
goto ERROR_EXIT;
} /* if */
/*
* Exit the program.
*/
fprintf( stdout, "\nProgram execution complete.\n" );
exit( 0 );
ERROR_EXIT:
if( OptotrakGetErrorString( szNDErrorString,
MAX_ERROR_STRING_LENGTH + 1 ) == 0 )
{
fprintf( stdout, szNDErrorString );
} /* if */
TransputerShutdownSystem();
exit( 1 );
}
|
|