#include #include #include "Gpib.h" #define PMC 6 /* GPIB address of PMC200-P */ #define BUFLEN 100 /* buffer length for received data */ void init_pmc() { unsigned char buf[BUFLEN]; /* buffer for received data */ gpib_init(); /* initialize the GPIB 1014 */ gpib_write("*IDN?",PMC); gpib_read(buf,BUFLEN,PMC); printf("PMC_ID=%s\n",buf); printf("GPIB_ERR=%d\n",GPIB_ERR); /* gpib_write("*RST",PMC); */ /* software reset, stop motion */ gpib_write("UNITS mm,mm",PMC); /* set units to mm */ return; } float getpos_pmc(int axis) /* returns position of */ { /* actuator */ float position; unsigned char buf[BUFLEN]; /* buffer for received data */ if( axis == 1 ) gpib_write("POS1?",PMC); /* get the current position */ else gpib_write("POS2?",PMC); gpib_read(buf,BUFLEN,PMC); sscanf(buf,"%f\n",&position); return(position); } void mvtopos_pmc(pos,axis) /* moves actuator to */ float pos; /* given position */ int axis; { /* at maximum speed */ unsigned char buf[BUFLEN]; /* buffer for received data */ if( axis == 1 ) gpib_write("VEL1?",PMC); /* get the maximum possible */ else gpib_write("VEL2?",PMC); /* get the maximum possible */ gpib_read(buf+5,BUFLEN,PMC); /* velocity and use it. */ if( axis == 1 ) strcpy(buf,"VEL1"); else strcpy(buf,"VEL2"); buf[4]=' '; gpib_write(buf,PMC); if( axis == 1 ) sprintf(buf,"MOVE1 %8.4f",pos); /* move to destination, */ else sprintf(buf,"MOVE2 %8.4f",pos); /* move to destination, */ gpib_write(buf,PMC); /* and wait until motion */ wait_stop(); /* has stopped. */ return; } void jog_pmc(amount,axis) /* moves actuator by a */ float amount; /* given amount */ int axis; { /* at minimum speed */ unsigned char buf[BUFLEN]; /* buffer for received data */ if( axis == 1 ) { gpib_write("VEL1 0.01",PMC); /* v=0.010 mm/sec */ sprintf(buf,"JOG1 %8.4f",amount); } else { gpib_write("VEL2 0.01",PMC); /* v=0.010 mm/sec */ sprintf(buf,"JOG2 %8.4f",amount); } gpib_write(buf,PMC); /* jog 'amount' */ wait_stop(); return; } /******************************************************************** * * * wait_stop() waits for all actuator movement to stop. * * And while twiddling thumbs, it counts the number of seconds * * it had to wait and returns them. * * * * The device command *OPC (operation complete) sets bit 0 of * * of the eventstatus register to 1. Reading the register * * clears its bits. * * * *********************************************************************/ wait_stop() { unsigned char buf[100]; /* buffer for received data */ int esr; /* event status register */ int count; count=0; gpib_write("*OPC",PMC); /* sets a bit when motion stops */ do{ /* check every second if */ sleep(1); count++; /* motion has stopped */ gpib_write("*ESR?",PMC); /* get the event status register */ gpib_read(buf,BUFLEN,PMC); sscanf(buf,"%d",&esr); } while(!(esr&1)); /* bit 0 is 1 when motion has */ /* stopped */ return(count); }