Initial version of the Newfocus drivers

This commit is contained in:
jsullivan-anl
2006-04-14 20:32:54 +00:00
parent 624f38c298
commit ab256a0ff2
8 changed files with 1584 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
# Makefile
TOP = ../..
include $(TOP)/configure/CONFIG
# Both the following line, and a line in the *.dbd file,
# must be uncommented to use diagnostic debugging messages.
USR_CXXFLAGS += -DDEBUG
OPT_CXXFLAGS =
DBD += devNewFocus.dbd
LIBRARY_IOC = NewFocus
SRCS += NewFocusRegister.cc
# PMNC8750 (i.e., PMNC8750) device driver.
SRCS += devPMNC8750.cc drvPMNC8750.cc
NewFocus_LIBS += motor asyn
NewFocus_LIBS += $(EPICS_BASE_IOC_LIBS)
include $(TOP)/configure/RULES
+68
View File
@@ -0,0 +1,68 @@
/*
FILENAME... NewFocusRegister.cc
USAGE... Register NewFocus motor device driver shell commands.
Version: 1.6
Modified By: rivers
Last Modified: 2004/07/28 20:24:01
*/
/*****************************************************************
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 <iocsh.h>
#include "NewFocusRegister.h"
#include "epicsExport.h"
extern "C"
{
// NewFocus Setup arguments
static const iocshArg setupArg0 = {"Max. controller count", iocshArgInt};
static const iocshArg setupArg1 = {"Max. drivers per controller count", iocshArgInt};
static const iocshArg setupArg2 = {"Polling rate", iocshArgInt};
// NewFocus Config arguments
static const iocshArg configArg0 = {"Card being configured", iocshArgInt};
static const iocshArg configArg1 = {"asyn port name", iocshArgString};
static const iocshArg configArg2 = {"asyn address (GPIB)", iocshArgInt};
static const iocshArg * const NewFocusSetupArgs[3] = {&setupArg0,
&setupArg1,
&setupArg2};
static const iocshArg * const NewFocusConfigArgs[3] = {&configArg0,
&configArg1,
&configArg2};
static const iocshFuncDef setupPMNC8750 = {"PMNC8750Setup", 3, NewFocusSetupArgs};
static const iocshFuncDef configPMNC8750 = {"PMNC8750Config", 3, NewFocusConfigArgs};
static void setupPMNC8750CallFunc(const iocshArgBuf *args)
{
PMNC8750Setup(args[0].ival, args[1].ival, args[2].ival);
}
static void configPMNC8750CallFunc(const iocshArgBuf *args)
{
PMNC8750Config(args[0].ival, args[1].sval, args[2].ival);
}
static void NewFocusRegister(void)
{
iocshRegister(&setupPMNC8750, setupPMNC8750CallFunc);
iocshRegister(&configPMNC8750, configPMNC8750CallFunc);
}
epicsExportRegistrar(NewFocusRegister);
} // extern "C"
+45
View File
@@ -0,0 +1,45 @@
/*
FILENAME... NewportRegister.h
USAGE... This file contains function prototypes for Newport 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 PMNC8750Setup(int, int, int);
extern RTN_STATUS PMNC8750Config(int, const char *, int);
+42
View File
@@ -0,0 +1,42 @@
NewFocus PicoMotor Controler (8750)
===================================
**** EXAMPLE CONFIGURATION FOR VXWORKS TARGETS ****
xxxApp/src/Makefile
-------------------
xxx_vxWorks_LIBS += NewFocus
xxxApp/src/xxxCommonInclude.dbd
--------------------------------
include "devNewFocus.dbd"
iocBoot/iocxxx/serial.cmd
---------------------------
tyGSAsynInit("serial1", "UART_0", 1, 19200,'N',1,8,'N',"\n","\r") /* NewFocus Pico Motor */
.
.
.
# New Focus Picomotor Network Controller (model 8750) (setup parameters:
# (1) maximum number of controllers in system
# (2) maximum number of drivers per controller (1 - 3)
# (3) motor task polling rate (min=1Hz,max=60Hz)
#drvPMNC8750debug=0
PMNC8750Setup(1, 2, 10)
# New Focuc Picomotor Network Controller (model 8750) configuration parameters:
# (1) controller# being configured,
# (2) asyn port name (string)
PMNC8750Config(0, "serial2")
iocBoot/iocxxx/motor.substitutions
----------------------------------
{xxx:, 1, m$(N), "PMNC8750", 0, 0, "motor $(N)", degrees, Pos, 10, 0., 1., 0, 1, .2, 1e-3, 3, 100, -100, ""}
{xxx:, 2 m$(N), "PMNC8750", 0, 1, "motor $(N)", degrees, Pos, 60, 0., 1.5, 0, 1, .2, 1e-3, 3, 100, -100, ""}
{xxx:, 3, m$(N), "PMNC8750", 0, 2, "motor $(N)", degrees, Pos, 60, 0., 1., 0, 1, .2, 1e-3, 3, 100, -100, ""}
+6
View File
@@ -0,0 +1,6 @@
# NewFocus PicoMotor Network Controller (PMNC) Device Driver support.
device(motor,VME_IO,devPMNC8750,"PMNC8750")
driver(drvPMNC8750)
registrar(NewFocusRegister)
variable(drvPMNC8750debug)
+333
View File
@@ -0,0 +1,333 @@
/*
FILENAME... devPMNC8750.cc
USAGE... Motor record device level support for NewFocus PMNC8750.
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 01-10-06 jps initialized from drvMM3000
*/
#include <string.h>
#include "motorRecord.h"
#include "motor.h"
#include "motordevCom.h"
#include "drvPMNCCom.h"
#include "epicsExport.h"
#define STATIC static
extern struct driver_table PMNC8750_access;
/* ----------------Create the dsets for devPMNC8750----------------- */
/* static long report(); */
STATIC struct driver_table *drvtabptr;
STATIC long PMNC8750_init(void *);
STATIC long PMNC8750_init_record(void *);
STATIC long PMNC8750_start_trans(struct motorRecord *);
STATIC RTN_STATUS PMNC8750_build_trans(motor_cmnd, double *, struct motorRecord *);
STATIC RTN_STATUS PMNC8750_end_trans(struct motorRecord *);
struct motor_dset devPMNC8750 =
{
{8, NULL, (DEVSUPFUN) PMNC8750_init, (DEVSUPFUN) PMNC8750_init_record, NULL},
motor_update_values,
PMNC8750_start_trans,
PMNC8750_build_trans,
PMNC8750_end_trans
};
extern "C" {epicsExportAddress(dset,devPMNC8750);}
/* --------------------------- program data --------------------- */
/* This table is used to define the command types */
/* WARNING! this must match "motor_cmnd" in motor.h */
static msg_types PMNC8750_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 **PMNC8750_cards;
/* --------------------------- program data --------------------- */
/* initialize device support for PMNC8750 stepper motor */
STATIC long PMNC8750_init(void *arg)
{
long rtnval;
int after = (int) arg;
if (after == 0)
{
drvtabptr = &PMNC8750_access;
(drvtabptr->init)();
}
rtnval = motor_init_com(after, *drvtabptr->cardcnt_ptr, drvtabptr, &PMNC8750_cards);
return(rtnval);
}
/* initialize a record instance */
STATIC long PMNC8750_init_record(void *arg)
{
struct motorRecord *mr = (struct motorRecord *) arg;
return(motor_init_record_com(mr, *drvtabptr->cardcnt_ptr, drvtabptr, PMNC8750_cards));
}
/* start building a transaction */
STATIC long PMNC8750_start_trans(struct motorRecord *mr)
{
return(motor_start_trans_com(mr, PMNC8750_cards));
}
/* end building a transaction */
STATIC RTN_STATUS PMNC8750_end_trans(struct motorRecord *mr)
{
return(motor_end_trans_com(mr, drvtabptr));
}
/* add a part to the transaction */
STATIC RTN_STATUS PMNC8750_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;
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, PMNC8750_cards);
motor_call = &(trans->motor_call);
card = motor_call->card;
axis = motor_call->signal;
motor_call->type = PMNC8750_table[command];
drive = (axis / PMNC8750_NUM_MOTORS) + 1; /* First drive = A1 */
motor = axis % PMNC8750_NUM_MOTORS;
brdptr = (*trans->tabptr->card_array)[card];
if (brdptr == NULL)
return(rtnval = ERROR);
cntrl = (struct PMNCcontroller *) brdptr->DevicePrivate;
if (PMNC8750_table[command] > motor_call->type)
motor_call->type = PMNC8750_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, PMNC8750_cards);
motor_call->type = PMNC8750_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:
sprintf(buff, "REL A%d=%d", drive, intval-motor_info->position);
break;
case MOVE_REL:
sprintf(buff, "REL A%d=%d", drive, intval);
break;
case HOME_FOR:
case HOME_REV:
sendMsg = false;
break;
case LOAD_POS:
/* Setting driver position because the controller cannot be set */
motor_info->position = intval;
sprintf(buff, "CHL A%d=%d", drive, motor);
break;
case SET_VEL_BASE:
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, PMNC8750_cards);
motor_call->type = PMNC8750_table[command];
sprintf(buff, "MPV A%d %d=%d", drive, motor, abs(intval));
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:
sprintf(buff, "GO A%d", drive);
break;
case SET_ENC_RATIO:
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 (intval >= 0)
sprintf(buff, "FOR A%d=%d", drive, intval);
else
sprintf(buff, "REV A%d=%d", drive, abs(intval));
strcpy(motor_call->message, buff);
rtnval = motor_end_trans_com(mr, drvtabptr);
rtnval = (RTN_STATUS) motor_start_trans_com(mr, PMNC8750_cards);
motor_call->type = PMNC8750_table[command];
sprintf(buff, "GO A%d",drive);
break;
case SET_PGAIN:
case SET_IGAIN:
case SET_DGAIN:
sendMsg = false;
break;
case ENABLE_TORQUE:
sprintf(buff, "MON A%d", drive);
break;
case DISABL_TORQUE:
sprintf(buff, "HOF A%d", drive);
break;
case SET_HIGH_LIMIT:
case SET_LOW_LIMIT:
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("PMNC8750_build_trans(): buffer overflow.\n");
else
{
strcat(motor_call->message, buff);
motor_end_trans_com(mr, drvtabptr);
}
}
return(rtnval);
}
+951
View File
@@ -0,0 +1,951 @@
/*
FILENAME... drvPMNC8750.cc
USAGE... Motor record driver level support for NewFocus PMNC8750.
Version: 1.17
Modified By: sluiter
Last Modified: 2005/03/30 19:10:48
*/
/*
* Original Author: Mark Rivers
* Date: 10/20/97
* Current Author: Ron Sluiter
*
* 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 PMNC8750 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 <driver>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 <string.h>
#include <epicsThread.h>
#include <drvSup.h>
#include "motor.h"
#include "NewFocusRegister.h"
#include "drvPMNCCom.h"
#include "asynOctetSyncIO.h"
#include "epicsExport.h"
#define STATIC static
#define READ_RESOLUTION "VER"
#define READ_STATUS "STA"
#define READ_POSITION "POS"
#define READ_ONE_POSITION "POS A1"
#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_CHAN_SELECT "CHL"
#define GET_MPV "MPV" /* Query Minimum Profile Velocity */
#define NOREPLY_EOS ">"
#define REPLY_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 PMNC8750 */
/* The PMNC8750 does not respond for 2 to 5 seconds after hitting a travel limit. */
#define SERIAL_TIMEOUT 5.0 /* Command timeout in sec. */
/*----------------debugging-----------------*/
#ifdef __GNUG__
#ifdef DEBUG
#define Debug(l, f, args...) { if(l<=drvPMNC8750debug) printf(f,## args); }
#else
#define Debug(l, f, args...)
#endif
#else
#define Debug()
#endif
volatile int drvPMNC8750debug = 0;
extern "C" {epicsExportAddress(int, drvPMNC8750debug);}
/* --- Local data. --- */
int PMNC8750_num_cards = 0;
int PMNC8750_num_drivers = 0; /* Number of Drivers per Controller */
/* 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 RTN_STATUS send_noreply_mess(int, char const *, char *);
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 PMNC8750_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,
start_status,
&initialized,
NULL
};
struct
{
long number;
long (*report) (int);
long (*init) (void);
} drvPMNC8750 = {2, report, init};
extern "C" {epicsExportAddress(drvet, drvPMNC8750);}
STATIC struct thread_args targs = {SCAN_RATE, &PMNC8750_access};
/*********************************************************
* Print out driver status report
*********************************************************/
static long report(int level)
{
int card;
if (PMNC8750_num_cards <=0)
printf(" No PMNC8750 controllers configured.\n");
else
{
for (card = 0; card < PMNC8750_num_cards; card++)
{
struct controller *brdptr = motor_state[card];
if (brdptr == NULL)
printf(" PMNC8750 controller %d connection failed.\n", card);
else
{
struct PMNCcontroller *cntrl;
cntrl = (struct PMNCcontroller *) brdptr->DevicePrivate;
printf(" PMNC8750 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 (PMNC8750_num_cards <= 0)
{
Debug(1, "init(): PMNC8750 driver disabled. PMNC8750Setup() 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)
{
struct PMNCcontroller *cntrl;
int itera, drive;
int recv_flag;
int total_drives;
char buff[BUFF_SIZE];
if (card >= 0)
{
cntrl = (struct PMNCcontroller *) motor_state[card]->DevicePrivate;
total_drives = cntrl->total_drivers;
Debug(3, "start_status(): Total Drives=%d\n", total_drives);
send_mess(card, READ_STATUS, NULL);
for (drive=0, recv_flag=1; drive < (total_drives+2) && recv_flag; drive++)
{
recv_flag = recv_mess(card, cntrl->status_string[drive], 0);
Debug(2, "start_status(): Status_string=%s\n", cntrl->status_string[drive]);
}
recv_mess(card, buff, 1); /* Get Prompt */
if (recv_flag)
{
cntrl->status = NORMAL;
send_mess(card, GET_CHAN_SELECT, NULL);
for (drive=0, recv_flag=1; drive < total_drives && recv_flag; drive++)
{
recv_flag = recv_mess(card, cntrl->chan_select_string[drive], 0);
Debug(2, "start_status(): ChanSelect_string=%s\n", cntrl->chan_select_string[drive]);
}
recv_mess(card, buff, 1); /* Get Prompt */
send_mess(card, READ_POSITION, NULL);
for (drive=0, recv_flag=1; drive < total_drives && recv_flag; drive++)
{
recv_flag = recv_mess(card, cntrl->position_string[drive], 0);
Debug(2, "start_status(): Position_string=%s\n", cntrl->position_string[drive]);
}
recv_mess(card, buff, 1); /* Get Prompt */
}
else
{
if (cntrl->status == NORMAL)
cntrl->status = RETRY;
else
cntrl->status = COMM_ERR;
}
}
else
{
/*
* For efficiency we send messages to all cards, then read all
* responses. This minimizes the latency due to processing on each card
*/
for (itera = 0; (itera < total_cards) && motor_state[itera]; itera++)
send_mess(itera, READ_STATUS, NULL);
for (itera = 0; (itera < total_cards) && motor_state[itera]; itera++)
{
cntrl = (struct PMNCcontroller *) motor_state[itera]->DevicePrivate;
total_drives = cntrl->total_drivers;
for (drive=0, recv_flag=1; drive < (total_drives+2) && recv_flag; drive++)
{
recv_flag = recv_mess(itera, cntrl->status_string[drive], 0);
Debug(2, "start_status(): Card %d Status_string=%s\n", itera, cntrl->status_string[drive]);
}
recv_mess(itera, buff, 1); /* Get Prompt */
if (recv_flag)
cntrl->status = NORMAL;
else
{
if (cntrl->status == NORMAL)
cntrl->status = RETRY;
else
cntrl->status = COMM_ERR;
}
}
/* Find the selected channel per driver */
for (itera = 0; (itera < total_cards) && motor_state[itera]; itera++)
send_mess(itera, GET_CHAN_SELECT, NULL);
for (itera = 0; (itera < total_cards) && motor_state[itera]; itera++)
{
cntrl = (struct PMNCcontroller *) motor_state[itera]->DevicePrivate;
total_drives = cntrl->total_drivers;
for (drive=0, recv_flag=1; drive < total_drives && recv_flag; drive++)
{
recv_flag = recv_mess(itera, cntrl->chan_select_string[drive], 0);
Debug(2, "start_status(): Card %d ChanSelect_string=%s\n", itera, cntrl->chan_select_string[drive]);
}
recv_mess(itera, buff, 1); /* Get Prompt */
}
/* Only the selected channel on each driver is returned */
for (itera = 0; (itera < total_cards) && motor_state[itera]; itera++)
send_mess(itera, READ_POSITION, NULL);
for (itera = 0; (itera < total_cards) && motor_state[itera]; itera++)
{
cntrl = (struct PMNCcontroller *) motor_state[itera]->DevicePrivate;
total_drives = cntrl->total_drivers;
for (drive=0, recv_flag=1; drive < total_drives && recv_flag; drive++)
{
recv_flag = recv_mess(itera, cntrl->position_string[drive], 0);
Debug(2, "start_status(): Card %d Position_string=%s\n", itera, cntrl->position_string[drive]);
}
recv_mess(itera, buff, 1); /* Get Prompt */
}
}
}
/**************************************************************
* Parse status and position strings for a card and signal
* set_status()
************************************************************/
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 *p;
char buff[BUFF_SIZE];
MOTOR_STATUS mstat;
int rtn_state;
int drive, scan_drive, scan_mstat;
int drive_motor, scan_motor;
long motorData;
bool plusdir, ls_active = false;
msta_field status;
cntrl = (struct PMNCcontroller *) motor_state[card]->DevicePrivate;
motor_info = &(motor_state[card]->motor_info[signal]);
status.All = motor_info->status.All;
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;
/* Calculate the drive number */
drive = signal / PMNC8750_NUM_MOTORS;
drive_motor = signal % PMNC8750_NUM_MOTORS;
/* Setup equality test by default invalid values*/
scan_drive= scan_motor = -1;
/* Find the currently Select drive motor */
p = cntrl->chan_select_string[drive];
if (sscanf(p, "A%d=%d",&scan_drive, &scan_motor) == 2)
{
Debug(5, "set_status(): Selected drive %d: chan = %x\n", scan_drive, scan_motor);
}
else
{
Debug(1, "set_status(): Selected drive %d: INVALID chan string %s\n", drive, p);
}
/* Set defaults in-case motor is not selected */
motorData = cntrl->last_position[signal];
mstat.All = 0;
/* Status and Position input only apply to selected motor so
* only parse the strings if motor is selected */
if (drive_motor == scan_motor)
{
/*
* Index to Drive entry and parse the status string
* Status string format: [0] SYSTEM STATUS 0x0
* [1] A1=0xhh were hh is status byte
* [2] A2=0xhh were hh is status byte
* .
*/
p = cntrl->status_string[scan_drive];
if (sscanf(p, "A%d=0x%x",&scan_drive, &scan_mstat) == 2)
{
mstat.All = scan_mstat;
Debug(5, "set_status(): drive %d - status byte = %x\n", scan_drive, scan_mstat);
}
else
Debug(1, "set_status(): drive %d - INVALID status string %s\n", drive, p);
/*
* Parse motor position
* Position string format: A1=##### <CR>A2=###### <CR>A3=##### .....
* Skip to substring for this motor, convert to double
*/
p = cntrl->position_string[scan_drive-1]; /* Drive numbers start at 1 */
if (sscanf(p, "A%d=%ld",&scan_drive, &motorData) == 2)
{
Debug(6, "set_status(): drive %d - position = %ld\n", scan_drive, motorData);
}
else
Debug(1, "set_status(): drive %d - INVALID position string %s\n", drive, p);
}
else
{
motorData = cntrl->last_position[signal] = 0;
Debug(5, "set_status(): NOT SELECTED drive %d, motor %d\n", drive, drive_motor);
}
/* Interpret data and move it into global area */
if (mstat.Bits.inMotion == false)
status.Bits.RA_DONE = 1;
else
status.Bits.RA_DONE = 0;
/* Drive Enabled */
status.Bits.EA_POSITION = (mstat.Bits.powerOn) ? 1: 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;
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++;
else
{
motor_info->position += (motorData - cntrl->last_position[signal]);
if (motor_state[card]->motor_info[signal].encoder_present == YES)
motor_info->encoder_position += (epicsInt32) (motorData - cntrl->last_position[signal]);
else
motor_info->encoder_position = 0;
cntrl->last_position[signal] = motorData;
motor_info->no_motion_count = 0;
}
Debug(1, ", Accum Pos: %d\n", motor_info->position);
/* Use sign of motor position (always relative) for direction */
status.Bits.RA_DIRECTION = (motorData >= 0) ? 1 : 0;
plusdir = (status.Bits.RA_DIRECTION) ? true : false;
status.Bits.RA_PROBLEM = 0;
/* Parse motor velocity? */
/* NEEDS WORK */
motor_info->velocity = 0;
if (!plusdir)
motor_info->velocity *= -1;
rtn_state = (!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) )
{
cntrl->last_position[signal] = 0; /* Reset last position after each move */
if (drive_motor == scan_motor)
{
/* Clear position on selected motor */
sprintf(buff, "CHL A%d=%d", scan_drive, scan_motor);
send_noreply_mess(card, buff, 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_noreply_mess(card, buff, NULL);
}
nodeptr->postmsgptr = NULL;
}
}
exit:
motor_info->status.All = status.All;
return(rtn_state);
}
/*****************************************************/
/* send a message to the */
/* PMNC8750 motor controller board with a handshake */
/* on the return of the prompt '>' character */
/* send_noreply_mess() */
/*****************************************************/
STATIC RTN_STATUS send_noreply_mess(int card, char const *com, char *inchar)
{
struct PMNCcontroller *cntrl;
char reply_buff[BUFF_SIZE]; /* Used to receive prompt after multiple commands */
int size;
size_t nwrite;
size_t nread = 0;
asynStatus status;
int eomReason;
size = strlen(com);
if (size > MAX_MSG_SIZE)
{
errlogMessage("drvPMNC8750: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("drvPMNC8750:send_mess() - invalid card #%d\n", card);
return(ERROR);
}
if (inchar != NULL)
{
errlogPrintf("drvPMNC8750:send_mess() - invalid argument = %s\n", inchar);
return(ERROR);
}
cntrl = (struct PMNCcontroller *) motor_state[card]->DevicePrivate;
/* Set Reply End-of-string - temporary */
pasynOctetSyncIO->setInputEos(cntrl->pasynUser,NOREPLY_EOS,strlen(NOREPLY_EOS));
/* Perform atomic write/read operation */
status = pasynOctetSyncIO->writeRead(cntrl->pasynUser, com, size,
reply_buff, BUFF_SIZE-1,
SERIAL_TIMEOUT, &nwrite, &nread, &eomReason);
Debug(2, "send_noreply_mess(): message = %s, status = %d\n ", com, status);
/* Reset Reply End-of-string to default */
pasynOctetSyncIO->setInputEos(cntrl->pasynUser,REPLY_EOS,strlen(REPLY_EOS));
if (status != asynSuccess)
return(ERROR);
else
return (OK);
}
/*****************************************************/
/* send a message to the PMNC8750 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("drvPMNC8750: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("drvPMNC8750:send_mess() - invalid card #%d\n", card);
return(ERROR);
}
if (name != NULL)
{
errlogPrintf("drvPMNC8750: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,
SERIAL_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 PMNC8750 sometimes responds to an MS command with an error
* message (see PMNC8750 User's Manual Appendix A). This is an
* unconfirmed PMNC8750 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 = SERIAL_TIMEOUT;
}
if (flush) status = pasynOctetSyncIO->flush(cntrl->pasynUser);
if (flag == 1)
// Temporary Change to EOS
pasynOctetSyncIO->setInputEos(cntrl->pasynUser,NOREPLY_EOS,strlen(NOREPLY_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 == 1)
// Reset EOS to default
pasynOctetSyncIO->setInputEos(cntrl->pasynUser,REPLY_EOS,strlen(REPLY_EOS));
Debug(2, "recv_mess(): message = \"%s\"\n", com);
return (nread);
}
/*****************************************************/
/* Setup system configuration */
/* PMNC8750Setup() */
/*****************************************************/
RTN_STATUS
PMNC8750Setup(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 > PMNC8750_NUM_CARDS)
PMNC8750_num_cards = PMNC8750_NUM_CARDS;
else
PMNC8750_num_cards = num_cards;
if (num_drivers < 1 || num_drivers > PMNC8750_NUM_DRIVERS)
PMNC8750_num_drivers = PMNC8750_NUM_DRIVERS;
else
PMNC8750_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 PMNC8750Config 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(PMNC8750_num_cards *
sizeof(struct controller *));
for (itera = 0; itera < PMNC8750_num_cards; itera++)
motor_state[itera] = (struct controller *) NULL;
return(OK);
}
/*****************************************************/
/* Configure a controller */
/* PMNC8750Config() */
/*****************************************************/
RTN_STATUS
PMNC8750Config(int card, /* card being configured */
const char *port, /* asyn port name */
int address) /* asyn address (GPIB) */
{
struct PMNCcontroller *cntrl;
if (card < 0 || card >= PMNC8750_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;
int card_index, motor_index;
char axis_pos[BUFF_SIZE];
char buff[BUFF_SIZE];
char *bufptr;
int total_axis = 0;
RTN_STATUS rtnStatus;
asynStatus success_rtn;
initialized = true; /* Indicate that driver is initialized. */
/* Check for setup */
if (PMNC8750_num_cards <= 0)
return(ERROR);
for (card_index = 0; card_index < PMNC8750_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,REPLY_EOS,strlen(REPLY_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
{
rtnStatus = send_noreply_mess(card_index, MOTOR_OFF, (char) NULL);
retry++;
/* Return value is length of response string */
} while(rtnStatus == ERROR && retry < 3);
}
if (success_rtn == asynSuccess && rtnStatus == OK)
{
brdptr->localaddr = (char *) NULL;
brdptr->motor_in_motion = 0;
send_noreply_mess(card_index, STOP_ALL, NULL); /* Stop all motors */
send_noreply_mess(card_index, INIT_ALL, NULL); /* Initalize all devices */
send_noreply_mess(card_index, MOTOR_ON, NULL); /* Initalize all devices */
send_mess(card_index, GET_IDENT, NULL); /* Read controller ID string */
recv_mess(card_index, buff, 0);
strncpy(brdptr->ident, &buff[0], MAX_IDENT_LEN); /* Skip "VE" */
recv_mess(card_index, buff, 1); /* Get Prompt */
/* Set Motion Master model indicator. */
bufptr = strstr(brdptr->ident, "Version 1.");
if (bufptr == NULL)
{
errlogPrintf("drvPMNC8750.c:motor_init() - unknown version = %s\n", brdptr->ident);
motor_state[card_index] = (struct controller *) NULL;
continue;
}
if (true) /* Model check - no way to check model */
cntrl->model = PMNC8750;
else
{
errlogPrintf("drvPMNC8750:motor_init() - invalid model = %s\n", brdptr->ident);
return(ERROR);
}
total_axis = 0;
send_mess(card_index, GET_MPV, NULL);
/* Number of return strings will tell us how many axes this controller has */
while (recv_mess(card_index, axis_pos, 0))
{
brdptr->motor_info[total_axis].motor_motion = NULL;
Debug(3, "motor_init(): Next Axis %s\n", axis_pos);
total_axis++;
}
brdptr->total_axis = total_axis;
cntrl->total_drivers = total_axis / PMNC8750_NUM_MOTORS;
Debug(2, "motor_init(): Total Axis=%d\n", brdptr->total_axis);
start_status(card_index);
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->encoder_present = NO;
motor_info->position = 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 *) "PMNC8750_motor", epicsThreadPriorityMedium,
epicsThreadGetStackSize(epicsThreadStackMedium),
(EPICSTHREADFUNC) motor_task, (void *) &targs);
return(OK);
}
/*---------------------------------------------------------------------*/
+115
View File
@@ -0,0 +1,115 @@
/*
FILENAME... drvPMNCCom.h
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
Last Modified: 2004/08/17 21:28:22
*/
/*
* Original Author: Mark Rivers
* Current Author: Mark Rivers
* 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 01-18-93 mlr initialized from drvOms58
* .02 06-16-03 rls Converted to R3.14.x.
*/
#ifndef INCdrvPMNCComh
#define INCdrvPMNCComh 1
#include "motor.h"
#include "motordrvCom.h"
#include "asynDriver.h"
#include "asynOctetSyncIO.h"
enum PMNC_model
{
PMNC8750
};
#ifndef __cplusplus
typedef enum PMNC_model PMNC_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 */
/* Motion Master specific data is stored in this structure. */
struct PMNCcontroller
{
asynUser *pasynUser; /* For RS-232 */
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 */
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. */
};
/* Motor status response for PMNC. */
typedef union
{
epicsUInt8 All;
struct
{
#ifdef MSB_First
bool bit7 :1; /* Bit #7 N/A. */
bool positionMode :1; /* Set if moving in position mode */
bool velocityMode :1; /* Set if moving in velocity mode */
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 inMotion :1; /* In-motion indicator. */
#else
bool inMotion :1; /* In-motion indicator. */
bool checksumError :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 */
bool velocityMode :1; /* Set if moving in velocity mode */
bool positionMode :1; /* Set if moving in position mode */
bool bit7 :1; /* Bit #7 N/A. */
#endif
} Bits;
} MOTOR_STATUS;
#endif /* INCdrvPMNCComh */