Fanuc C-Executer Operating Manual
B-62443EN-3/03E
- 443 -
[Example]
The following program reads the parameter data within the specified
number range and axis and displays them.
#include <data.h>
#include <fwindow.h>
#include <stdio.h>
#include <stdlib.h>
/* start/end are start/end number to be read, axis is axis number. */
int example( int start, int end, int axis )
{
struct odbsys info ;
struct iodbpsdr *buf, *ptr ;
int ret, idx1, idx2, axno, inc ;
cnc_sysinfo( &info ) ;
axno = atoi( info.axes ) ;
buf = (struct iodbpsdr *)calloc( 1, 1000 ) ;
ret = cnc_rdparar( start, axis, end, 1000, buf ) ;
ptr = buf ;
if ( !ret ) {
for ( idx1 = start ; idx1 <= end ; idx1++ ) {
if ( ( idx1 != 0 ) && ( ptr->datano == 0 ) ) break ;
printf( "No.%05d ", ptr->datano ) ;
switch ( ptr->type >> 8 ) {
case 0: printf( "BIT " ) ; break ;
case 1: printf( "BYTE" ) ; break ;
case 2: printf( "WORD" ) ; break ;
case 3: printf( "2WRD" ) ; break ;
}
switch ( ptr->type & 0xff ) {
case 0xff :
for ( idx2 = 0 ; idx2 < axno ; idx2++ ) {
printf( " #%d:", idx2+1 ) ;
switch ( ptr->type >> 8 ) {
case 0:
printf( "0x%02X",
(unsigned char)(ptr->u.cdatas[idx2]) ) ;
inc = 1 ; break ;
case 1:
printf( "%d", ptr->u.cdatas[idx2] ) ;
inc = 1 ; break ;
case 2:
printf( "%d", ptr->u.idatas[idx2] ) ;
inc = 2 ; break ;
case 3:
printf( "%ld", ptr->u.ldatas[idx2] ) ;
inc = 4 ; break ;
}
}
putchar( '\n' ) ;
ptr = (struct iodbpsdr *)(((char *)ptr)+4+8*inc) ;
break ;
/* to be continued on the next page... */