diff --git a/motorApp/NewFocusSrc/devNewFocus.dbd b/motorApp/NewFocusSrc/devNewFocus.dbd index b672dc05..e188256d 100644 --- a/motorApp/NewFocusSrc/devNewFocus.dbd +++ b/motorApp/NewFocusSrc/devNewFocus.dbd @@ -1,6 +1,6 @@ # NewFocus PicoMotor Network Controller (PMNC) Device Driver support. -device(motor,VME_IO,devPMNC8750,"PMNC8750") -driver(drvPMNC8750) +device(motor,VME_IO,devPMNC87xx,"PMNC87xx") +driver(drvPMNC87xx) registrar(NewFocusRegister) -variable(drvPMNC8750debug) +variable(drvPMNC87xxdebug) diff --git a/motorApp/NewFocusSrc/devPMNC87xx.cc b/motorApp/NewFocusSrc/devPMNC87xx.cc new file mode 100644 index 00000000..c6beec41 --- /dev/null +++ b/motorApp/NewFocusSrc/devPMNC87xx.cc @@ -0,0 +1,412 @@ +/* +FILENAME... devPMNC87xx.cc +USAGE... Motor record device level support for NewFocus 8750 and 8752 Controller . + +Version: 1.3 +Modified By: sluiter +Last Modified: 2004/12/20 21:10:53 +*/ + +/* + * Original Author: Mark Rivers + * Date: 10/16/97 + * Current Author: Joe Sullivan + * + * Experimental Physics and Industrial Control System (EPICS) + * + * Copyright 1991, the Regents of the University of California, + * and the University of Chicago Board of Governors. + * + * This software was produced under U.S. Government contracts: + * (W-7405-ENG-36) at the Los Alamos National Laboratory, + * and (W-31-109-ENG-38) at Argonne National Laboratory. + * + * Initial development by: + * The Controls and Automation Group (AT-8) + * Ground Test Accelerator + * Accelerator Technology Division + * Los Alamos National Laboratory + * + * Co-developed with + * The Controls and Computing Group + * Accelerator Systems Division + * Advanced Photon Source + * Argonne National Laboratory + * + * Modification Log: + * ----------------- + * .00 10-16-97 mlr initialized from devOms58 + * .01 07-19-99 rls initialized from drvMM4000 + * .02 04-21-01 rls Added jog velocity motor command. + * .03 05-22-03 rls Converted to R3.14.x. + * .04 06-20-06 jps initialized from drvPMNC8750 + */ + + +#include +#include "motorRecord.h" +#include "motor.h" +#include "motordevCom.h" +#include "drvPMNCCom.h" +#include "epicsExport.h" + +#define STATIC static + +extern struct driver_table PMNC87xx_access; + +/* ----------------Create the dsets for devPMNC87xx----------------- */ +/* static long report(); */ +STATIC struct driver_table *drvtabptr; +STATIC long PMNC87xx_init(void *); +STATIC long PMNC87xx_init_record(void *); +STATIC long PMNC87xx_start_trans(struct motorRecord *); +STATIC RTN_STATUS PMNC87xx_build_trans(motor_cmnd, double *, struct motorRecord *); +STATIC RTN_STATUS PMNC87xx_end_trans(struct motorRecord *); + +struct motor_dset devPMNC87xx = +{ + {8, NULL, (DEVSUPFUN) PMNC87xx_init, (DEVSUPFUN) PMNC87xx_init_record, NULL}, + motor_update_values, + PMNC87xx_start_trans, + PMNC87xx_build_trans, + PMNC87xx_end_trans +}; + +extern "C" {epicsExportAddress(dset,devPMNC87xx);} + +/* --------------------------- program data --------------------- */ + +/* This table is used to define the command types */ +/* WARNING! this must match "motor_cmnd" in motor.h */ + +static msg_types PMNC87xx_table[] = { + MOTION, /* MOVE_ABS */ + MOTION, /* MOVE_REL */ + MOTION, /* HOME_FOR */ + MOTION, /* HOME_REV */ + IMMEDIATE, /* LOAD_POS */ + IMMEDIATE, /* SET_VEL_BASE */ + IMMEDIATE, /* SET_VELOCITY */ + IMMEDIATE, /* SET_ACCEL */ + IMMEDIATE, /* GO */ + IMMEDIATE, /* SET_ENC_RATIO */ + INFO, /* GET_INFO */ + MOVE_TERM, /* STOP_AXIS */ + VELOCITY, /* JOG */ + IMMEDIATE, /* SET_PGAIN */ + IMMEDIATE, /* SET_IGAIN */ + IMMEDIATE, /* SET_DGAIN */ + IMMEDIATE, /* ENABLE_TORQUE */ + IMMEDIATE, /* DISABL_TORQUE */ + IMMEDIATE, /* PRIMITIVE */ + IMMEDIATE, /* SET_HIGH_LIMIT */ + IMMEDIATE, /* SET_LOW_LIMIT */ + VELOCITY /* JOG_VELOCITY */ +}; + + +static struct board_stat **PMNC87xx_cards; + +/* --------------------------- program data --------------------- */ + + +/* initialize device support for PMNC87xx stepper motor */ +STATIC long PMNC87xx_init(void *arg) +{ + long rtnval; + int after = (int) arg; + + if (after == 0) + { + drvtabptr = &PMNC87xx_access; + (drvtabptr->init)(); + } + + rtnval = motor_init_com(after, *drvtabptr->cardcnt_ptr, drvtabptr, &PMNC87xx_cards); + return(rtnval); +} + + +/* initialize a record instance */ +STATIC long PMNC87xx_init_record(void *arg) +{ + struct motorRecord *mr = (struct motorRecord *) arg; + return(motor_init_record_com(mr, *drvtabptr->cardcnt_ptr, drvtabptr, PMNC87xx_cards)); +} + + +/* start building a transaction */ +STATIC long PMNC87xx_start_trans(struct motorRecord *mr) +{ + return(motor_start_trans_com(mr, PMNC87xx_cards)); +} + + +/* end building a transaction */ +STATIC RTN_STATUS PMNC87xx_end_trans(struct motorRecord *mr) +{ + return(motor_end_trans_com(mr, drvtabptr)); +} + + +/* add a part to the transaction */ +STATIC RTN_STATUS PMNC87xx_build_trans(motor_cmnd command, double *parms, struct motorRecord *mr) +{ + struct motor_trans *trans = (struct motor_trans *) mr->dpvt; + struct mess_node *motor_call; + struct mess_info *motor_info; + struct controller *brdptr; + struct PMNCcontroller *cntrl; + struct PMD_axis *paxisDef; + PMD_model dType; + + char buff[110]; + int axis, card; + int drive, motor; + unsigned int size; + int intval; + RTN_STATUS rtnval; + bool sendMsg; + + rtnval = OK; + buff[0] = '\0'; + sendMsg = true; + + motor_start_trans_com(mr, PMNC87xx_cards); + + motor_call = &(trans->motor_call); + card = motor_call->card; + axis = motor_call->signal; + + motor_call->type = PMNC87xx_table[command]; + brdptr = (*trans->tabptr->card_array)[card]; + if (brdptr == NULL) + return(rtnval = ERROR); + cntrl = (struct PMNCcontroller *) brdptr->DevicePrivate; + + + paxisDef = &cntrl->axisDef[axis]; + drive = paxisDef->driverNum; + motor = paxisDef->motorNum; + dType = paxisDef->driverType; + + if (PMNC87xx_table[command] > motor_call->type) + motor_call->type = PMNC87xx_table[command]; + + if (trans->state != BUILD_STATE) + return(rtnval = ERROR); + + if (command == PRIMITIVE && mr->init != NULL && strlen(mr->init) != 0) + strcat(motor_call->message, mr->init); + + switch (command) + { + case SET_PGAIN: + case SET_IGAIN: + case SET_DGAIN: + break; + case MOVE_ABS: + case MOVE_REL: + case HOME_FOR: + case HOME_REV: + case JOG: + if (strlen(mr->prem) != 0) + { + strcat(motor_call->message, mr->prem); + rtnval = motor_end_trans_com(mr, drvtabptr); + rtnval = (RTN_STATUS) motor_start_trans_com(mr, PMNC87xx_cards); + motor_call->type = PMNC87xx_table[command]; + + } + if (strlen(mr->post) != 0) + motor_call->postmsgptr = (char *) &mr->post; + default: + /* Protect against NULL pointer with WRTITE_MSG(GO/STOP_AXIS/GET_INFO, NULL). */ + intval = (parms == NULL) ? 0 : NINT(parms[0]); + break; + } + + motor_info = &((*drvtabptr->card_array)[card]->motor_info[axis]); + + switch (command) + { + case MOVE_ABS: + if (dType == PMD8753) + sprintf(buff, "REL A%d=%d G", drive, intval-motor_info->position); + else + sprintf(buff, "ABS A%d=%d G", drive, intval); + break; + case MOVE_REL: + sprintf(buff, "REL A%d=%d G", drive, intval); + break; + case HOME_FOR: + // if (dType == PMD8751) + // sprintf(buff, "FIN A%d", drive); + // else + trans->state = IDLE_STATE; /* No command sent to the controller. */ + sendMsg = false; + break; + case HOME_REV: + // if (dType == PMD8751) + // sprintf(buff, "RIN A%d", drive); + // else + trans->state = IDLE_STATE; /* No command sent to the controller. */ + sendMsg = false; + break; + case LOAD_POS: + + if (dType == PMD8753) + { + /* Setting local driver position because the controller cannot be set */ + sprintf(buff, "CHL A%d=%d", drive, motor); + motor_info->position = intval; + } + else if (dType == PMD8751) + { + /* Closed loop driver - able to set position */ + sprintf(buff, "POS %d=%d", drive, intval); + } + else + { + trans->state = IDLE_STATE; /* No command sent to the controller. */ + sendMsg = false; + } + + break; + case SET_VEL_BASE: + if (dType == PMD8753) + { + if (abs(intval) > 1999) + intval = 1999; + /* Set VEL to maximum to eliminate MPV out-of-range error */ + sprintf(buff, "VEL A%d %d=2000", drive, motor); + strcpy(motor_call->message, buff); + + rtnval = motor_end_trans_com(mr, drvtabptr); + rtnval = (RTN_STATUS) motor_start_trans_com(mr, PMNC87xx_cards); + motor_call->type = PMNC87xx_table[command]; + + + sprintf(buff, "MPV A%d %d=%d", drive, motor, abs(intval)); + } + else // if (dType == PMD8751) + { + trans->state = IDLE_STATE; /* No command sent to the controller. */ + sendMsg = false; + } + + break; + case SET_VELOCITY: + if (abs(intval) > 2000) + intval = 2000; + sprintf(buff, "VEL A%d %d=%d", drive, motor, abs(intval)); + break; + case SET_ACCEL: + /* + * The value passed is in steps/sec/sec. + */ + sprintf(buff, "ACC A%d %d=%d", drive, motor, intval); + break; + case GO: + // GO included in motion commands - fake command to get response + sprintf(buff, "CHL %d", drive); + break; + case SET_ENC_RATIO: + trans->state = IDLE_STATE; /* No command sent to the controller. */ + sendMsg = false; + break; + case PRIMITIVE: + case GET_INFO: + /* These commands are not actually done by sending a message, but + rather they will indirectly cause the driver to read the status + of all motors */ + break; + case STOP_AXIS: + sprintf(buff, "HAL A%d", drive); /* Using the smooth stop command */ + break; + case JOG: + if (dType == PMD8753) + { + if (intval >= 0) + sprintf(buff, "FOR A%d=%d G", drive, intval); + else + sprintf(buff, "REV A%d=%d G", drive, abs(intval)); + } + else if (dType == PMD8751) + { + if (abs(intval) > 2000) + intval = 2000; + sprintf(buff, "VEL A%d %d=%d", drive, motor, abs(intval)); + + strcpy(motor_call->message, buff); + rtnval = motor_end_trans_com(mr, drvtabptr); + rtnval = (RTN_STATUS) motor_start_trans_com(mr, PMNC87xx_cards); + motor_call->type = PMNC87xx_table[command]; + + // Use Relative Move command for jogging + // because the 8751 does not indicate motion with (FOR and REV) + // ** BUG? ** + if (intval >= 0) + sprintf(buff, "REL A%d=1000000 G",drive); + else + sprintf(buff, "REL A%d=-1000000 G",drive); + } + else + sendMsg = false; + + break; + case SET_PGAIN: + case SET_IGAIN: + case SET_DGAIN: + trans->state = IDLE_STATE; /* No command sent to the controller. */ + sendMsg = false; + break; + case ENABLE_TORQUE: + if (dType == PMD8751) + sprintf(buff, "SER A%d", drive); + else if (dType == PMD8753) + sprintf(buff, "MON A%d", drive); + else + { + trans->state = IDLE_STATE; /* No command sent to the controller. */ + sendMsg = false; + } + + break; + case DISABL_TORQUE: + if (dType == PMD8751) + sprintf(buff, "NOS A%d", drive); + else if (dType == PMD8753) + sprintf(buff, "MOF A%d", drive); + else + { + trans->state = IDLE_STATE; /* No command sent to the controller. */ + sendMsg = false; + } + break; + case SET_HIGH_LIMIT: + case SET_LOW_LIMIT: + trans->state = IDLE_STATE; /* No command sent to the controller. */ + sendMsg = false; + break; + default: + sendMsg = false; + rtnval = ERROR; + } + + + if (sendMsg == true) + { + size = strlen(buff); + + if (size > sizeof(buff) || (strlen(motor_call->message) + size) > MAX_MSG_SIZE) + errlogMessage("PMNC87xx_build_trans(): buffer overflow.\n"); + else + { + strcat(motor_call->message, buff); + motor_end_trans_com(mr, drvtabptr); + } + } + + return(rtnval); +} diff --git a/motorApp/NewFocusSrc/drvPMNC87xx.cc b/motorApp/NewFocusSrc/drvPMNC87xx.cc new file mode 100644 index 00000000..df44fd39 --- /dev/null +++ b/motorApp/NewFocusSrc/drvPMNC87xx.cc @@ -0,0 +1,971 @@ +/* +FILENAME... drvPMNC87xx.cc +USAGE... Motor record driver level support for NewFocus PMNC87xx. + +Version: 1.17 +Modified By: sullivan +Last Modified: 2005/03/30 19:10:48 +*/ + +/* + * Original Author: Mark Rivers + * Date: 06/28/06 + * Current Author: Joe Sullivan + * + * Experimental Physics and Industrial Control System (EPICS) + * + * Copyright 1991, the Regents of the University of California, + * and the University of Chicago Board of Governors. + * + * This software was produced under U.S. Government contracts: + * (W-7405-ENG-36) at the Los Alamos National Laboratory, + * and (W-31-109-ENG-38) at Argonne National Laboratory. + * + * Initial development by: + * The Controls and Automation Group (AT-8) + * Ground Test Accelerator + * Accelerator Technology Division + * Los Alamos National Laboratory + * + * Co-developed with + * The Controls and Computing Group + * Accelerator Systems Division + * Advanced Photon Source + * Argonne National Laboratory + * + * Modification Log: + * ----------------- + * .01 10-20-97 mlr initialized from drvOms58 + * .02 10-30-97 mlr Replaced driver calls with gpipIO functions + * .03 10-30-98 mlr Minor code cleanup, improved formatting + * .04 02-01-99 mlr Added temporary fix to delay reading motor positions at + * the end of a move. + * .05 04-18-00 rls PMNC87xx takes 2 to 5 seconds to respond to queries after + * hitting a hard travel limit. Adjusted GPIB and SERIAL + * timeouts accordingly. Deleted communication retries. + * Reworked travel limit processing so that direction + * status bit matches limit switch. Copied recv_mess() + * logic from drvMM4000.c. Use TPE command to determine + * if motor has an encoder. + * .06 10/02/01 rls - allow one retry after a communication error. + * - use motor status response bit-field. + * .07 05-22-03 rls - Converted to R3.14.2. + * .08 10/23/03 rls - recv_mess() eats the controller error response, outputs + * an error message and retries. + * .09 02/03/04 rls - Eliminate erroneous "Motor motion timeout ERROR". + * .10 07/09/04 rls - removed unused Setup() argument. + * .11 07/28/04 rls - "epicsExport" debug variable. + * .12 09/21/04 rls - support for 32axes/controller. + * .13 12/21/04 rls - MS Visual C compatibility; make all epicsExportAddress + * extern "C" linkage. + * - make debug variables always available. + * .14 01/11/06 jps - initialize from drvMM3000.cc + * + */ + +#include +#include +#include +#include "NewFocusRegister.h" +#include "drvPMNCCom.h" +#include "asynOctetSyncIO.h" +#include "epicsExport.h" + +#define STATIC static + +#define READ_RESOLUTION "VER" +#define READ_STATUS "STA %d" +#define READ_DIAG "DIAG %d" +#define READ_POS "POS %d" +#define READ_CHAN_SELECT "CHL %d" +#define STOP_ALL "STO" +#define INIT_ALL "INI" +#define MOTOR_ON "MON" +#define MOTOR_OFF "MOF" +#define JOY_ON "JON" +#define GET_IDENT "VER" +#define GET_MPV "MPV" /* Query Minimum Profile Velocity */ + +#define GET_DRT "DRT" /* Query Driver Types */ + +#define VER_STR "Version 1." + +#define PROMPT_EOS ">" +#define NL_EOS "\n" +#define CMND_EOS "\r" + +/* Status byte bits */ +#define M_AXIS_MOVING 0x01 +#define M_MOTOR_POWER 0x02 +#define M_MOTOR_DIRECTION 0x04 +#define M_PLUS_LIMIT 0x08 +#define M_MINUS_LIMIT 0x10 +#define M_HOME_SIGNAL 0x20 + +#define BUFF_SIZE 100 /* Maximum length of string to/from PMNC87xx */ + +#define PMNC_TIMEOUT 3.0 /* Command timeout in sec. */ + +/*----------------debugging-----------------*/ +#ifdef __GNUG__ + #ifdef DEBUG + #define Debug(l, f, args...) { if(l<=drvPMNC87xxdebug) printf(f,## args); } + #else + #define Debug(l, f, args...) + #endif +#else + #define Debug() +#endif +volatile int drvPMNC87xxdebug = 0; +extern "C" {epicsExportAddress(int, drvPMNC87xxdebug);} + +/* --- Local data. --- */ +int PMNC87xx_num_cards = 0; +int PMNC87xx_num_drivers = 0; /* Number of Drivers per Controller */ +char nobuff[BUFF_SIZE]; /* Scratch buffer - noreply commands */ + +/* Local data required for every driver; see "motordrvComCode.h" */ +#include "motordrvComCode.h" + +/*----------------functions-----------------*/ +STATIC int recv_mess(int, char *, int); +STATIC RTN_STATUS send_mess(int, char const *, char *); +STATIC int send_recv_mess(int, char const *, char *, char const *); +STATIC int set_status(int, int); +STATIC void start_status(int); +static long report(int); +static long init(); +STATIC int motor_init(); +STATIC void query_done(int, int, struct mess_node *); + +/*----------------functions-----------------*/ + +struct driver_table PMNC87xx_access = +{ + motor_init, + motor_send, + motor_free, + motor_card_info, + motor_axis_info, + &mess_queue, + &queue_lock, + &free_list, + &freelist_lock, + &motor_sem, + &motor_state, + &total_cards, + &any_motor_in_motion, + send_mess, + recv_mess, + set_status, + query_done, + NULL, + &initialized, + NULL +}; + +struct +{ + long number; + long (*report) (int); + long (*init) (void); +} drvPMNC87xx = {2, report, init}; + +extern "C" {epicsExportAddress(drvet, drvPMNC87xx);} + +STATIC struct thread_args targs = {SCAN_RATE, &PMNC87xx_access, 0.0}; + +/********************************************************* + * Print out driver status report + *********************************************************/ +static long report(int level) +{ + int card; + + if (PMNC87xx_num_cards <=0) + printf(" No PMNC87xx controllers configured.\n"); + else + { + for (card = 0; card < PMNC87xx_num_cards; card++) + { + struct controller *brdptr = motor_state[card]; + + if (brdptr == NULL) + printf(" PMNC87xx controller %d connection failed.\n", card); + else + { + struct PMNCcontroller *cntrl; + + cntrl = (struct PMNCcontroller *) brdptr->DevicePrivate; + printf(" PMNC87xx controller %d asyn port= %s, address=%d, id: %s \n", + card, cntrl->asyn_port, cntrl->asyn_address, + brdptr->ident); + break; + } + } + } + return(OK); +} + + +static long init() +{ + /* + * We cannot call motor_init() here, because that function can do GPIB I/O, + * and hence requires that the drvGPIB have already been initialized. + * That cannot be guaranteed, so we need to call motor_init from device + * support + */ + /* Check for setup */ + if (PMNC87xx_num_cards <= 0) + { + Debug(1, "init(): PMNC87xx driver disabled. PMNC87xxSetup() missing from startup script.\n"); + } + return((long) 0); +} + + +STATIC void query_done(int card, int axis, struct mess_node *nodeptr) +{ +} + + +/********************************************************* + * Read the status and position of all motors on a card + * start_status(int card) + * if card == -1 then start all cards + *********************************************************/ +STATIC void start_status(int card) +{ +} + +/************************************************************** + * Parse status and position strings for a card and signal + * set_status() + ************************************************************/ + +#define CHECKRTN \ + if (recvRtn > 0) { \ + cntrl->status = NORMAL; \ + status.Bits.CNTRL_COMM_ERR = 0; \ + } \ + else { \ + if (cntrl->status == NORMAL) { \ + cntrl->status = RETRY; \ + setReturn=0; \ + } \ + else { \ + cntrl->status = COMM_ERR; \ + status.Bits.CNTRL_COMM_ERR = 1; \ + status.Bits.RA_PROBLEM = 1; \ + setReturn = 1; \ + } \ + goto exit; \ + } + + +STATIC int set_status(int card, int signal) +{ + struct PMNCcontroller *cntrl; + struct mess_node *nodeptr; + register struct mess_info *motor_info; + /* Message parsing variables */ + char *pStr; + char buff[BUFF_SIZE]; + MOTOR_STATUS mstat; + MOTOR_AUX_STATUS auxstat; + struct PMD_axis *signalDef; + int setReturn; + int recvRtn; + int driverID, motorID; + int recvDriver, recvStatus; + long motorData; + int selectMotor; + bool plusdir, ls_active = false; + msta_field status; + + + setReturn = 0; + cntrl = (struct PMNCcontroller *) motor_state[card]->DevicePrivate; + motor_info = &(motor_state[card]->motor_info[signal]); + status.All = motor_info->status.All; + + signalDef = &cntrl->axisDef[signal]; + + /* Get the motor information */ + driverID = signalDef->driverNum; + motorID = signalDef->motorNum; + + if (signalDef->driverType == PMD8753) + { + sprintf(buff, READ_CHAN_SELECT, driverID); + pStr = cntrl->chan_select_string[driverID]; + recvRtn = send_recv_mess(card, buff, pStr, NULL); + CHECKRTN; + Debug(2, "start_status(): ChanSelect_string=%s\n", pStr); + selectMotor = atoi(pStr); + } + else + selectMotor = 0; /* PMD8751 only has one motor */ + + + /* Set defaults in-case motor is not selected */ + motorData = cntrl->last_position[signal]; + mstat.All = 0; + auxstat.All = 0; + + sprintf(buff, READ_STATUS, driverID); + pStr = cntrl->status_string[driverID]; + /* STATUS command does not return a prompt - bug? */ + recvRtn = send_recv_mess(card, buff, pStr, NL_EOS); + CHECKRTN; + Debug(2, "set_status(): Status_string=%s\n", pStr); + if (sscanf(pStr, "A%d=0x%x",&recvDriver, &recvStatus) == 2) + { + mstat.All = recvStatus; + Debug(5, "set_status(): drive %d - status byte = %x\n", recvDriver, recvStatus); + } + else + Debug(1, "set_status(): drive %d - INVALID status string %s\n", driverID, pStr); + + + if (signalDef->driverType == PMD8751) + { + sprintf(buff, READ_DIAG, driverID); + pStr = cntrl->aux_status_string[driverID]; + recvRtn = send_recv_mess(card, buff, pStr, NULL); + CHECKRTN; + Debug(2, "set_status(): Aux Status_string=%s\n", pStr); + if (sscanf(pStr, "A%d=0x%x",&recvDriver, &recvStatus) == 2) + { + auxstat.All = recvStatus; + Debug(5, "set_status(): drive %d - status byte = %x\n", recvDriver, recvStatus); + } + else + Debug(1, "set_status(): drive %d - INVALID Aux Status string %s\n", driverID, pStr); + } + + /* Check if set_status() motor is currently selected on driver */ + if (selectMotor == motorID) + { + sprintf(buff, READ_POS, driverID); + pStr = cntrl->position_string[driverID]; + recvRtn = send_recv_mess(card, buff, pStr, NULL); + CHECKRTN; + Debug(2, "set_status(): postion_string=%s\n", pStr); + if (sscanf(pStr, "A%d=%ld",&recvDriver, &motorData) == 2) + { + Debug(5, "set_status(): drive %d = Position:%ld\n", recvDriver, motorData); + } + else + Debug(1, "set_status(): drive %d - INVALID position string %s\n", driverID, pStr); + } + else + { + if (signalDef->driverType == PMD8753) + motorData = cntrl->last_position[signal] = 0; + + Debug(5, "set_status(): NOT SELECTED drive %d, motor %d\n", driverID, motorID); + } + + + nodeptr = motor_info->motor_motion; + + + /* Interpret data and move it into global area */ + + if (signalDef->driverType == PMD8753) // Open-Loop Driver + { + /* Drive Enabled */ + status.Bits.EA_POSITION = (mstat.Bits_8753.powerOn) ? 1: 0; + + if (mstat.Bits_8753.inMotion == false) + status.Bits.RA_DONE = 1; + else if (selectMotor == motorID) // Moving only applies to selected motor + status.Bits.RA_DONE = 0; + + /* Limit Switch Status - NOT AVAILABLE */ + status.Bits.RA_PLUS_LS = 0; + status.Bits.RA_MINUS_LS = 0; + status.Bits.RA_HOME = 0; + + /* encoder status - NOT AVAILABLE */ + status.Bits.EA_SLIP = 0; + status.Bits.EA_SLIP_STALL = 0; + status.Bits.EA_HOME = 0; + } + else if (signalDef->driverType == PMD8751) // Closed-Loop Driver + { + // if (mstat.Bits_8751.moveDone == true && (mstat.Bits_8751.homing == false || motor_info->no_motion_count > 5)) + if (mstat.Bits_8751.moveDone == true) + status.Bits.RA_DONE = 1; + else + status.Bits.RA_DONE = 0; + + /* Drive Enabled */ + status.Bits.EA_POSITION = (auxstat.Bits_8751.servoOn) ? 1: 0; + + if (mstat.Bits_8751.powerOn && auxstat.Bits_8751.servoOn) + { + /* Limit Switch Status */ + status.Bits.RA_PLUS_LS = ((mstat.Bits_8751.forLimit) ? 1: 0); + status.Bits.RA_MINUS_LS = ((mstat.Bits_8751.revLimit) ? 1: 0); + status.Bits.RA_HOME = ((mstat.Bits_8751.homing) ? 1: 0); + } + + /* encoder status - NOT AVAILABLE */ + status.Bits.EA_SLIP = 0; + status.Bits.EA_SLIP_STALL = 0; + status.Bits.EA_HOME = 0; + } + + + Debug(2, "set_status(): Axis:%d, New Pos: %ld, Last Pos: %ld", signal, motorData, cntrl->last_position[signal]); + + if (motorData == cntrl->last_position[signal]) + { + motor_info->no_motion_count++; + status.Bits.RA_DIRECTION = 1; + } + else + { + if (signalDef->driverType == PMD8751) // Closed-Loop Driver + motor_info->position = motorData; + else + motor_info->position += (motorData - cntrl->last_position[signal]); + + if (motor_state[card]->motor_info[signal].encoder_present == YES) + { + if (signalDef->driverType == PMD8751) // Closed-Loop Driver + motor_info->encoder_position = (epicsInt32) motorData; + else + motor_info->encoder_position += (epicsInt32) (motorData - cntrl->last_position[signal]); + } + else + motor_info->encoder_position = 0; + + /* Use sign of motor position (always relative) for direction */ + if (signalDef->driverType == PMD8753) + status.Bits.RA_DIRECTION = (motorData >= 0) ? 1 : 0; + else if (signalDef->driverType == PMD8751) + status.Bits.RA_DIRECTION = ((motorData - cntrl->last_position[signal]) >= 0) ? 1 : 0; + + cntrl->last_position[signal] = motorData; + motor_info->no_motion_count = 0; + } + + + plusdir = (status.Bits.RA_DIRECTION) ? true : false; + Debug(1, ", Pos: %d, Dir: %x\n", motor_info->position, plusdir); + + /* Determine if move done because of limit switches */ + if ((plusdir && status.Bits.RA_PLUS_LS) || (!plusdir && status.Bits.RA_MINUS_LS)) + ls_active = true; + + status.Bits.RA_PROBLEM = 0; + + /* Parse motor velocity? */ + /* NEEDS WORK */ + + motor_info->velocity = 0; + + // if (!plusdir) + // motor_info->velocity *= -1; + + setReturn = (!motor_info->no_motion_count || ls_active == true || + status.Bits.RA_DONE | status.Bits.RA_PROBLEM) ? 1 : 0; + + /* Test for post-move processing. */ + if ((status.Bits.RA_DONE || ls_active == true) ) + { + if (signalDef->driverType == PMD8753) + { + cntrl->last_position[signal] = 0; /* Reset last position after each move */ + + if (selectMotor == motorID) + { + /* Clear position on selected motor */ + sprintf(buff, "CHL A%d=%d", driverID, motorID); + send_recv_mess(card, buff, nobuff, NULL); + } + } + + if (nodeptr != 0) + { + /* Allways turn joystick on after a move */ + /* strcpy(buff, JOY_ON); */ + + if (nodeptr->postmsgptr != 0) /* Test for post move record string */ + { + strcpy(buff, nodeptr->postmsgptr); + send_recv_mess(card, buff, nobuff, NULL); + } + + nodeptr->postmsgptr = NULL; + } + } + +exit: + motor_info->status.All = status.All; + return(setReturn); +} + + +/*****************************************************/ +/* atomic write/read function */ +/* PMNC87xx motor controller has a handshake */ +/* with the return of the prompt '>' character */ +/* send_recv_mess() */ +/*****************************************************/ +STATIC int send_recv_mess(int card, char const *send_com, char *recv_com, char const *eos) +{ + struct PMNCcontroller *cntrl; + int size; + size_t nwrite; + size_t nread = 0; + asynStatus status; + int eomReason; + + + size = strlen(send_com); + recv_com[0] = '\0'; + + if (size > MAX_MSG_SIZE) + { + errlogMessage("drvPMNC87xx:send_recv_mess(); message size violation.\n"); + return(ERROR); + } + else if (size == 0) /* Normal exit on empty input message. */ + return (OK); + + if (!motor_state[card]) + { + errlogPrintf("drvPMNC87xx:send_recv_mess() - invalid card #%d\n", card); + return(ERROR); + } + + Debug(2, "send_recv_mess(): message = %s\n", send_com); + + cntrl = (struct PMNCcontroller *) motor_state[card]->DevicePrivate; + + if (eos) + // Temporary Change to End-of-string + pasynOctetSyncIO->setInputEos(cntrl->pasynUser,eos,strlen(eos)); + + + /* Perform atomic write/read operation */ + status = pasynOctetSyncIO->writeRead(cntrl->pasynUser, send_com, size, + recv_com, BUFF_SIZE-1, + PMNC_TIMEOUT, &nwrite, &nread, &eomReason); + if ((status != asynSuccess) || (nread <= 0)) + { + recv_com[0] = '\0'; + nread = ERROR; + } + + if (eos) + // Reset EOS to default + pasynOctetSyncIO->setInputEos(cntrl->pasynUser,PROMPT_EOS,strlen(PROMPT_EOS)); + + + Debug(2, "send_recv_mess(): recv message = \"%s\"\n", recv_com); + + return(nread); + +} +/*****************************************************/ +/* send a message to the PMNC87xx board */ +/* send_mess() */ +/*****************************************************/ +STATIC RTN_STATUS send_mess(int card, char const *com, char *name) +{ + struct PMNCcontroller *cntrl; + int size; + size_t nwrite; + + size = strlen(com); + + if (size > MAX_MSG_SIZE) + { + errlogMessage("drvPMNC87xx:send_mess(); message size violation.\n"); + return(ERROR); + } + else if (size == 0) /* Normal exit on empty input message. */ + return(OK); + + if (!motor_state[card]) + { + errlogPrintf("drvPMNC87xx:send_mess() - invalid card #%d\n", card); + return(ERROR); + } + + if (name != NULL) + { + errlogPrintf("drvPMNC87xx:send_mess() - invalid argument = %s\n", name); + return(ERROR); + } + + Debug(2, "send_mess(): message = %s\n", com); + + cntrl = (struct PMNCcontroller *) motor_state[card]->DevicePrivate; + pasynOctetSyncIO->write(cntrl->pasynUser, com, size, + PMNC_TIMEOUT, &nwrite); + + return(OK); +} + + +/* + * FUNCTION... recv_mess(int card, char *com, int flag) + * + * INPUT ARGUMENTS... + * card - controller card # (0,1,...). + * *com - caller's response buffer. + * flag | FLUSH = flush controller's output buffer; set timeout = 0. + * | !FLUSH = retrieve response into caller's buffer; set timeout. + * | 0 = read until '\n' + * | 1 = read until '>' + * + * LOGIC... + * Initialize: + * - receive timeout to zero + * - received string length to zero. + * + * IF controller card does not exist. + * ERROR RETURN. + * ENDIF + * + * SWITCH on port type. + * CASE port type is GPIB. + * BREAK. + * CASE port type is RS232. + * IF input "flag" indicates NOT flushing the input buffer. + * Set receive timeout nonzero. + * ENDIF + * Call pasynOctetSyncIO->read(). + * + * NOTE: The PMNC87xx sometimes responds to an MS command with an error + * message (see PMNC87xx User's Manual Appendix A). This is an + * unconfirmed PMNC87xx bug. Retry read if this is a Hard Travel + * limit switch error. This effectively flushes the error message. + * + * IF input "com" buffer length is > 3 characters, AND, the 1st + * character is an "E" (Maybe this an unsolicited error + * message response?). + * Call pasynOctetSyncIO->read(). + * ENDIF + * BREAK + * ENDSWITCH + * + * NORMAL RETURN. + */ + +STATIC int recv_mess(int card, char *com, int flag) +{ + struct PMNCcontroller *cntrl; + double timeout = 0.; + int flush = 1; + size_t nread = 0; + int eomReason; + asynStatus status; + + /* Check that card exists */ + if (!motor_state[card]) + return(ERROR); + + cntrl = (struct PMNCcontroller *) motor_state[card]->DevicePrivate; + + if (flag != FLUSH) { + flush = 0; + timeout = PMNC_TIMEOUT; + } + if (flush) status = pasynOctetSyncIO->flush(cntrl->pasynUser); + + if (flag == 0) + // Temporary Change to EOS to '\n' + pasynOctetSyncIO->setInputEos(cntrl->pasynUser,NL_EOS,strlen(NL_EOS)); + + status = pasynOctetSyncIO->read(cntrl->pasynUser, com, BUFF_SIZE, + timeout, &nread, &eomReason); + + if ((status != asynSuccess) || (nread <= 0)) + { + com[0] = '\0'; + nread = 0; + } + else + com[nread-1] = '\0'; + + if (flag == 0) + // Reset EOS to '\n' + pasynOctetSyncIO->setInputEos(cntrl->pasynUser,PROMPT_EOS,strlen(PROMPT_EOS)); + + Debug(2, "recv_mess(): message = \"%s\"\n", com); + return (nread); +} + + +/*****************************************************/ +/* Setup system configuration */ +/* PMNC87xxSetup() */ +/*****************************************************/ +RTN_STATUS +PMNC87xxSetup(int num_cards, /* maximum number of controllers in system. */ + int num_drivers, /* maximum number of drivers per controller */ + int scan_rate) /* polling rate - 1/60 sec units. */ +{ + int itera; + + if (num_cards < 1 || num_cards > PMNC87xx_NUM_CARDS) + PMNC87xx_num_cards = PMNC87xx_NUM_CARDS; + else + PMNC87xx_num_cards = num_cards; + + if (num_drivers < 1 || num_drivers > PMNC87xx_NUM_DRIVERS) + PMNC87xx_num_drivers = PMNC87xx_NUM_DRIVERS; + else + PMNC87xx_num_drivers = num_drivers; + + + /* Set motor polling task rate */ + if (scan_rate >= 1 && scan_rate <= 60) + targs.motor_scan_rate = scan_rate; + else + targs.motor_scan_rate = SCAN_RATE; + + /* + * Allocate space for motor_state structures. Note this must be done + * before PMNC87xxConfig is called, so it cannot be done in motor_init() + * This means that we must allocate space for a card without knowing + * if it really exists, which is not a serious problem + */ + motor_state = (struct controller **) malloc(PMNC87xx_num_cards * + sizeof(struct controller *)); + + for (itera = 0; itera < PMNC87xx_num_cards; itera++) + motor_state[itera] = (struct controller *) NULL; + + return(OK); +} + + +/*****************************************************/ +/* Configure a controller */ +/* PMNC87xxConfig() */ +/*****************************************************/ +RTN_STATUS +PMNC87xxConfig(int card, /* card being configured */ + const char *port, /* asyn port name */ + int address) /* asyn address (GPIB) */ +{ + struct PMNCcontroller *cntrl; + + if (card < 0 || card >= PMNC87xx_num_cards) + return (ERROR); + + motor_state[card] = (struct controller *) malloc(sizeof(struct controller)); + motor_state[card]->DevicePrivate = malloc(sizeof(struct PMNCcontroller)); + cntrl = (struct PMNCcontroller *) motor_state[card]->DevicePrivate; + + strcpy(cntrl->asyn_port, port); + cntrl->asyn_address = address; + return(OK); +} + + + +/*****************************************************/ +/* initialize all software and hardware */ +/* This is called from the initialization routine in */ +/* device support. */ +/* motor_init() */ +/*****************************************************/ +STATIC int motor_init() +{ + struct controller *brdptr; + struct PMNCcontroller *cntrl; + struct PMD_axis *axisdef; + int card_index, motor_index; + char buff[BUFF_SIZE]; + char *bufptr; + int total_axis = 0; + int driverIndex; + int rtnCnt; + asynStatus success_rtn; + + initialized = true; /* Indicate that driver is initialized. */ + + /* Check for setup */ + if (PMNC87xx_num_cards <= 0) + return(ERROR); + + for (card_index = 0; card_index < PMNC87xx_num_cards; card_index++) + { + if (!motor_state[card_index]) + continue; + + brdptr = motor_state[card_index]; + brdptr->cmnd_response = true; + total_cards = card_index + 1; + cntrl = (struct PMNCcontroller *) brdptr->DevicePrivate; + + /* Initialize communications channel */ + success_rtn = pasynOctetSyncIO->connect(cntrl->asyn_port, + cntrl->asyn_address, &cntrl->pasynUser, NULL); + if (success_rtn == asynSuccess) + { + int retry = 0; + + /* Set command End-of-string */ + pasynOctetSyncIO->setInputEos(cntrl->pasynUser,PROMPT_EOS,strlen(PROMPT_EOS)); + pasynOctetSyncIO->setOutputEos(cntrl->pasynUser,CMND_EOS,strlen(CMND_EOS)); + + + /* Send a message to the board, see if it exists */ + /* flush any junk at input port - should not be any data available */ + pasynOctetSyncIO->flush(cntrl->pasynUser); + + + do + { + rtnCnt = send_recv_mess(card_index, GET_IDENT, buff, NULL); + retry++; + /* Return value is length of response string */ + } while(rtnCnt <= 0 && retry < 3); + + } + + if (success_rtn == asynSuccess && rtnCnt > 0) + { + strncpy(brdptr->ident, &buff[0], MAX_IDENT_LEN); /* Save Version info */ brdptr->localaddr = (char *) NULL; + brdptr->motor_in_motion = 0; + send_recv_mess(card_index, STOP_ALL, nobuff, NULL); /* Stop all motors */ + // send_recv_mess(card_index, INIT_ALL, nobuff, NULL); /* Initalize all devices - takes > 5 sec */ + // send_recv_mess(card_index, MOTOR_ON, nobuff, NULL); /* Enable all motors */ + + /* Set Motion Master model indicator. */ + bufptr = strstr(brdptr->ident, VER_STR); + if (bufptr == NULL) + { + errlogPrintf("drvPMNC87xx.c:motor_init() - unknown version = %s\n", brdptr->ident); + motor_state[card_index] = (struct controller *) NULL; + continue; + } + /* Check for known version - 1.x */ + switch (*(bufptr + strlen(VER_STR))) + { + case '0': + cntrl->pmnc = PMNC8750; + break; + case '5': + case '6': + cntrl->pmnc = PMNC8752; + break; + default: + errlogPrintf("drvPMNC87xx:motor_init() - invalid model = %s\n", brdptr->ident); + return(ERROR); + break; + } + + + total_axis = 0; + driverIndex = 0; + axisdef = cntrl->axisDef; + + if (cntrl->pmnc == PMNC8750) + { + /* Use indirect method to determine axis count - Only 8753 driver supported */ + send_mess(card_index, GET_MPV, NULL); + /* Number of return strings will tell us how many axes this controller has */ + /* Return format: A M= */ + while (recv_mess(card_index, buff, 0)) + { + sscanf(buff, "A%d M%d", &driverIndex, &motor_index); + axisdef[total_axis].driverType = PMD8753; + axisdef[total_axis].driverNum = driverIndex; + axisdef[total_axis].motorNum = motor_index; + brdptr->motor_info[total_axis].motor_motion = NULL; + Debug(3, "motor_init(): Next Axis %s\n", buff); + total_axis++; + } + } + else // PMNC8752 + { + union {int All; PMD_model ID;} driver; + int addAxis, newAxis, tmpAxis; + + /* Use direct driver type query (DRT) */ + send_mess(card_index, GET_DRT, NULL); + /* Number of return strings will tell us how many axes this controller has */ + /* Return format: A */ + while (recv_mess(card_index, buff, 0)) + { + sscanf(buff, "A%d=%d", &driverIndex, &driver.All); + if (driver.ID == PMD8753) + addAxis = 3; + else if (driver.ID == PMD8751) + addAxis = 1; + else + { + errlogPrintf("drvPMNC87xx:motor_init() - invalid driver = %d\n", driver.All); + return(ERROR); + } + + Debug(3, "motor_init(): Next Driver %s\n", buff); + + for (newAxis = 0, tmpAxis = total_axis; newAxis < addAxis; newAxis++, tmpAxis++) + { + axisdef[tmpAxis].driverType = driver.ID; + axisdef[tmpAxis].driverNum = driverIndex; + axisdef[tmpAxis].motorNum = newAxis; + brdptr->motor_info[tmpAxis].motor_motion = NULL; + } + + total_axis += addAxis; + } + + } + + brdptr->total_axis = total_axis; + cntrl->total_drivers = driverIndex; + cntrl->status = NORMAL; + Debug(2, "motor_init(): Total Drivers %d\nTotal Axis=%d\n", driverIndex, brdptr->total_axis); + + for (motor_index = 0; motor_index < total_axis; motor_index++) + { + struct mess_info *motor_info = &brdptr->motor_info[motor_index]; + + motor_info->status.All = 0; + motor_info->no_motion_count = 0; + motor_info->encoder_position = 0; + motor_info->position = 0; + + /* Encoder Enable */ + motor_info->encoder_present = YES; + motor_info->status.Bits.EA_PRESENT = 1; + // motor_info->pid_present = YES; + motor_info->status.Bits.GAIN_SUPPORT = 1; + + set_status(card_index, motor_index); /* Read status of each motor */ + } + } + else + motor_state[card_index] = (struct controller *) NULL; + } + + any_motor_in_motion = 0; + + mess_queue.head = (struct mess_node *) NULL; + mess_queue.tail = (struct mess_node *) NULL; + + free_list.head = (struct mess_node *) NULL; + free_list.tail = (struct mess_node *) NULL; + + epicsThreadCreate((char *) "PMNC87xx_motor", epicsThreadPriorityMedium, + epicsThreadGetStackSize(epicsThreadStackMedium), + (EPICSTHREADFUNC) motor_task, (void *) &targs); + + return(OK); +} + +/*---------------------------------------------------------------------*/ diff --git a/motorApp/NewFocusSrc/drvPMNCCom.h b/motorApp/NewFocusSrc/drvPMNCCom.h index 117bead8..d5247b20 100644 --- a/motorApp/NewFocusSrc/drvPMNCCom.h +++ b/motorApp/NewFocusSrc/drvPMNCCom.h @@ -4,14 +4,14 @@ USAGE... This file contains Newport Motion Master (MM) driver "include" information that is specific to Motion Master models 3000/4000. Version: 1.10 -Modified By: rivers +Modified By: sullivan Last Modified: 2004/08/17 21:28:22 */ /* * Original Author: Mark Rivers - * Current Author: Mark Rivers - * Date: 10/16/97 + * Current Author: Joe Sullivan + * Date: 06/28/06 * * Experimental Physics and Industrial Control System (EPICS) * @@ -43,23 +43,54 @@ Last Modified: 2004/08/17 21:28:22 #ifndef INCdrvPMNCComh #define INCdrvPMNCComh 1 -#include "motor.h" #include "motordrvCom.h" #include "asynDriver.h" #include "asynOctetSyncIO.h" +/* Picomotor Network Controllers */ enum PMNC_model { - PMNC8750 + PMNC8750, + PMNC8752 }; + +/* Picomotor Drivers - use DRT Command to determine */ +enum PMD_model +{ + PMD8753=1, // 3 channel open-loop + PMD8751=2 // 1 channel closed-loop +}; + + +/* Picomotor Driver 8751 Fault Codes (POWER OFF) */ +enum PMD8751_FAULTS +{ + ENCODER=2, + MOTORSHORT=1, + NOMOTOR=0, + OVERHEAT=3 +}; + + + #ifndef __cplusplus typedef enum PMNC_model PMNC_model; +typedef enum PMD_model PMD_model; #endif -#define PMNC8750_NUM_CARDS 3 /* Maximum number of controllers */ -#define PMNC8750_NUM_DRIVERS 3 /* Maximum number of drivers per controller */ -#define PMNC8750_NUM_MOTORS 3 /* Maximum number of motors per driver */ +#define PMNC87xx_NUM_CARDS 10 /* Maximum number of controllers */ +#define PMNC87xx_NUM_DRIVERS 10 /* Maximum number of drivers per controller */ +#define PMNC8753_NUM_MOTORS 3 /* Maximum number of motors per driver */ +#define PMNC8751_NUM_MOTORS 1 /* Maximum number of motors per driver */ + +/* Per axis definition */ +struct PMD_axis +{ + PMD_model driverType; + int driverNum; + int motorNum; +}; /* Motion Master specific data is stored in this structure. */ struct PMNCcontroller @@ -68,13 +99,13 @@ struct PMNCcontroller int asyn_address; /* Use for GPIB or other address with asyn */ char asyn_port[80]; /* asyn port name */ -/* String containing status of selected motors */ - char status_string[PMNC8750_NUM_DRIVERS+2][25]; -/* String containing position of motors */ - char position_string[PMNC8750_NUM_DRIVERS][25]; - /* String containing selected channel */ - char chan_select_string[PMNC8750_NUM_DRIVERS][25]; - PMNC_model model; /* New Focus Model Info */ + char aux_status_string[PMNC87xx_NUM_DRIVERS+1][25]; + char status_string[PMNC87xx_NUM_DRIVERS+1][25]; + char position_string[PMNC87xx_NUM_DRIVERS+1][25]; + char chan_select_string[PMNC87xx_NUM_DRIVERS+1][25]; + + PMNC_model pmnc; /* Controller Type */ + struct PMD_axis axisDef[MAX_AXIS]; /* Axis definition - New Focus Driver Model and Number */ long last_position[MAX_AXIS]; /* Track last incremtal position to noMotion status */ int total_drivers; /* Count number of drivers connected to controller */ CommStatus status; /* Controller communication status. */ @@ -85,6 +116,7 @@ struct PMNCcontroller typedef union { epicsUInt8 All; + /* 8753 Driver Status */ struct { #ifdef MSB_First @@ -94,12 +126,12 @@ typedef union bool atVelocity :1; /* Set if commanded velocity is reached */ bool motorSelected :1; /* Set if valid motor selected */ bool powerOn :1; /* Motor power 1 - ON; 0 - OFF. */ - bool checksumError :1; /* CheckSum Error */ + bool chksumError :1; /* CheckSum Error */ bool inMotion :1; /* In-motion indicator. */ #else bool inMotion :1; /* In-motion indicator. */ - bool checksumError :1; /* CheckSum Error */ + bool cksumError :1; /* CheckSum Error */ bool powerOn :1; /* Motor power 1 - ON; 0 - OFF. */ bool motorSelected :1; /* Set if valid motor selected */ bool atVelocity :1; /* Set if commanded velocity is reached */ @@ -107,9 +139,113 @@ typedef union bool positionMode :1; /* Set if moving in position mode */ bool bit7 :1; /* Bit #7 N/A. */ #endif - } Bits; + } Bits_8753; + /* 8751 Driver Status - SERVO ON and POWER ON */ + struct + { +#ifdef MSB_First + bool homing :1; /* Set ON if homing in progress (FIN, RIN) */ + bool forLimit :1; /* Set OFF if forward limit reached */ + bool revLimit :1; /* Set OFF if reverse limit reached */ + bool posError :1; /* Set ON if position error limit exceeded */ + bool powerOn :1; /* Motor Power Indicator */ + bool noMotor :1; /* Set ON if Missing Motor. */ + bool cksumError :1; /* CheckSum Error */ + bool moveDone :1; /* Set ON if Done. */ + +#else + bool moveDone :1; /* In-motion indicator. */ + bool chksumError :1; /* CheckSum Error */ + bool noMotor :1; /* Set ON if Missing Motor. */ + bool powerOn :1; /* Motor power indicator 1 - ON; 0 - OFF. */ + bool posError :1; /* Set ON if position error limit exceeded */ + bool revLimit :1; /* Set OFF if reverse limit reached */ + bool forLimit :1; /* Set OFF if forward limit reached */ + bool homing :1; /* Set ON if homing in progress (FIN, RIN) */ +#endif + } Bits_8751; + /* 8751 Driver Status - SERVO OFF */ + struct + { +#ifdef MSB_First + bool homing :1; /* Set ON if homing in progress (FIN, RIN) */ + bool overheat :1; /* Set OFF if motor overheated */ + bool stopIN :1; /* Set OFF if External STOP input ACTIVE */ + bool posError :1; /* Set ON if position error limit exceeded */ + bool powerOn :1; /* Set ON if valid motor selected */ + bool noMotor :1; /* Set ON if Missing Motor. */ + bool cksumError :1; /* CheckSum Error */ + bool moveDone :1; /* Set ON if Done. */ + +#else + bool moveDone :1; /* In-motion indicator. */ + bool chksumError :1; /* CheckSum Error */ + bool noMotor :1; /* Set ON if Missing Motor. */ + bool powerOn :1; /* Motor power indicator */ + bool posError :1; /* Set ON if position error limit exceeded */ + bool stopIN :1; /* Set OFF if External STOP input ACTIVE */ + bool overheat :1; /* Set OFF if motor overheated */ + bool homing :1; /* Set ON if homing in progress (FIN, RIN) */ +#endif + } Bits_8751_NOS; + /* 8751 Driver Status - SERVO ON and POWER OFF */ + struct + { +#ifdef MSB_First + bool homing :1; /* Set ON if homing in progress (FIN, RIN) */ + bool fault :2; /* Driver Power Faults - See PMD8751_FAULTS */ + bool posError :1; /* Set ON if position error limit exceeded */ + bool powerOn :1; /* Set ON if valid motor selected */ + bool noMotor :1; /* Set ON if Missing Motor. */ + bool cksumError :1; /* CheckSum Error */ + bool moveDone :1; /* Set ON if Done. */ + +#else + bool moveDone :1; /* In-motion indicator. */ + bool chksumError :1; /* CheckSum Error */ + bool noMotor :1; /* Set ON if Missing Motor. */ + bool powerOn :1; /* Motor power indicator */ + bool posError :1; /* Set ON if position error limit exceeded */ + bool fault :2; /* Driver Power Faults - See PMD8751_FAULTS */ + bool homing :1; /* Set ON if homing in progress (FIN, RIN) */ +#endif + } Bits_8751_FAULT; + } MOTOR_STATUS; +/* Driver Aux Status response for PMNC. */ +typedef union +{ + epicsUInt8 All; + /* 8751 Driver Aux Status - DIAG Command */ + struct + { +#ifdef MSB_First + bool bit7 :1; /* Bit #7 N/A. */ + bool bit6 :1; /* Bit #6 N/A. */ + bool servoOverRun :1; /* Set if servo process time overrun (>.512msec) */ + bool slewDone :1; /* Set when trapesoidal slew time over */ + bool accelDone :1; /* Set when trapesoidal accell time over */ + bool servoOn :1; /* Set if servo mode ON - else OpenLoop */ + bool posWrap :1; /* Set on 32 bit overflow (position) */ + bool diagBit :1; /* Used to encode error diagnostics */ + +#else + bool diagBit :1; /* Used to encode error diagnostics */ + bool posWrap :1; /* Set on 32 bit overflow (position) */ + bool servoOn :1; /* Set if servo mode ON - else OpenLoop */ + bool accelDone :1; /* Set when trapesoidal accell time over */ + bool slewDone :1; /* Set when trapesoidal slew time over */ + bool servoOverRun :1; /* Set if servo process time overrun (>.512msec) */ + bool bit6 :1; /* Bit #6 N/A. */ + bool bit7 :1; /* Bit #7 N/A. */ +#endif + } Bits_8751; +} MOTOR_AUX_STATUS; + + + + #endif /* INCdrvPMNCComh */