diff --git a/.gitmodules b/.gitmodules index dfdd55d1..d351db3f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -46,3 +46,6 @@ [submodule "modules/motorSmartMotor"] path = modules/motorSmartMotor url = https://github.com/epics-motor/motorSmartMotor.git +[submodule "modules/motorThorLabs"] + path = modules/motorThorLabs + url = https://github.com/epics-motor/motorThorLabs.git diff --git a/modules/Makefile b/modules/Makefile index f352381c..6a304d4d 100644 --- a/modules/Makefile +++ b/modules/Makefile @@ -21,6 +21,7 @@ SUBMODULES += motorOriel SUBMODULES += motorPiJena SUBMODULES += motorPi SUBMODULES += motorSmartMotor +SUBMODULES += motorThorLabs # Allow sites to add extra submodules -include Makefile.local diff --git a/modules/motorThorLabs b/modules/motorThorLabs new file mode 160000 index 00000000..97c022e2 --- /dev/null +++ b/modules/motorThorLabs @@ -0,0 +1 @@ +Subproject commit 97c022e2c27aefe31d5c87a2c1bf39e91979847f diff --git a/motorApp/Makefile b/motorApp/Makefile index 09ad1799..d1c5802e 100644 --- a/motorApp/Makefile +++ b/motorApp/Makefile @@ -39,9 +39,6 @@ PC6KSrc_DEPEND_DIRS = MotorSrc DIRS += NewFocusSrc NewFocusSrc_DEPEND_DIRS = MotorSrc -DIRS += ThorLabsSrc -ThorLabsSrc_DEPEND_DIRS = MotorSrc - DIRS += AerotechSrc AerotechSrc_DEPEND_DIRS = MotorSrc diff --git a/motorApp/ThorLabsSrc/Makefile b/motorApp/ThorLabsSrc/Makefile deleted file mode 100644 index 435595b1..00000000 --- a/motorApp/ThorLabsSrc/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -# Makefile -TOP = ../.. -include $(TOP)/configure/CONFIG - -# The following are used for debugging messages. -USR_CXXFLAGS += -DDEBUG - -#OPT_CXXFLAGS = -g -O0 - -DBD += devThorLabs.dbd - -LIBRARY_IOC = ThorLabs - -# Intelligent Motion Systems driver support. -SRCS += ThorLabsRegister.cc -SRCS += devMDT695.cc drvMDT695.cc - -ThorLabs_LIBS += motor asyn -ThorLabs_LIBS += $(EPICS_BASE_IOC_LIBS) - -include $(TOP)/configure/RULES - diff --git a/motorApp/ThorLabsSrc/README b/motorApp/ThorLabsSrc/README deleted file mode 100644 index 931b4a86..00000000 --- a/motorApp/ThorLabsSrc/README +++ /dev/null @@ -1,96 +0,0 @@ - - ThorLabs Piezo Control Modules -============================================================================== - -Controller Model: MDT695 (Plug in motion control card) -Driver Models: MDT694 (1 axis) - MDT603 (3 axis) - -RS232 Configuration ----------------------------------- - -Default: 115200, 8, 1, N (DB9) - - Internal DIP Switch Setting to 19200 (D1=OFF, D2=ON, D3=OFF) - -Cabling: - Requires custom cable from ThorLabs(DB9-Male to DB9-Female) - RX - Pin 2 - TX - Pin 3 - - -Controller Specifications ------------------------------------------- -No Software configuration available - -Position Units: Volts (format %.1f) - Precision: 0.1 volts - Limits: 0.0 to 150.0 - -Velocity Units: NONE - - -ASCII Commands ------------------------------------------- -Set Voltage (##.# format) (X, Y and Z) -'XV' -'YV' -'ZV' - -Read Voltage (##.# format) (X, Y and Z) -'XR?' -'YR?' -'ZR?' - -NO Status information is available (Done, Limit Switch ... etc) -Assume motion is always done (0.1 readback delay set) - - -============== Build Info ====================== - -xxxApp/src - Makefile - -------- - xxx_Common_LIBS += ThorLabs - - xxCommonInclude.dbd - ------------------- - include "devMDT695.dbd" - - -============= IOC Boot info ====================== - -iocBoot/iocLinux - serial.cmd - ---------- - - # serial 1 is a RS232 link to a Oriel Encoder Mike Controller - drvAsynSerialPortConfigure("serial1", "/dev/ttyS0", 0, 0, 0) - asynSetOption(serial1,0,baud,4800) - asynOctetSetOutputEos("serial1",0,"\r") - asynOctetSetInputEos("serial1",0,"\r") - - - . - . - - # ThorLabs MDT695 Piezo - driver setup parameters: - # (1) maximum number of controllers in system - # (2) motor task polling rate (min=1Hz, max=60Hz) - MDT695Setup(2, 60) - - # Thor driver configuration parameters: - # (1) controller being configured - # (2) asyn port name (string) - MDT695Config(0, "serial1") - MDT695Config(1, "serial3") - - - motor.substitutions - ------------------- - Set the DTYPE column to "MDT695" - - - - - diff --git a/motorApp/ThorLabsSrc/ThorLabsRegister.cc b/motorApp/ThorLabsSrc/ThorLabsRegister.cc deleted file mode 100644 index 457af508..00000000 --- a/motorApp/ThorLabsSrc/ThorLabsRegister.cc +++ /dev/null @@ -1,65 +0,0 @@ -/* -FILENAME... ThorLabslRegister.cc -USAGE... Register ThorLabs motor device driver shell commands. - -*/ - -/***************************************************************** - COPYRIGHT NOTIFICATION -***************************************************************** - -(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO - -This software was developed under a United States Government license -described on the COPYRIGHT_UniversityOfChicago file included as part -of this distribution. -**********************************************************************/ - -#include -#include "ThorLabsRegister.h" -#include "epicsExport.h" - -extern "C" -{ - -// ThorLabs Setup arguments -static const iocshArg setupArg0 = {"Max. controller count", iocshArgInt}; -static const iocshArg setupArg1 = {"Polling rate", iocshArgInt}; - -// ThorLabs Config arguments -static const iocshArg configArg0 = {"Card being configured", iocshArgInt}; -static const iocshArg configArg1 = {"asyn port name", iocshArgString}; - -static const iocshArg * const ThorLabsSetupArgs[2] = {&setupArg0, &setupArg1}; - -static const iocshArg * const ThorLabsConfigArgs[2] = {&configArg0, &configArg1}; - -static const iocshFuncDef setupMDT695 = {"MDT695Setup",2, ThorLabsSetupArgs}; - -static const iocshFuncDef configMDT695 = {"MDT695Config", 2, ThorLabsConfigArgs}; - - - -static void setupMDT695CallFunc(const iocshArgBuf *args) -{ - MDT695Setup(args[0].ival, args[1].ival); -} - -static void configMDT695CallFunc(const iocshArgBuf *args) -{ - MDT695Config(args[0].ival, args[1].sval); -} - - -static void ThorLabsRegister(void) -{ - - iocshRegister(&setupMDT695, setupMDT695CallFunc); - - iocshRegister(&configMDT695, configMDT695CallFunc); - -} - -epicsExportRegistrar(ThorLabsRegister); - -} // extern "C" diff --git a/motorApp/ThorLabsSrc/ThorLabsRegister.h b/motorApp/ThorLabsSrc/ThorLabsRegister.h deleted file mode 100644 index 07607273..00000000 --- a/motorApp/ThorLabsSrc/ThorLabsRegister.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -FILENAME... ThorLabsRegister.h -USAGE... This file contains function prototypes for ThorLabs IOC shell commands. - -Version: 1.4 -Modified By: rivers -Last Modified: 2004/07/28 18:45:16 -*/ - -/* - * Original Author: Ron Sluiter - * Date: 05/19/03 - * - * 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: - * ----------------- - */ - -#include "motor.h" -#include "motordrvCom.h" - -/* Function prototypes. */ -extern RTN_STATUS MDT695Setup(int, int); -extern RTN_STATUS MDT695Config(int, const char *); -extern RTN_STATUS MDT695UpLoad(int, const char *, const char *); - - diff --git a/motorApp/ThorLabsSrc/devMDT695.cc b/motorApp/ThorLabsSrc/devMDT695.cc deleted file mode 100644 index 86d1f7d0..00000000 --- a/motorApp/ThorLabsSrc/devMDT695.cc +++ /dev/null @@ -1,291 +0,0 @@ -/* -FILENAME... devMDT695.cc -USAGE... Motor record device level support for ThorLabs Piezo Control - Module (MDT695) - -*/ - -/* - * Original Author: Joe Sullivan - * Date: 9/27/2006 - * - * 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 09-27-06 jps initialized from devEMC18011.cc - */ - - -#include -#include -#include -#include "motorRecord.h" -#include "motor.h" -#include "motordevCom.h" -#include "drvMDT695.h" -#include "epicsExport.h" - -#define STATIC static - -extern struct driver_table MDT695_access; - -/* ----------------Create the dsets for devMDT695----------------- */ -STATIC struct driver_table *drvtabptr; -STATIC long MDT695_init(int); -STATIC long MDT695_init_record(void *); -STATIC long MDT695_start_trans(struct motorRecord *); -STATIC RTN_STATUS MDT695_build_trans(motor_cmnd, double *, struct motorRecord *); -STATIC RTN_STATUS MDT695_end_trans(struct motorRecord *); - -struct motor_dset devMDT695 = -{ - {8, NULL, (DEVSUPFUN) MDT695_init, (DEVSUPFUN) MDT695_init_record, NULL}, - motor_update_values, - MDT695_start_trans, - MDT695_build_trans, - MDT695_end_trans -}; - -extern "C" {epicsExportAddress(dset,devMDT695);} - -/* --------------------------- program data --------------------- */ - -/* This table is used to define the command types */ -/* WARNING! this must match "motor_cmnd" in motor.h */ - -static msg_types MDT695_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 **MDT695_cards; - -/* --------------------------- program data --------------------- */ - - -/* initialize device support for MDT695 stepper motor */ -STATIC long MDT695_init(int after) -{ - long rtnval; - - if (!after) - { - drvtabptr = &MDT695_access; - (drvtabptr->init)(); - } - - rtnval = motor_init_com(after, *drvtabptr->cardcnt_ptr, drvtabptr, &MDT695_cards); - return(rtnval); -} - - -/* initialize a record instance */ -STATIC long MDT695_init_record(void *arg) -{ - struct motorRecord *mr = (struct motorRecord *) arg; - /* Disable change of direction testing in record support */ - /* This device does it's own backlash correction */ - mr->ntm = menuYesNoNO; - return(motor_init_record_com(mr, *drvtabptr->cardcnt_ptr, drvtabptr, MDT695_cards)); -} - - -/* start building a transaction */ -STATIC long MDT695_start_trans(struct motorRecord *mr) -{ - return(motor_start_trans_com(mr, MDT695_cards)); -} - - -/* end building a transaction */ -STATIC RTN_STATUS MDT695_end_trans(struct motorRecord *mr) -{ - return(motor_end_trans_com(mr, drvtabptr)); -} - - -/* add a part to the transaction */ -STATIC RTN_STATUS MDT695_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 controller *brdptr; - // struct mess_info *motor_info; - struct MDT695Controller *cntrl; - char buff[110]; - int signal, card, intval; - double dval, cntrl_units; - unsigned int size; - bool sendMsg; - RTN_STATUS rtnval; - - rtnval = OK; - buff[0] = '\0'; - sendMsg = true; - - /* Protect against NULL pointer with WRTITE_MSG(GO/STOP_AXIS/GET_INFO, NULL). */ - intval = (parms == NULL) ? 0 : NINT(parms[0]); - dval = (parms == NULL) ? 0 : *parms; - - motor_call = &(trans->motor_call); - card = motor_call->card; - signal = motor_call->signal; - - brdptr = (*trans->tabptr->card_array)[card]; - if (brdptr == NULL) - return(rtnval = ERROR); - - cntrl = (struct MDT695Controller *) brdptr->DevicePrivate; - /* 6K Controllers expect Velocity and Acceleration settings in Revs/sec/sec */ - cntrl_units = dval * cntrl->drive_resolution; - - - if (MDT695_table[command] > motor_call->type) - motor_call->type = MDT695_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); - strcat(motor_call->message, MDT695_OUT_EOS); - } - - switch (command) - { - 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); - strcat(motor_call->message, MDT695_OUT_EOS); - - } - if (strlen(mr->post) != 0) - motor_call->postmsgptr = (char *) &mr->post; - break; - - default: - break; - } - - /* ThorLabs Piezo driver - voltage set command only */ - switch (command) - { - case MOVE_REL: - // No relative move available - break; - case MOVE_ABS: - sprintf(buff, "#V%.*f", 1, cntrl_units); - break; - - case HOME_FOR: - case HOME_REV: - break; - - case LOAD_POS: - break; - - case SET_VEL_BASE: - break; /* MDT695 does not use base velocity */ - - case SET_VELOCITY: - break; - - case SET_ACCEL: - break; - - case GO: - break; - - case SET_ENC_RATIO: - rtnval = ERROR; - break; - - 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: - break; - - case JOG: - break; - - case SET_PGAIN: - case SET_IGAIN: - case SET_DGAIN: - rtnval = ERROR; - break; - - case ENABLE_TORQUE: - case DISABL_TORQUE: - rtnval = ERROR; - break; - - case SET_HIGH_LIMIT: - case SET_LOW_LIMIT: - rtnval = ERROR; - break; - - default: - rtnval = ERROR; - } - - size = strlen(buff); - if (size > sizeof(buff) || (strlen(motor_call->message) + size) > MAX_MSG_SIZE) - errlogMessage("MDT695_build_trans(): buffer overflow.\n"); - else - { - strcat(motor_call->message, buff); - } - - return(rtnval); -} diff --git a/motorApp/ThorLabsSrc/devThorLabs.dbd b/motorApp/ThorLabsSrc/devThorLabs.dbd deleted file mode 100644 index fb4a37ce..00000000 --- a/motorApp/ThorLabsSrc/devThorLabs.dbd +++ /dev/null @@ -1,6 +0,0 @@ -# ThorLabs Piezo Device Driver support. -device(motor,VME_IO,devMDT695,"MDT695") -driver(drvMDT695) -registrar(ThorLabsRegister) -variable(drvMDT695debug) - diff --git a/motorApp/ThorLabsSrc/drvMDT695.cc b/motorApp/ThorLabsSrc/drvMDT695.cc deleted file mode 100644 index ab2c8013..00000000 --- a/motorApp/ThorLabsSrc/drvMDT695.cc +++ /dev/null @@ -1,655 +0,0 @@ -/* -FILENAME... drvMDT695.cc -USAGE... Motor record driver level support for ThorLabs - Piezo Control Module (Model: MDT695) - Compatable with MDT694, MDT693 - - -*/ - -/* - * Original Author: Joe Sullivan - * Date: 9/27/2006 - * - * 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 09-27-06 jps initialized from drvEMC18011.cc - */ - - -#include -#include /* isascii functions */ -#include -#include -#include -#include -#include -#include -#include "motor.h" -#include "ThorLabsRegister.h" -#include "drvMDT695.h" -#include "asynOctetSyncIO.h" -#include "epicsExport.h" - -#define CMD_ID "I" -#define CMD_DEV "D" -#define RESP_DEV "d" /* Response if ECHO is ON */ -#define CMD_ECHO "E" -#define CMD_POS "#R?" - -#define MDT695_NUM_CARDS 16 -#define BUFF_SIZE 120 /* Maximum length of string to/from MDT695 */ - -#define TIMEOUT 2.0 /* Command timeout in sec. */ - -/* Delay after START_MOTION before a status update is possible */ -#define MOTION_DELAY 0.1 - -/*----------------debugging-----------------*/ -volatile int drvMDT695debug = 0; -extern "C" {epicsExportAddress(int, drvMDT695debug);} -static inline void Debug(int level, const char *format, ...) { - #ifdef DEBUG - if (level < drvMDT695debug) { - va_list pVar; - va_start(pVar, format); - vprintf(format, pVar); - va_end(pVar); - } - #endif -} - -/* --- Local data. --- */ -int MDT695_num_cards = 0; -static char *MDT694_axis[] = {"X", "Y", "Z"}; - -/* Local data required for every driver; see "motordrvComCode.h" */ -#include "motordrvComCode.h" - -/* This is a temporary fix to introduce a delayed reading of the motor - * position after a move completes - */ -volatile double drvMDT695ReadbackDelay = 0.; - - -/*----------------functions-----------------*/ -static int recv_mess(int card, char *com, int flag); -static RTN_STATUS send_mess(int card, char const *, char *name); -static int set_status(int card, int signal); -static long report(int level); -static long init(); -static int motor_init(); -static void query_done(int, int, struct mess_node *); - -/*----------------functions-----------------*/ - -struct driver_table MDT695_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, - MDT694_axis -}; - -struct drvMDT695_drvet -{ - long number; - long (*report) (int); - long (*init) (void); -} drvMDT695 = {2, report, init}; - -extern "C" {epicsExportAddress(drvet, drvMDT695);} - -static struct thread_args targs = {SCAN_RATE, &MDT695_access, MOTION_DELAY}; - -/********************************************************* - * Print out driver status report - *********************************************************/ -static long report(int level) -{ - int card; - - if (MDT695_num_cards <=0) - printf(" No MDT695 controllers configured.\n"); - else - { - for (card = 0; card < MDT695_num_cards; card++) - { - struct controller *brdptr = motor_state[card]; - - if (brdptr == NULL) - printf(" MDT695 controller %d connection failed.\n", card); - else - { - struct MDT695Controller *cntrl; - - cntrl = (struct MDT695Controller *) brdptr->DevicePrivate; - printf(" MDT695 controller %d, port=%s, address=%d, id: %s \n", - card, cntrl->asyn_port, cntrl->asyn_address, - brdptr->ident); - } - } - } - 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 (MDT695_num_cards <= 0) - { - Debug(1, "init(): MDT695 driver disabled. MDT695Setup() 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() - ************************************************************/ - -static int set_status(int card, int signal) -{ - struct MDT695Controller *cntrl; - struct mess_node *nodeptr; - register struct mess_info *motor_info; - char send_buff[80]; - char *startptr, *endptr; - int rtn_state; - int recvCnt; - int motorData; - int motor; - bool recvRetry; - bool ls_active = false; - msta_field status; - - cntrl = (struct MDT695Controller *) motor_state[card]->DevicePrivate; - motor_info = &(motor_state[card]->motor_info[signal]); - status.All = motor_info->status.All; - motor = signal+1; - - - recvRetry = true; - - startptr = cntrl->recv_string; - send_mess(card, CMD_POS, MDT694_axis[signal]); - if ((recvCnt = recv_mess(card, startptr, 0)) > 0) - { - double datad; - - /* Convert position and check for error */ - Debug(5, "set_status(): RecvStr = %s\n", &startptr[2]); - datad = strtod(&startptr[2], &endptr); - if (&startptr[2] != endptr) - { - Debug(5, "set_status(): motorData = %.2f\n", datad); - motorData = NINT(datad / cntrl->drive_resolution); - recvRetry = false; - } - } - - /* Check for normal look termination - all queries successful */ - if (recvRetry == false) - cntrl->status = NORMAL; - else - { - /* Try turning Echo OFF before next retry */ - recvCnt = recv_mess(card, startptr, 0); /* Flush recv buffer */ - send_mess(card, CMD_ECHO, NULL); - recvCnt = recv_mess(card, startptr, 0); - - if (cntrl->status == NORMAL) - { - epicsThreadSleep(MOTION_DELAY); - cntrl->status = RETRY; - } - else - cntrl->status = COMM_ERR; - } - - if (cntrl->status != NORMAL) - { - if (cntrl->status == COMM_ERR) - { - status.Bits.CNTRL_COMM_ERR = 1; - status.Bits.RA_PROBLEM = 1; - rtn_state = 1; - goto exit; - } - else - { - rtn_state = 0; - goto exit; - } - } - else - status.Bits.CNTRL_COMM_ERR = 0; - - nodeptr = motor_info->motor_motion; - - /* - * There is no status information available - assume motion complete - */ - - Debug(5, "set_status(): status = %s\n", "Done"); - status.Bits.RA_DONE = 1; - status.Bits.RA_DIRECTION = 1; - - status.Bits.RA_HOME = 0; - - /* Set Travel limit switch status bits. */ - status.Bits.RA_PLUS_LS = 0; - status.Bits.RA_MINUS_LS = 0; - - ls_active = (status.Bits.RA_PLUS_LS || status.Bits.RA_MINUS_LS) ? true : false; - - - /* encoder status */ - status.Bits.EA_POSITION = 0; - status.Bits.EA_SLIP = 0; - status.Bits.EA_SLIP_STALL = 0; - status.Bits.EA_HOME = 0; - - if (motorData == motor_info->position) - { - if (nodeptr != 0) /* Increment counter only if motor is moving. */ - motor_info->no_motion_count++; - } - else - { - motor_info->position = motorData; - motor_info->encoder_position = 0; - motor_info->no_motion_count = 0; - } - - status.Bits.RA_PROBLEM = 0; - - /* Parse motor velocity? */ - /* NEEDS WORK */ - motor_info->velocity = 0; - - rtn_state = (!motor_info->no_motion_count || ls_active == true || - status.Bits.RA_DONE | status.Bits.RA_PROBLEM) ? 1 : 0; - - /* Test for post-move string. */ - if ((status.Bits.RA_DONE || ls_active == true) && nodeptr != 0 && - nodeptr->postmsgptr != 0) - { - strncpy(send_buff, nodeptr->postmsgptr, 80); - send_mess(card, send_buff, (char*) NULL); - nodeptr->postmsgptr = NULL; - } - -exit: - motor_info->status.All = status.All; - return(rtn_state); -} - - -/*****************************************************/ -/* send a message to the MDT695 board */ -/* send_mess() */ -/*****************************************************/ -static RTN_STATUS send_mess(int card, char const *com, char *name) -{ - struct MDT695Controller *cntrl; - char local_buff[MAX_MSG_SIZE]; - char *pname; - int comsize, namesize; - size_t nwrite; - - comsize = (com == NULL) ? 0 : strlen(com); - namesize = (name == NULL) ? 0 : strlen(name); - - if ((comsize + namesize) > MAX_MSG_SIZE) - { - errlogMessage("drvMDT695.c:send_mess(); message size violation.\n"); - return(ERROR); - } - else if (comsize == 0) /* Normal exit on empty input message. */ - return(OK); - - if (!motor_state[card]) - { - errlogPrintf("drvMDT695.c:send_mess() - invalid card #%d\n", card); - return(ERROR); - } - - local_buff[0] = (char) NULL; /* Terminate local buffer. */ - - if (name == NULL) - strcat(local_buff, com); /* Make a local copy of the string. */ - else - { - strcpy(local_buff, com); - // Look for name substitution - if ((pname = strchr(local_buff, '#'))) - *pname = *name; - } - - Debug(2, "send_mess(): message = %s\n", local_buff); - - cntrl = (struct MDT695Controller *) motor_state[card]->DevicePrivate; - - /* flush any junk at input port - should not be any data available */ - pasynOctetSyncIO->flush(cntrl->pasynUser); - - pasynOctetSyncIO->write(cntrl->pasynUser, local_buff, strlen(com), - 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 = this flag is ignored - the receive buffer is flushed - * on every write (see write_mess()) - * LOGIC... - * IF controller card does not exist. - * ERROR RETURN. - * ENDIF - * NORMAL RETURN. - */ - -static int recv_mess(int card, char *com, int flag) -{ - struct MDT695Controller *cntrl; - double timeout = 0.; - size_t nread = 0; - asynStatus status; - int eomReason; - int rtnVal; - - /* Check that card exists */ - if (!motor_state[card]) - return(ERROR); - - cntrl = (struct MDT695Controller *) motor_state[card]->DevicePrivate; - - timeout = TIMEOUT; - - status = pasynOctetSyncIO->read(cntrl->pasynUser, com, BUFF_SIZE, - timeout, &nread, &eomReason); - - if (nread > 0) - Debug(2, "recv_mess(): message = '%s'\n", com); - - if (status != asynSuccess) - { - com[0] = '\0'; - rtnVal = -1; - Debug(1, "recv_mess(): TIMEOUT \n"); - } - else - rtnVal = (int)nread; - - return(rtnVal); -} - - -/*****************************************************/ -/* Setup system configuration */ -/* MDT695Setup() */ -/*****************************************************/ -RTN_STATUS -MDT695Setup(int num_cards, /* maximum number of controllers in system. */ - int scan_rate) /* polling rate - 1/60 sec units. */ -{ - int itera; - - if (num_cards < 1 || num_cards > MDT695_NUM_CARDS) - MDT695_num_cards = MDT695_NUM_CARDS; - else - MDT695_num_cards = num_cards; - - /* 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 MDT695Config 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(MDT695_num_cards * - sizeof(struct controller *)); - - for (itera = 0; itera < MDT695_num_cards; itera++) - motor_state[itera] = (struct controller *) NULL; - - return(OK); -} - - -/*****************************************************/ -/* Configure a controller */ -/* MDT695Config() */ -/*****************************************************/ -RTN_STATUS -MDT695Config(int card, /* card being configured */ - const char *name) /* asyn port name */ -{ - struct MDT695Controller *cntrl; - - if (card < 0 || card >= MDT695_num_cards) - return(ERROR); - - motor_state[card] = (struct controller *) malloc(sizeof(struct controller)); - motor_state[card]->DevicePrivate = malloc(sizeof(struct MDT695Controller)); - cntrl = (struct MDT695Controller *) motor_state[card]->DevicePrivate; - - strcpy(cntrl->asyn_port, name); - 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 MDT695Controller *cntrl; - int card_index, motor_index; - char buff[BUFF_SIZE]; - int total_axis = 0; - int recvCnt, retryCnt; - bool cardFound = false; - asynStatus success_rtn; - - initialized = true; /* Indicate that driver is initialized. */ - - /* Check for setup */ - if (MDT695_num_cards <= 0) - return(ERROR); - - - for (card_index = 0; card_index < MDT695_num_cards; card_index++) - { - if (!motor_state[card_index]) - continue; - - brdptr = motor_state[card_index]; - brdptr->cmnd_response = false; - total_cards = card_index + 1; - cntrl = (struct MDT695Controller *) brdptr->DevicePrivate; - - /* Initialize communications channel */ - success_rtn = pasynOctetSyncIO->connect(cntrl->asyn_port, - cntrl->asyn_address, &cntrl->pasynUser, NULL); - - if (success_rtn == asynSuccess) - { - - /* Set command End-of-string */ - pasynOctetSyncIO->setInputEos(cntrl->pasynUser, - MDT695_IN_EOS,strlen(MDT695_IN_EOS)); - pasynOctetSyncIO->setOutputEos(cntrl->pasynUser, - MDT695_OUT_EOS,strlen(MDT695_OUT_EOS)); - - /* Send a message to the board, see if it exists */ - retryCnt = 0; - - do - { - /* Read device type */ - send_mess(card_index, CMD_DEV, NULL); - recvCnt = recv_mess(card_index, buff, 0); - /* Check for valid response -- if not retry */ - if ((recvCnt > 0) && strstr(buff, "MDT")) - cardFound = true; - else - { - /* Try turning Echo OFF */ - recvCnt = recv_mess(card_index, buff, 0); /* Flush recv buffer */ - send_mess(card_index, CMD_ECHO, NULL); - recvCnt = recv_mess(card_index, buff, 0); - } - } while(!cardFound && ++retryCnt < 3); - } - - if (cardFound) - { - - /* Check for 1 or 3 axis models */ - if (strstr(buff, "694")) - total_axis = 1; - else - total_axis = 3; - - /* Get controller ID info -- multi-line response */ - *brdptr->ident = (char)NULL; - send_mess(card_index, CMD_ID, NULL); - do - { - recvCnt = recv_mess(card_index, buff, 0); - if (recvCnt > 0) - { - if (strstr(buff, "Model")) - strcpy(brdptr->ident, buff); - else if (strstr(buff, "Version")) - { - strcat(brdptr->ident, ", "); - strcat(brdptr->ident, buff); - } - } - } while(recvCnt >= 0); - - - brdptr->localaddr = (char *) NULL; - brdptr->motor_in_motion = 0; - - brdptr->total_axis = total_axis; - cntrl->drive_resolution = MDT695_RESOLUTION; - - 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; - motor_info->motor_motion = NULL; - - /* NO Encoder support - internal closed loop controller */ - motor_info->encoder_present = NO; - motor_info->status.Bits.EA_PRESENT = 0; - motor_info->pid_present = NO; - motor_info->status.Bits.GAIN_SUPPORT = 0; - - 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 *) "MDT695_motor", 64, 5000, (EPICSTHREADFUNC) motor_task, (void *) &targs); - epicsThreadCreate((char *) "MDT695_motor", - epicsThreadPriorityMedium, - epicsThreadGetStackSize(epicsThreadStackMedium), - (EPICSTHREADFUNC) motor_task, (void *) &targs); - - - return(OK); -} - diff --git a/motorApp/ThorLabsSrc/drvMDT695.h b/motorApp/ThorLabsSrc/drvMDT695.h deleted file mode 100644 index fc520298..00000000 --- a/motorApp/ThorLabsSrc/drvMDT695.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -FILENAME... drvMDT695.h -USAGE... This file contains ThorLabs Piezo Control Module (MDT695) - motorRecord driver information . - -*/ - -/* - * Original Author: Mark Rivers - * Current Author: J. Sullivan - * Date: 10/16/97 - * - * 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 09-27-06 jps initialized from drvEMC18011.h - */ - -#ifndef INCdrvMDT695h -#define INCdrvMDT695h 1 - -#include "motor.h" -#include "motordrvCom.h" -#include "asynDriver.h" -#include "asynOctetSyncIO.h" - -#define MDT695_MAX_MOTORS 3 -#define MDT695_MSG_SIZE 120 -#define MDT695_STATUS_RETRY 10 - -/* End-of-string defines */ -#define MDT695_OUT_EOS "\r" /* Command */ -#define MDT695_IN_EOS "\r" /* Reply */ - - -/* Positition resolution is fixed at 0.1 volts */ -#define MDT695_RESOLUTION 0.1 - -# -/* Motion Master specific data is stored in this structure. */ -struct MDT695Controller -{ - asynUser *pasynUser; /* For RS-232 */ - int asyn_address; /* Use for GPIB or other address with asyn */ - char asyn_port[80]; /* asyn port name */ - char recv_string[MDT695_MSG_SIZE]; /* Position Query result strings */ - double drive_resolution; /* This controller has a fixed drive resolution */ - CommStatus status; /* Controller communication status. */ -}; - - -#endif /* INCdrvMDT695h */ -