Add threshold routines and Linux adaptations

This commit is contained in:
cvs
2000-10-20 06:42:25 +00:00
parent 12c5d4dc6b
commit ce6eb2944d

View File

@ -1,4 +1,4 @@
#define ident "2B01"
#define ident "2B03"
#ifdef VAXC
#module EL737_Utility ident
#endif
@ -47,6 +47,7 @@
** 2A01 6-Aug-1997 DM. Cope with new RA response format (= timer first)
** Add EL737_GetLongStatus.
** 2B01 5-Aug-1998 DM. Put messages into a .MSG file.
** 2B02 22-Apr-1999 DM. Add EL737_GetThresh and EL737_SetThresh.
**============================================================================
** The entry points included in this module are described below. Prototypes
** can be defined via:
@ -56,14 +57,18 @@
** EL737_Close - Close a connection to an EL737 counter.
** EL737_Config - Configure a connection to an EL737 counter.
** EL737_Continue - Continue a measurement with an EL737 counter.
** EL737_EnableThresh - Enable/disable threshold monitoring.
** EL737_ErrInfo - Return detailed status from last operation.
** EL737_GetMonIntegTime - Get Monitor Integration Time (DI register).
** EL737_GetRateIntegTime - Get Rate Integration Time (DT register).
** EL737_GetStatus - Get 4 counters and counter status.
** EL737_GetStatusExtra - Get counters 5 to 8.
** EL737_GetThresh - Get threshold monitoring status.
** EL737_Open - Open a connection to an EL737 counter.
** EL737_Pause - Pause a measurement with an EL737 counter.
** EL737_SendCmnd - Send a command to RS232C server.
** EL737_SetErrcode - Set up EL737_errcode.
** EL737_SetThresh - Set threshold monitoring level.
** EL737_StartCnt - Start a preset cnt measurement with an EL737.
** EL737_StartTime - Start a preset time measurement with an EL737.
** EL737_Stop - Stop a measurement with an EL737 counter.
@ -161,6 +166,39 @@
** EL737_Continue sends a CO command to the counter to get it to continue
** a paused measurement and then an RS command to read its status.
**-------------------------------------------------------------------------
** int EL737_EnableThresh (&handle, indx)
** ------------------
** Input Args:
** void **handle - The pointer to the structure returned by EL737_Open.
** int indx - The number of the counter to select as the "active"
** threshold monitoring counter. If (indx == 0),
** threshold monitoring is disabled.
** Output Args:
** none
** Modified Args:
** none
** Return status:
** True if no problems detected, otherwise False and EL737_ErrInfo
** can be called to identify the problem. Values of Errcode set by
** EL737_EnableThresh are (other values may be set by the called routines):
** EL737__OFL, __BAD_CMD, __BAD_TMO, __BAD_ASYNSRV --> see EL737_Open.
** EL737__BAD_BSY --> "?2" response received - cntr probably in
** wrong state.
** EL737__BAD_PAR --> Bad parameter. Illegal value for <indx> or "?3"
** or "?4" response received.
** EL737__BAD_ILLG --> the response to the commands was illegal in
** some way. This could happen if there is noise
** on the RS232C connection to the EL737.
** Routines called:
** AsynSrv_SendCmnds
** Description:
** A "DR <indx>" command is sent to select counter <indx> to be the
** "active" threshold monitoring counter. A value of 0 causes
** threshold monitoring to be disabled in the EL737. The threshold
** for the selected counter will not be changed. If it is required
** to set a threshold value as well as enabling monitoring, it is
** simplest to use EL737_SetThresh.
**-------------------------------------------------------------------------
** void EL737_ErrInfo (&entry_txt_ptr, &errcode, &my_errno, &vaxc_errno)
** -------------
** Input Args:
@ -181,10 +219,11 @@
** Returns detailed status of the last operation. Once an error has been
** detected, the error status is frozen until this routine has been called.
**-------------------------------------------------------------------------
** int EL737_GetMonIntegTime (&handle, &mon_integ_time)
** int EL737_GetMonIntegTime (&handle, indx, &mon_integ_time)
** ---------------------
** Input Args:
** void **handle - The pointer to the structure returned by EL737_Open.
** int indx - The counter whose integ time is wanted.
** Output Args:
** float *mon_integ_time - The integration time used for monitoring
** the rate threshold.
@ -203,7 +242,7 @@
** Routines called:
** AsynSrv_SendCmnds
** Description:
** The routine issues a DI command to the controller and
** The routine issues a "DI <indx>" command to the controller and
** analyses the result.
**-------------------------------------------------------------------------
** int EL737_GetRateIntegTime (&handle, &rate_integ_time)
@ -257,7 +296,9 @@
** AsynSrv_SendCmnds
** Description:
** The routine issues an RA and RS command to the controller and
** analyses the result.
** analyses the result. If a syntax error is detected in either the RA
** or RS response, the routine tries up to 3 times to get a meaningful
** reply.
**-------------------------------------------------------------------------
** int EL737_GetStatusExtra (&handle, &c5, &c6, &c7, &c8)
** --------------------
@ -280,6 +321,32 @@
** return values for counters 1, 2, 3 and 4 must precede a call to
** EL737_GetStatusExtra.
**-------------------------------------------------------------------------
** int EL737_GetThresh (&handle, &indx, &val)
** ---------------
** Input Args:
** void **handle - The pointer to the structure returned by EL737_Open.
** Output Args:
** int *indx - The number of the threshold monitor counter. If =0,
** threshold monitoring is disabled.
** float *val - If *indx != 0, the value of the threshold. Otherwise,
** it is zero.
** Modified Args:
** none
** Return status:
** True if no problems detected, otherwise False and EL737_ErrInfo
** can be called to identify the problem. Values of Errcode set by
** EL737_GetThresh are (other values may be set by the called routines):
** EL737__BAD_TMO, _LOC, _CMD, _OFL, _ADR, _ASYNSRV --> see EL737_Open.
** EL737__BAD_ILLG --> one of the responses could probably not be
** decoded. This could happen if there is noise
** on the RS232C connection to the EL737.
** If an error is detected, all arguments are set to 0.
** Routines called:
** AsynSrv_SendCmnds
** Description:
** The routine issues a DR and, if threshold monitoring is enabled,
** a "DL <indx>" command to the controller and analyses the responses.
**-------------------------------------------------------------------------
** int EL737_Open (&handle, &host, port, chan)
** ----------
** Input Args:
@ -371,6 +438,65 @@
** Description:
** The command is passed to AsynSrv_SendCmnds and the reply extracted.
**-------------------------------------------------------------------------
** int EL737_SetErrcode (&info_ptr, &response, &cmnd)
** ----------------
** Set up EL737_errcode (for internal use only)
** Input Args:
** struct EL737info *info_ptr - The pntr to the structure returned by
** EL737_Open.
** char *response - The response received from a command.
** char *cmnd - The command which was sent.
** Output Args:
** none
** Modified Args:
** none
** Return status:
** The value of EL737_errcode.
** Routines called:
** none
** Description:
** The command checks *response for certain keywords and sets EL737_errcode
** accordingly.
**-------------------------------------------------------------------------
** int EL737_SetThresh (&handle, indx, val)
** ---------------
** Input Args:
** void **handle - The pointer to the structure returned by EL737_Open.
** int indx - The number of the counter whose threshold is to
** be set. If (indx == 0), threshold monitoring is
** disabled and val is not used.
** float val - The value of the threshold to be set.
** Output Args:
** none
** Modified Args:
** none
** Return status:
** True if no problems detected, otherwise False and EL737_ErrInfo
** can be called to identify the problem. Values of Errcode set by
** EL737_SetThresh are (other values may be set by the called routines):
** EL737__OFL, __BAD_CMD, __BAD_TMO, __BAD_ASYNSRV --> see EL737_Open.
** EL737__BAD_BSY --> "?2" response received - cntr probably in
** wrong state.
** EL737__BAD_PAR --> Bad parameter. Illegal value for <indx> or "?3"
** or "?4" response received.
** EL737__BAD_ILLG --> the response to the commands was illegal in
** some way. This could happen if there is noise
** on the RS232C connection to the EL737.
** Routines called:
** AsynSrv_SendCmnds, EL737_EnableThresh
** Description:
** a) If (indx == 0): EL737_SetThresh simply calls EL737_EnableThresh to
** send a "DR 0" command which will disable threshold
** monitoring by the counter.
**
** b) If (indx != 0): First of all, a "DL <indx> |<val>|" command is sent
** to the counter to set the threshold for counter <indx>
** to the absolute value of <val>.
** Then, if (val >= 0), EL737_EnableThresh is then called
** to select counter <indx> to be the "active" threshold
** monitoring counter. Otherwise, the "active" counter
** is not changed.
**-------------------------------------------------------------------------
** int EL737_StartCnt (&handle, count, &status)
** --------------
** Input Args:
@ -500,9 +626,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#ifndef LINUX
#include <timers.h>
#endif
#include <math.h>
#include <errno.h>
#include <signal.h>
#include <netdb.h>
@ -512,9 +636,12 @@
#include <string.h>
#ifdef __VMS
#include <unixio.h>
#include <unixio.h>
#else
#include <unistd.h>
#include <unistd.h>
#ifdef FORTIFY
#include <fortify/fortify.h>
#endif
#endif
/*-----------------------------------------------------------------*/
#include <sinq_prototypes.h>
@ -665,36 +792,71 @@
*/
my_status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host,
"co\r", "rs\r", NULL);
"CO\r", "RS\r", NULL);
if (!my_status) {
EL737_errcode = EL737__BAD_ASYNSRV;
return False;
}else {
rply_ptr1 = NULL;
rply_ptr0 = AsynSrv_GetReply (
}
rply_ptr1 = NULL;
rply_ptr0 = AsynSrv_GetReply (
&info_ptr->asyn_info, &info_ptr->from_host, NULL);
if (rply_ptr0 != NULL) rply_ptr1 = AsynSrv_GetReply (
if (rply_ptr0 != NULL) rply_ptr1 = AsynSrv_GetReply (
&info_ptr->asyn_info, &info_ptr->from_host, rply_ptr0);
if (rply_ptr0 == NULL) rply_ptr0 = "?";
if (rply_ptr1 == NULL) rply_ptr1 = "?";
if ((*rply_ptr0 == '\0') &&
(sscanf (rply_ptr1, "%d", status) == 1)) {
if (EL737_errcode != 0) return False;
EL737_call_depth--;
return True;
}
EL737_errcode = EL737__BAD_ILLG;
if (strcmp (rply_ptr0, "?OF" ) == 0) EL737_errcode = EL737__BAD_LOC;
if (strcmp (rply_ptr0, "?OFL") == 0) EL737_errcode = EL737__BAD_OFL;
if (strcmp (rply_ptr0, "?OV" ) == 0) EL737_errcode = EL737__BAD_OVFL;
if (strcmp (rply_ptr0, "?1" ) == 0) EL737_errcode = EL737__BAD_CMD;
if (strcmp (rply_ptr0, "?2" ) == 0) EL737_errcode = EL737__BAD_BSY;
if (strcmp (rply_ptr0, "?3" ) == 0) EL737_errcode = EL737__BAD_PAR;
if (strncmp (rply_ptr0, "?TMO", 4) == 0) EL737_errcode = EL737__BAD_TMO;
*status = 0;
return False;
if (rply_ptr0 == NULL) rply_ptr0 = "?";
if (rply_ptr1 == NULL) rply_ptr1 = "?";
if ((*rply_ptr0 == '\0') &&
(sscanf (rply_ptr1, "%d", status) == 1)) {
if (EL737_errcode != 0) return False;
EL737_call_depth--;
return True;
}
*status = 0;
EL737_SetErrcode (info_ptr, rply_ptr0, "CO\" or \"RS");
return False;
}
/*
**---------------------------------------------------------------------------
** EL737_EnableThresh: Enable/disable Threshold Monitoring.
*/
int EL737_EnableThresh (
/* ==================
*/ void **handle,
int indx) {
int status;
char cmnd[20];
struct EL737info *info_ptr;
char *rply_ptr0;
/*----------------------------------------------
*/
info_ptr = (struct EL737info *) *handle;
if (!EL737_AddCallStack (info_ptr, "EL737_EnableThresh")) return False;
if ((indx < 0) || (indx > 8)) {
EL737_errcode = EL737__BAD_PAR; return False;
}
/*----------------------------------------------
** Send "DR <indx>" cmnd to EL737 to select the
** "active" threshold rate counter.
*/
sprintf (cmnd, "DR %d\r", indx);
status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host,
cmnd, NULL);
if (!status) {
EL737_errcode = EL737__BAD_ASYNSRV; return False;
}
rply_ptr0 = AsynSrv_GetReply (
&info_ptr->asyn_info, &info_ptr->from_host, NULL);
if (rply_ptr0 == NULL) rply_ptr0 = "?";
if (*rply_ptr0 == '\0') {
EL737_call_depth--;
return True;
}
EL737_SetErrcode (info_ptr, rply_ptr0, cmnd);
return False;
}
/*
** -------------------------------------------------------------------------
@ -732,6 +894,7 @@
case EL737__BAD_ASYNSRV: strcpy (buff, "/EL737__BAD_ASYNSRV"); break;
case EL737__BAD_BSY: strcpy (buff, "/EL737__BAD_BSY"); break;
case EL737__BAD_CMD: strcpy (buff, "/EL737__BAD_CMD"); break;
case EL737__BAD_CNTR: strcpy (buff, "/EL737__BAD_CNTR"); break;
case EL737__BAD_DEV: strcpy (buff, "/EL737__BAD_DEV"); break;
case EL737__BAD_ILLG: strcpy (buff, "/EL737__BAD_ILLG"); break;
case EL737__BAD_LOC: strcpy (buff, "/EL737__BAD_LOC"); break;
@ -741,9 +904,11 @@
case EL737__BAD_PAR: strcpy (buff, "/EL737__BAD_PAR"); break;
case EL737__BAD_SOCKET: strcpy (buff, "/EL737__BAD_SOCKET"); break;
case EL737__BAD_TMO: strcpy (buff, "/EL737__BAD_TMO"); break;
case EL737__CNTR_OVFL: strcpy (buff, "/EL737__CNTR_OVFL"); break;
case EL737__FORCED_CLOSED: strcpy (buff, "/EL737__FORCED_CLOSED"); break;
case EL737__NOT_OPEN: strcpy (buff, "/EL737__NOT_OPEN"); break;
case EL737__NO_SOCKET: strcpy (buff, "/EL737__NO_SOCKET"); break;
case EL737__NO_VALUE: strcpy (buff, "/EL737__NO_VALUE"); break;
default: sprintf (buff, "/EL737__unknown_err_code: %d", EL737_errcode);
}
StrJoin (EL737_routine[0], sizeof(EL737_routine), EL737_routine[0], buff);
@ -760,14 +925,16 @@
}
/*
**---------------------------------------------------------------------------
** EL737_GetMonIntegTime: Get DI register value.
** EL737_GetMonIntegTime: Get DI register value for a counter.
*/
int EL737_GetMonIntegTime (
/* =====================
*/ void **handle,
int indx,
float *mon_integ_time) {
int status;
char cmnd[20];
struct EL737info *info_ptr;
char *rply_ptr0;
/*----------------------------------------------
@ -777,11 +944,12 @@
if (!EL737_AddCallStack (info_ptr, "EL737_GetMonIntegTime")) return False;
/*----------------------------------------------
** Send DT cmnd to EL737
** Send "DI <indx>" cmnd to EL737
*/
sprintf (cmnd, "DI %d\r", indx);
status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host,
"dt\r", NULL);
cmnd, NULL);
if (!status) {
EL737_errcode = EL737__BAD_ASYNSRV;
return False;
@ -794,14 +962,8 @@
EL737_call_depth--;
return True;
}
EL737_errcode = EL737__BAD_ILLG;
if (strcmp (rply_ptr0, "?OF" ) == 0) EL737_errcode = EL737__BAD_LOC;
if (strcmp (rply_ptr0, "?OFL") == 0) EL737_errcode = EL737__BAD_OFL;
if (strcmp (rply_ptr0, "?OV" ) == 0) EL737_errcode = EL737__BAD_OVFL;
if (strcmp (rply_ptr0, "?1" ) == 0) EL737_errcode = EL737__BAD_CMD;
if (strcmp (rply_ptr0, "?2" ) == 0) EL737_errcode = EL737__BAD_BSY;
if (strncmp (rply_ptr0, "?TMO", 4) == 0) EL737_errcode = EL737__BAD_TMO;
*mon_integ_time = 0.1;
EL737_SetErrcode (info_ptr, rply_ptr0, cmnd);
return False;
}
}
@ -824,11 +986,11 @@
if (!EL737_AddCallStack (info_ptr, "EL737_GetRateIntegTime")) return False;
/*----------------------------------------------
** Send DI cmnd to EL737
** Send DT cmnd to EL737
*/
status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host,
"di\r", NULL);
"DT\r", NULL);
if (!status) {
EL737_errcode = EL737__BAD_ASYNSRV;
return False;
@ -841,13 +1003,7 @@
EL737_call_depth--;
return True;
}
EL737_errcode = EL737__BAD_ILLG;
if (strcmp (rply_ptr0, "?OF" ) == 0) EL737_errcode = EL737__BAD_LOC;
if (strcmp (rply_ptr0, "?OFL") == 0) EL737_errcode = EL737__BAD_OFL;
if (strcmp (rply_ptr0, "?OV" ) == 0) EL737_errcode = EL737__BAD_OVFL;
if (strcmp (rply_ptr0, "?1" ) == 0) EL737_errcode = EL737__BAD_CMD;
if (strcmp (rply_ptr0, "?2" ) == 0) EL737_errcode = EL737__BAD_BSY;
if (strncmp (rply_ptr0, "?TMO", 4) == 0) EL737_errcode = EL737__BAD_TMO;
EL737_SetErrcode (info_ptr, rply_ptr0, "DT");
*rate_integ_time = 0.1;
return False;
}
@ -866,69 +1022,57 @@
float *timer,
int *rs) {
int status, errcode, nvals;
int i, status, nvals;
struct EL737info *info_ptr;
char *rply_ptr;
char *rply_ptr0;
char *rply_ptr1;
char *rply_ptr, *p_cmnd;
/*----------------------------------------------
*/
*c1 = *c2 = *c3 = *c4 = *rs = 0; *timer = 0.0;
info_ptr = (struct EL737info *) *handle;
if (!EL737_AddCallStack (info_ptr, "EL737_GetStatus")) return False;
info_ptr->c5 = info_ptr->c6 = info_ptr->c7 = info_ptr->c8 = 0;
/*----------------------------------------------
** Send RA and RS cmnds to EL737
** Send RA and RS cmnds to EL737. Since this routine gets
** used such a lot, try up to 3 times if a syntax error in
** the reply is detected.
*/
status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
for (i = 0; i < 3; i++) {
status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host,
"ra\r", "rs\r", NULL);
if (!status) {
EL737_errcode = EL737__BAD_ASYNSRV;
return False;
}else {
rply_ptr1 = NULL;
rply_ptr0 = AsynSrv_GetReply (
"RA\r", "RS\r", NULL);
if (!status) {EL737_errcode = EL737__BAD_ASYNSRV; return False;}
p_cmnd = "RA";
rply_ptr = AsynSrv_GetReply (
&info_ptr->asyn_info, &info_ptr->from_host, NULL);
if (rply_ptr0 != NULL) rply_ptr1 = AsynSrv_GetReply (
&info_ptr->asyn_info, &info_ptr->from_host, rply_ptr0);
if (rply_ptr0 == NULL) rply_ptr0 = "?";
if (rply_ptr1 == NULL) rply_ptr1 = "?";
nvals = sscanf (rply_ptr0, "%f %d %d %d %d %d %d %d %d",
if (rply_ptr != NULL) {
nvals = sscanf (rply_ptr, "%f %d %d %d %d %d %d %d %d",
timer, c1, c2, c3, c4,
&info_ptr->c5, &info_ptr->c6,
&info_ptr->c7, &info_ptr->c8);
if (nvals != 9) nvals = sscanf (rply_ptr0, "%d %d %d %d %f",
if (nvals != 9) nvals = sscanf (rply_ptr, "%d %d %d %d %f",
c1, c2, c3, c4, timer);
if (nvals == 5) {
info_ptr->c5 = info_ptr->c6 = info_ptr->c7 = info_ptr->c8 = 0;
nvals = 9;
}
if ((nvals != 9) ||
(sscanf (rply_ptr1, "%d", rs) != 1)) {
if (*rply_ptr0 == '?') {
rply_ptr = rply_ptr0;
}else if (*rply_ptr1 == '?') {
rply_ptr = rply_ptr1;
}else {
rply_ptr = "?";
if (nvals == 5) {
info_ptr->c5 = info_ptr->c6 = info_ptr->c7 = info_ptr->c8 = 0;
nvals = 9;
}
if (nvals == 9) {
p_cmnd = "RS";
rply_ptr = AsynSrv_GetReply (
&info_ptr->asyn_info, &info_ptr->from_host, rply_ptr);
if (rply_ptr != NULL) {
if (sscanf (rply_ptr, "%d", rs) == 1) {
EL737_call_depth--;
return True;
}
}
}
errcode = EL737__BAD_ILLG;
if (strcmp (rply_ptr0, "?OF" ) == 0) errcode = EL737__BAD_LOC;
if (strcmp (rply_ptr0, "?OFL") == 0) errcode = EL737__BAD_OFL;
if (strcmp (rply_ptr0, "?OV" ) == 0) errcode = EL737__BAD_OVFL;
if (strcmp (rply_ptr0, "?1" ) == 0) errcode = EL737__BAD_CMD;
if (strcmp (rply_ptr0, "?2" ) == 0) errcode = EL737__BAD_BSY;
if (strncmp (rply_ptr0, "?TMO", 4) == 0) errcode = EL737__BAD_TMO;
EL737_errcode = errcode;
*c1 = *c2 = *c3 = *c4 = *rs = 0; *timer = 0.0;
return False;
}
}
if (EL737_errcode != 0) return False;
EL737_call_depth--;
return True;
if (rply_ptr == NULL) rply_ptr = "?";
EL737_SetErrcode (info_ptr, rply_ptr, p_cmnd);
*c1 = *c2 = *c3 = *c4 = *rs = 0; *timer = 0.0;
return False;
}
/*
**---------------------------------------------------------------------------
@ -961,6 +1105,75 @@
}
/*
**---------------------------------------------------------------------------
** EL737_GetThresh: Get threshold monitoring status.
*/
int EL737_GetThresh (
/* ===============
*/ void **handle,
int *indx,
float *val) {
int status, my_indx;
float my_val;
char cmnd[20];
struct EL737info *info_ptr;
char *rply_ptr0;
/*----------------------------------------------
*/
*indx = 0;
*val = 0.0;
info_ptr = (struct EL737info *) *handle;
if (!EL737_AddCallStack (info_ptr, "EL737_GetThresh")) return False;
/*----------------------------------------------
** Send DR cmnd to EL737 to get the number of the
** "active" threshold rate counter.
*/
status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host,
"DR\r", NULL);
if (!status) {
EL737_errcode = EL737__BAD_ASYNSRV;
return False;
}
rply_ptr0 = AsynSrv_GetReply (
&info_ptr->asyn_info, &info_ptr->from_host, NULL);
if (rply_ptr0 == NULL) rply_ptr0 = "?";
if ((sscanf (rply_ptr0, "%d", &my_indx) == 1) &&
(my_indx >= 0) &&
(my_indx <= 8)) {
*indx = my_indx;
if (my_indx != 0) {
/*----------------------------------------------
** Now send DL cmnd to EL737 to get the threshold value.
*/
sprintf (cmnd, "DL %d\r", my_indx);
status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host,
cmnd, NULL);
if (!status) {
EL737_errcode = EL737__BAD_ASYNSRV;
return False;
}
rply_ptr0 = AsynSrv_GetReply (
&info_ptr->asyn_info, &info_ptr->from_host, NULL);
if (rply_ptr0 == NULL) rply_ptr0 = "?";
if (sscanf (rply_ptr0, "%f", &my_val) == 1) {
*val = my_val;
EL737_call_depth--;
return True;
}
}else {
*val = 0.0;
EL737_call_depth--;
return True;
}
}
EL737_SetErrcode (info_ptr, rply_ptr0, cmnd);
return False;
}
/*
**---------------------------------------------------------------------------
** EL737_Open: Open a connection to an EL737 counter.
*/
int EL737_Open (
@ -972,7 +1185,6 @@
int status, c1, c2, c3, c4, nvals;
float timer;
int errcode;
struct EL737info *my_handle;
char tmo_save[4];
char *rply_ptr;
@ -1032,11 +1244,11 @@
*/
status = AsynSrv_SendCmnds (&my_handle->asyn_info,
&my_handle->to_host, &my_handle->from_host,
"rmt 1\r", NULL);
"RMT 1\r", NULL);
if (status) {
status = AsynSrv_SendCmnds (&my_handle->asyn_info,
&my_handle->to_host, &my_handle->from_host,
"rmt 1\r", "echo 2\r", "ra\r", NULL);
"RMT 1\r", "ECHO 2\r", "RA\r", NULL);
}
if (!status) {
/* Some error occurred in AsynSrv_SendCmnds */
@ -1088,15 +1300,7 @@
EL737_call_depth--;
return True;
}else {
errcode = EL737__BAD_ILLG;
if (strcmp (rply_ptr0, "?OF" ) == 0) errcode = EL737__BAD_LOC;
if (strcmp (rply_ptr0, "?OFL") == 0) errcode = EL737__BAD_OFL;
if (strcmp (rply_ptr0, "?OV" ) == 0) errcode = EL737__BAD_OVFL;
if (strcmp (rply_ptr0, "?1" ) == 0) errcode = EL737__BAD_CMD;
if (strcmp (rply_ptr0, "?2" ) == 0) errcode = EL737__BAD_BSY;
if (strcmp (rply_ptr0, "?3" ) == 0) errcode = EL737__BAD_PAR;
if (strncmp (rply_ptr0, "?TMO", 4) == 0) errcode = EL737__BAD_TMO;
EL737_errcode = errcode;
EL737_SetErrcode (my_handle, rply_ptr0, "RMT\", \"ECHO\" or \"RA");
}
}
AsynSrv_Close (&my_handle->asyn_info, False);
@ -1126,7 +1330,7 @@
*/
my_status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host,
"ps\r", "rs\r", NULL);
"PS\r", "RS\r", NULL);
if (!my_status) {
EL737_errcode = EL737__BAD_ASYNSRV;
return False;
@ -1145,14 +1349,7 @@
EL737_call_depth--;
return True;
}
EL737_errcode = EL737__BAD_ILLG;
if (strcmp (rply_ptr0, "?OF" ) == 0) EL737_errcode = EL737__BAD_LOC;
if (strcmp (rply_ptr0, "?OFL") == 0) EL737_errcode = EL737__BAD_OFL;
if (strcmp (rply_ptr0, "?OV" ) == 0) EL737_errcode = EL737__BAD_OVFL;
if (strcmp (rply_ptr0, "?1" ) == 0) EL737_errcode = EL737__BAD_CMD;
if (strcmp (rply_ptr0, "?2" ) == 0) EL737_errcode = EL737__BAD_BSY;
if (strcmp (rply_ptr0, "?3" ) == 0) EL737_errcode = EL737__BAD_PAR;
if (strncmp (rply_ptr0, "?TMO", 4) == 0) EL737_errcode = EL737__BAD_TMO;
EL737_SetErrcode (info_ptr, rply_ptr0, "PS\" or \"RS");
*status = 0;
return False;
}
@ -1197,6 +1394,94 @@
}
/*
**---------------------------------------------------------------------------
** EL737_SetErrcode - Set up EL737_errcode
*/
int EL737_SetErrcode (
/* ================
*/ struct EL737info *info_ptr,
char *response,
char *cmnd) {
int status, s_len;
char *rply;
char tmo_save[4];
char eot_save[4];
EL737_errcode = EL737__BAD_ILLG;
if (strcmp (response, "?OF" ) == 0) EL737_errcode = EL737__BAD_LOC;
if (strcmp (response, "?OFL") == 0) EL737_errcode = EL737__BAD_OFL;
if (strcmp (response, "?OV" ) == 0) EL737_errcode = EL737__BAD_OVFL;
if (strcmp (response, "?1" ) == 0) EL737_errcode = EL737__BAD_CMD;
if (strcmp (response, "?2" ) == 0) EL737_errcode = EL737__BAD_BSY;
if (strcmp (response, "?3" ) == 0) EL737_errcode = EL737__BAD_PAR;
if (strcmp (response, "?4" ) == 0) EL737_errcode = EL737__BAD_CNTR;
if (strcmp (response, "?5" ) == 0) EL737_errcode = EL737__NO_VALUE;
if (strcmp (response, "?6" ) == 0) EL737_errcode = EL737__CNTR_OVFL;
if (strncmp (response, "?TMO", 4) == 0) EL737_errcode = EL737__BAD_TMO;
if ((EL737_errcode == EL737__BAD_ILLG) && (cmnd != NULL)) {
s_len = strlen (cmnd);
if (cmnd[s_len-1] == '\r') s_len--;
fprintf (stderr, " Unrecognised response to \"%.*s\" command: \"%s\"\n",
s_len, cmnd, response);
}
return EL737_errcode;
}
/*
**---------------------------------------------------------------------------
** EL737_SetThresh: Set threshold monitoring level.
*/
int EL737_SetThresh (
/* ===============
*/ void **handle,
int indx,
float val) {
int status;
char cmnd[32];
struct EL737info *info_ptr;
char *rply_ptr0;
/*----------------------------------------------
*/
info_ptr = (struct EL737info *) *handle;
if (!EL737_AddCallStack (info_ptr, "EL737_SetThresh")) return False;
if ((indx < 0) || (indx > 8)) {
EL737_errcode = EL737__BAD_PAR; return False;
}
/*----------------------------------------------
** If <indx> is zero, simply call EL737_EnableThresh to
** disable threshold monitoring by the counter.
*/
if (indx == 0) {
return EL737_EnableThresh (handle, 0);
}
/*----------------------------------------------
** Send "DR <indx> |<val>|" cmnd to EL737 to set the
** threshold for counter <indx>.
*/
sprintf (cmnd, "DL %d %.3f\r", indx, fabs (val));
status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host,
cmnd, NULL);
if (!status) {
EL737_errcode = EL737__BAD_ASYNSRV; return False;
}
rply_ptr0 = AsynSrv_GetReply (
&info_ptr->asyn_info, &info_ptr->from_host, NULL);
if (rply_ptr0 == NULL) rply_ptr0 = "?";
if (*rply_ptr0 == '\0') {
if (val >= 0) return EL737_EnableThresh (handle, indx);
EL737_call_depth--;
return True;
}
EL737_SetErrcode (info_ptr, rply_ptr0, cmnd);
return False;
}
/*
**---------------------------------------------------------------------------
** EL737_StartCnt: Start a preset cnt measurement with an EL737.
*/
int EL737_StartCnt (
@ -1218,10 +1503,10 @@
/*----------------------------------------------
** Send MP and RS cmnds to EL737
*/
sprintf (cmnd, "mp %d\r", count); /* Encode an appropriate command */
sprintf (cmnd, "MP %d\r", count); /* Encode an appropriate command */
my_status = AsynSrv_SendCmnds (&info_ptr->asyn_info, /* Send it */
&info_ptr->to_host, &info_ptr->from_host,
cmnd, "rs\r", NULL);
cmnd, "RS\r", NULL);
if (!my_status) {
EL737_errcode = EL737__BAD_ASYNSRV;
return False;
@ -1240,14 +1525,7 @@
EL737_call_depth--;
return True;
}
EL737_errcode = EL737__BAD_ILLG;
if (strcmp (rply_ptr0, "?OF" ) == 0) EL737_errcode = EL737__BAD_LOC;
if (strcmp (rply_ptr0, "?OFL") == 0) EL737_errcode = EL737__BAD_OFL;
if (strcmp (rply_ptr0, "?OV" ) == 0) EL737_errcode = EL737__BAD_OVFL;
if (strcmp (rply_ptr0, "?1" ) == 0) EL737_errcode = EL737__BAD_CMD;
if (strcmp (rply_ptr0, "?2" ) == 0) EL737_errcode = EL737__BAD_BSY;
if (strcmp (rply_ptr0, "?3" ) == 0) EL737_errcode = EL737__BAD_PAR;
if (strncmp (rply_ptr0, "?TMO", 4) == 0) EL737_errcode = EL737__BAD_TMO;
EL737_SetErrcode (info_ptr, rply_ptr0, cmnd);
*status = 0;
return False;
}
@ -1275,10 +1553,10 @@
/*----------------------------------------------
** Send TP and RS cmnds to EL737
*/
sprintf (cmnd, "tp %.2f\r", timer); /* Encode an appropriate command */
sprintf (cmnd, "TP %.2f\r", timer); /* Encode an appropriate command */
my_status = AsynSrv_SendCmnds (&info_ptr->asyn_info, /* Send it */
&info_ptr->to_host, &info_ptr->from_host,
cmnd, "rs\r", NULL);
cmnd, "RS\r", NULL);
if (!my_status) {
EL737_errcode = EL737__BAD_ASYNSRV;
return False;
@ -1297,14 +1575,7 @@
EL737_call_depth--;
return True;
}
EL737_errcode = EL737__BAD_ILLG;
if (strcmp (rply_ptr0, "?OF" ) == 0) EL737_errcode = EL737__BAD_LOC;
if (strcmp (rply_ptr0, "?OFL") == 0) EL737_errcode = EL737__BAD_OFL;
if (strcmp (rply_ptr0, "?OV" ) == 0) EL737_errcode = EL737__BAD_OVFL;
if (strcmp (rply_ptr0, "?1" ) == 0) EL737_errcode = EL737__BAD_CMD;
if (strcmp (rply_ptr0, "?2" ) == 0) EL737_errcode = EL737__BAD_BSY;
if (strcmp (rply_ptr0, "?3" ) == 0) EL737_errcode = EL737__BAD_PAR;
if (strncmp (rply_ptr0, "?TMO", 4) == 0) EL737_errcode = EL737__BAD_TMO;
EL737_SetErrcode (info_ptr, rply_ptr0, cmnd);
*status = 0;
return False;
}
@ -1337,7 +1608,7 @@
*/
my_status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host,
"s\r", "rs\r", "ra\r", NULL);
"S\r", "RS\r", "RA\r", NULL);
if (!my_status) {
EL737_errcode = EL737__BAD_ASYNSRV;
return False;
@ -1375,14 +1646,7 @@
if (*rply_ptr1 == '?') rply_ptr0 = rply_ptr1;
if (*rply_ptr0 == '?') rply_ptr0 = rply_ptr2;
}
EL737_errcode = EL737__BAD_ILLG;
if (strcmp (rply_ptr0, "?OF" ) == 0) EL737_errcode = EL737__BAD_LOC;
if (strcmp (rply_ptr0, "?OFL") == 0) EL737_errcode = EL737__BAD_OFL;
if (strcmp (rply_ptr0, "?OV" ) == 0) EL737_errcode = EL737__BAD_OVFL;
if (strcmp (rply_ptr0, "?1" ) == 0) EL737_errcode = EL737__BAD_CMD;
if (strcmp (rply_ptr0, "?2" ) == 0) EL737_errcode = EL737__BAD_BSY;
if (strcmp (rply_ptr0, "?3" ) == 0) EL737_errcode = EL737__BAD_PAR;
if (strncmp (rply_ptr0, "?TMO", 4) == 0) EL737_errcode = EL737__BAD_TMO;
EL737_SetErrcode (info_ptr, rply_ptr0, "S\", \"RS\" or \"RA");
*c1 = *c2 = *c3 = *c4 = *rs = 0; *timer = 0.0;
return False;
}
@ -1408,7 +1672,7 @@
*/
my_status = AsynSrv_SendCmnds (&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host,
"s\r", NULL);
"S\r", NULL);
if (!my_status) {
EL737_errcode = EL737__BAD_ASYNSRV;
return False;
@ -1423,14 +1687,7 @@
EL737_call_depth--;
return True;
}
EL737_errcode = EL737__BAD_ILLG;
if (strcmp (rply_ptr0, "?OF" ) == 0) EL737_errcode = EL737__BAD_LOC;
if (strcmp (rply_ptr0, "?OFL") == 0) EL737_errcode = EL737__BAD_OFL;
if (strcmp (rply_ptr0, "?OV" ) == 0) EL737_errcode = EL737__BAD_OVFL;
if (strcmp (rply_ptr0, "?1" ) == 0) EL737_errcode = EL737__BAD_CMD;
if (strcmp (rply_ptr0, "?2" ) == 0) EL737_errcode = EL737__BAD_BSY;
if (strcmp (rply_ptr0, "?3" ) == 0) EL737_errcode = EL737__BAD_PAR;
if (strncmp (rply_ptr0, "?TMO", 4) == 0) EL737_errcode = EL737__BAD_TMO;
EL737_SetErrcode (info_ptr, rply_ptr0, "S");
return False;
}
}
@ -1446,9 +1703,6 @@
int *c3,
int *c4,
float *timer) {
#ifdef LINUX
#define nanosleep_d9 nanosleep
#endif
#ifdef __VMS
#include <lib$routines.h>
#define hibernate lib$wait (0.25)
@ -1457,7 +1711,7 @@
#include <time.h>
struct timespec delay = {0, 250000000};
struct timespec delay_left;
#define hibernate nanosleep_d9 (&delay, &delay_left)
#define hibernate nanosleep (&delay, &delay_left)
#endif
int my_rs;
struct EL737info *info_ptr;