The function dscGetStatus() is used to indicate the current status of any interrupt operation, including A/D sampling, D/A conversions, digital input, digital output, and user interrupts. It provides several status indicators (see the definition for the data structure DSCS on page 167 for complete details):
The common convention for using this function is to start a particular interrupt function, and then go into a while loop that terminates when a specified condition has occurred, such as when a specified timeout has been reached or when the interrupt operation completes. Completion is indicated by the status indicator OP_TYPE_NONE.
Create and initialize a driver status structure (DSCS). Call dscGetStatus() and pass it a pointer to this structure in order to return the current interrupt operation status. The two important elements to note in the DSCS structure are op_type and transfers. After calling dscGetStatus(), these elements will contain the interrupt operation status and current number of transfers respectively.
NOTE: If the interrupt operation is in recycle mode, then anytime the number of transfers reaches the maximum number of transfers specified (buffer size), the current number of transfers indicator (buffer pointer) will be reset to 0. In this case there is no total transfers counter. Instead, you must keep track of the total no. of I/O transfers yourself by counting how many times the buffer pointer has been reset. For more information regarding the various modes of interrupt operations, please refer to the chapter on interrupt-based operations on page 27.
#include <sys/timeb.h> /* run the interrupt operation for 30 seconds, then cancel */ #define TIMEOUT_SEC 30 DSCS dscs; struct timeb time_before; struct timeb time_after; /* Start interrupt function - dscADSampleInt() etc. */ /* Step 1 */ dscs.transfers = 0; dscs.op_type = OP_TYPE_INT; /* Step 2 */ ftime(&time_before); while (dscs.op_type != OP_TYPE_NONE) { ftime(&time_after); if ((time_after.time - time_before.time) > TIMEOUT_SEC) { dscCancelOp(dscb); break; } if ((result = dscGetStatus(dscb, &dscs)) != DE_NONE) return result; }
NOTE: On DOS and Linux platforms, the function, ftime(), and the structure, timeb, are used as shown above. On Windows 9x/NT/2000 platforms, these symbols are defined as _ftime() and _timeb respectively.
This page was last modified 14:56, 12 Feb 2004.
Copyright (c) 2004 Diamond Systems. All Rights Reserved.