/*gprd.c Read from a specified GPIB port */ /* Robert R. Howell 08/06/94 */ /* Based on track.c */ /****** Various useful defines ******************************************/ /* Convert 8 bits from BCD to binary */ #define BCD_DEC(x) ( ( 10 * ( ( (x)>>4 )&0xf) ) | ((x)&0xF) ) #define DPR ( 57.29577951 ) /* Degrees per radian */ /***** includes **********************************************************/ #include "wirotypes.h" /* Does wiro typedefs and system dependencies */ #include /* Standard libraries */ #include #include #include #include #include #include #include #include #include #include #include #include #include "GPIBports.h" /* contains GPIB interface info */ short encode_ha_rate (double Velocity); short encode_dec_rate (double Velocity); void init (void); /* The master initialization routine */ unsigned short haraw, decraw; /* Here are some structures to read in some data */ struct d80data drives, drives2; struct d80data encoders, encoders2; struct d80data1 paddle; void main(int argc, char *argv[]) { gpibport_setup(); /* This opens up the appropriate channel */ /* so that the other commands can use it */ /* to communicate with the IEEE 488. */ /* Set up encoder port in high speed */ track_init(); /* Call standard wiro initializations */ init( ); /* Init initializes I/O ports and reads data once */ /* Read paddle */ gpib_rd(paddle_adr, (lpchar) &paddle.port1, 5); /* Read paddle mux */ /* switch ( SPEED_BITS & paddle.port5) Getting paddle bits */ /* Read encoders. */ /* gpib_rd(encoder_adr, (lpchar) &encoders.dome, 5); */ /* #ifdef REVERSED */ /* Swap bytes for Intel chips */ /* swab( (char *) &encoders.dec, (char *) &encoders2.dec, 4); memcpy( (char *) &encoders.dec, (char *) &encoders2.dec, 4); */ /* #endif */ #include #include #include "GPIBports.h" #include "wtrack.h" extern int drive_present, encoder_present, paddle_present, hifi_present; extern double sin_lat, cos_lat; extern unsigned short last_ha_enc, last_dec_enc; extern struct d80data encoders, encoders2; extern struct d80data1 paddle; extern struct d80data drives, drives2; */ /***************************************************************************/ /* Open and initialize everything */ /***************************************************************************/ void init( void ) { char msg[81]; unsigned short tmpgray; /* RRH holds shifted gray code value */ /* Configuration values for the 4 IoTech channels (2 per box). */ static char *configs[ 4 ] = /* Configuration reported? */ { "1.1C5E0F0G0I000K0L0000M000P0R0Y0", /* Drive port -- output */ "1.1C0E0F0G0I000K0L0000M000P0R0Y0", /* Encoder port -- input */ "1.1C0E0F0G0I000K0L0000M000P0R0Y0", /* Paddle port -- input */ "1.1C0E0F0G0I000K0L0000M000P0R0Y0" }; static char *defaults[ 4 ] = /* Configuration set. */ { "C5F0G0I000K0L0000M000P0R0Y0XS0X", /* Drive port -- output */ "C0F0G0I000K0L0000M000P0R0Y0XS0X", /* Encoder port -- input */ "C0F0G0I000K0L0000M000P0R0Y0XS0X", /* Paddle port -- input */ "C0F0G0I000K0L0000M000P0R0Y0XS0X" }; /* FIRST, open the path to the IB488 and clear all the devices */ /******************** Init the drive channel **************************/ init_port(drive_adr, "Drive", configs[0], defaults[0]); /******************** Init the encoder channel **********************/ if (encoder_present) init_port(encoder_adr, "Encoder", configs[1], defaults[1]); /******************** Init the paddle channel *************************/ if (paddle_present) init_port(paddle_adr, "Paddle", configs[2], defaults[2]); /***************** Now read the encoders one time. *******************/ printf("Reading encoders once..."); gpib_rd(encoder_adr, (lpchar) &(encoders.dome), 5); printf("Done Initializing. \n"); } /*****************************************************************/ /*****************************************************************/ int init_port(address, name, conf, def) int address; char *name; char *conf; char *def; { char msg[81]; printf("Setting %s channel...",name); fflush(stdout); gpib_clear(address); gpib_wrs(address, "E?X" ); /* Check for errors */ gpib_rds(address, msg, 80); if ( msg[ 1 ] != '0' ) printf( "GPIB %s port error: %s\n", name, msg ); gpib_wrs(address, "U0X" ); /* Check configuration */ gpib_rds(address, msg, 80); if ( strcmp( msg, conf) != 0 ) /* & set it if it is wrong */ { gpib_wrs(address, def ); gpib_wrs(address, "U0X"); /* check one last time */ gpib_rds(address, msg, 80); if ( strcmp( msg, conf ) != 0 ) printf( "Unable to configure GPIB %s port.\n",name); } gpib_wrs(address, "F0X"); /* set fast binary mode */ /* Set to Hex mode for testing */ printf("Done.\n"); }