diff --git a/motorApp/PiSrc/drvPIC844.cc b/motorApp/PiSrc/drvPIC844.cc index dc5c4a02..ca637d1b 100644 --- a/motorApp/PiSrc/drvPIC844.cc +++ b/motorApp/PiSrc/drvPIC844.cc @@ -3,9 +3,9 @@ FILENAME... drvPIC844.cc USAGE... Motor record driver level support for Physik Instrumente (PI) GmbH & Co. C-844 motor controller. -Version: $Revision: 1.8 $ +Version: $Revision: 1.9 $ Modified By: $Author: sluiter $ -Last Modified: $Date: 2004-09-21 14:41:41 $ +Last Modified: $Date: 2004-12-20 21:35:37 $ */ /* @@ -41,6 +41,10 @@ Last Modified: $Date: 2004-09-21 14:41:41 $ * .04 09/09/04 rls - Retry on initial comm. (PIC844 comm. locks up when IOC * is power cycled). * .05 09/21/04 rls - support for 32axes/controller. + * .06 12/16/04 rls - asyn R4.0 support. + * - make debug variables always available. + * - MS Visual C compatibility; make all epicsExportAddress + * extern "C" linkage. */ /* @@ -68,7 +72,6 @@ DESIGN LIMITATIONS... /*----------------debugging-----------------*/ #ifdef __GNUG__ #ifdef DEBUG - volatile int drvPIC844debug = 0; #define Debug(l, f, args...) { if(l<=drvPIC844debug) printf(f,## args); } #else #define Debug(l, f, args...) @@ -76,6 +79,8 @@ DESIGN LIMITATIONS... #else #define Debug() #endif +volatile int drvPIC844debug = 0; +extern "C" {epicsExportAddress(int, drvPIC844debug);} /* --- Local data. --- */ int PIC844_num_cards = 0; @@ -126,7 +131,7 @@ struct long (*init) (void); } drvPIC844 = {2, report, init}; -epicsExportAddress(drvet, drvPIC844); +extern "C" {epicsExportAddress(drvet, drvPIC844);} static struct thread_args targs = {SCAN_RATE, &PIC844_access}; @@ -396,16 +401,18 @@ static RTN_STATUS send_mess(int card, char const *com, char *name) { char local_buff[MAX_MSG_SIZE]; struct PIC844controller *cntrl; - int size; + int comsize, namesize; + int nwrite; - size = strlen(com); - - if (size > MAX_MSG_SIZE) + comsize = (com == NULL) ? 0 : strlen(com); + namesize = (name == NULL) ? 0 : strlen(name); + + if ((comsize + namesize) > MAX_MSG_SIZE) { errlogMessage("drvPIC844.cc:send_mess(); message size violation.\n"); return(ERROR); } - else if (size == 0) /* Normal exit on empty input message. */ + else if (comsize == 0) /* Normal exit on empty input message. */ return(OK); if (!motor_state[card]) @@ -423,15 +430,14 @@ static RTN_STATUS send_mess(int card, char const *com, char *name) strcat(local_buff, ";"); /* put in comman seperator. */ } - /* Make a local copy of the string and add the command line terminator. */ + /* Make a local copy of the string. */ strcat(local_buff, com); - strcat(local_buff, "\n"); Debug(2, "send_mess(): message = %s\n", local_buff); cntrl = (struct PIC844controller *) motor_state[card]->DevicePrivate; pasynOctetSyncIO->write(cntrl->pasynUser, local_buff, strlen(local_buff), - COMM_TIMEOUT); + COMM_TIMEOUT, &nwrite); return(OK); } @@ -444,9 +450,8 @@ static RTN_STATUS send_mess(int card, char const *com, char *name) static int recv_mess(int card, char *com, int flag) { struct PIC844controller *cntrl; - int flush = 0; - int timeout; - int len=0; + int nread = 0; + asynStatus status = asynError; int eomReason; /* Check that card exists */ @@ -454,25 +459,21 @@ static int recv_mess(int card, char *com, int flag) return(ERROR); cntrl = (struct PIC844controller *) motor_state[card]->DevicePrivate; - + if (flag == FLUSH) - timeout = 0; + pasynOctetSyncIO->flush(cntrl->pasynUser); else - timeout = COMM_TIMEOUT; + status = pasynOctetSyncIO->read(cntrl->pasynUser, com, BUFF_SIZE, + COMM_TIMEOUT, &nread, &eomReason); - len = pasynOctetSyncIO->read(cntrl->pasynUser, com, BUFF_SIZE, (char *) "\n", - 1, flush, timeout, &eomReason); - - if (len == 0) - com[0] = '\0'; - else + if ((status != asynSuccess) || (nread <= 0)) { - com[len - 1] = '\0'; - len -= 1; + com[0] = '\0'; + nread = 0; } Debug(2, "recv_mess(): message = \"%s\"\n", com); - return(len); + return(nread); } @@ -552,6 +553,8 @@ static int motor_init() int total_axis; int status; asynStatus success_rtn; + static const char output_terminator[] = "\n"; + static const char input_terminator[] = "\n"; initialized = true; /* Indicate that driver is initialized. */ @@ -571,18 +574,21 @@ static int motor_init() cntrl = (struct PIC844controller *) brdptr->DevicePrivate; /* Initialize communications channel */ - success_rtn = pasynOctetSyncIO->connect(cntrl->asyn_port, - cntrl->asyn_address, &cntrl->pasynUser); + success_rtn = pasynOctetSyncIO->connect(cntrl->asyn_port, 0, + &cntrl->pasynUser, NULL); if (success_rtn == asynSuccess) { int retry = 0; + pasynOctetSyncIO->setOutputEos(cntrl->pasynUser, output_terminator, + strlen(output_terminator)); + pasynOctetSyncIO->setInputEos(cntrl->pasynUser, input_terminator, + strlen(input_terminator)); + /* Send a message to the board, see if it exists */ /* flush any junk at input port - should not be any data available */ - do - recv_mess(card_index, buff, FLUSH); - while (strlen(buff) != 0); + pasynOctetSyncIO->flush(cntrl->pasynUser); do {