Danaher Motion
06/2005
BASIC Moves Development Studio
2.5.2. Prototype
File
For the MC-Basic language translator to match function parameters, provide
a C-function prototype file (PROTO.PRO). It is important to understand that
matching between the provided MC prototype and actual C implementation
cannot be tested by the translator.
It is your responsibility to keep
consistency between the function prototype and C implementation.
NOTE
To speedup translation of the prototype file, PROTO.PRO is
copied into RAM at startup and at every
OLOAD
. When
PROTO.PRO is modified and sent to the controller, issue an
OLOAD
or reboot the MC to refresh the prototypes in the RAM.
The translator is case-insensitive, while object module loader is case-
sensitive, so
write the name of a C function in capital letters within the C
code
. MC prototypes of C functions and C function calls through the MC are
not case sensitive.
Parameters can be passed “by value” and “by reference”
Few object files may be incrementally linked together.
The general syntax for the MC prototype of a C-function is:
IMPORT_C <
Function_Name
> ({AS <
type
>}, {BYVAL AS {<
type
>}) {AS <
type
>}
A parameter passed by value has the BYVAL prefix.
A parameter passed by reference has no prefix.
Prototypes do not include parameter names.
A C function prototype with no parameters is written with empty parentheses:
IMPORT_C <
Function_Name
> ( ) {AS <
type
>}
A C function prototype with no returned value (a void function) is written as:
IMPORT_C <
Function_Name
> ({AS <
type
>}, {BYVAL AS {<
type
>})
A C-function accepts any combination of double-, long- and string-type
parameters. The parameters may be passed “by value” or “by reference”.
The returned value may be long, double, string or none (for C functions with
void returned value).
Examples of prototypes and implementation:
MC-Basic Prototype
C Implementation
import_c cFunc_LV As Long
int CFUNC_LV(void);
import_c cFunc_DV As double
double CFUNC_LV(void);
import_c cFunc_SV As string char*
CFUNC_LV(void);
import_c cFunc_VV()
void CFUNC_VV(void);
import_c cFunc_LL(ByVal As Long) As Long
int CFUNC_LL(int L);
import_c cFunc_DRD(As Double) As Double
double CFUNC_DRD(double* D);
import_c cFunc_SRS(As String) As String
char* CFUNC_SRS(char** S);
Import_C cFunc_LARD
(
[*] as Long) as Double
double CFUNC_LARD(long *l);
import_c cFunc_SS(ByVal As String) As String
char* CFUNC_SS(char* S);
Parameters can be of type long, double or string; in any order, up to 32
parameters.
Only one-dimensional arrays are allowed as C-functions arguments.
M-SS-005-03 Rev
E
41