Spectrum Brands MC.31XX 用户手册

下载
页码 102
Standard acquisition modes
Programming
(c) Spectrum GmbH
49
Status register
The following shortened excerpt of a sample program gives you an example of how to start the board in classic mode and how to poll for 
the SPC_READY flag. It is assumed that all board setup has been done before.
Starting with interrupt driven mode
In contrast to the classic mode, the interrupt mode has no need for polling for the board’s status. Starting your board in the interrupt driven 
mode does in the main not differ from the classic mode. But there has to be done some additional programming to prevent the program from 
hanging. The SPC_STARTANDWAIT command doesn’t return until the board has stopped. Big advantage of this mode is that it doesn’t waste 
any CPU time for polling. The driver is just waiting for an interrupt and the System has full CPU time for other jobs. To benefit from this mode 
it is necessary to set up a program with at least two different tasks: One for starting the board and to be blocked waiting for an interrupt. The 
other one to make any kind of calculations or display activities.
Command register
If the board is started in the interrupt mode  the task calling the start function will not return until the board 
has finished. If no trigger event is found or the external clock is not present, this function will wait until the 
program is terminated from the taskmanager (Windows) or from another console (Linux).
To prevent the program from this deadlock, a second task must be used which can send the SPC_STOP signal to stop the board. Another 
possibility, that does not require the need of a second task is to define a timeout value.
This is the easiest and safest way to use the interrupt driven mode. If the board started in the interrupts mode it definitely will not return until 
either the recording has finished or the timeout time has expired. In that case the function will return with an error code. See the appendix 
for details.
The following excerpt of a sample program gives you an example of how to start the board in the interrupt driven mode. It is assumed that 
all board setup has been done before.
An example on how to get a second task that can do some monitoring on the running task and eventually send the SPC_STOP command can 
be found on the Spectrum driver CD that has been shipped with your board. The latest examples can also be down loaded via our website 
at http://www.spectrum-instrumentation.com.
Register
Value
Direction
Description
SPC_STATUS
10
r
Status register, of the board.
SPC_RUN
0
Indicates that the board has been started and is waiting for a triggerevent.
SPC_TRIGGER
10
Indicates that the board is running and a triggerevent has been detected.
SPC_READY
20
Indicates, that the board has stopped.
// ----- start the board -----
nErr = SpcSetParam (hDrv, SPC_COMMAND,      SPC_START);
// Here you can check for driver errors as mentioned in the relating chapter
// ----- Wait for Status Ready (polling for SPC_READY in a loop) -----
do
    {
    SpcGetParam (hDrv, SPC_STATUS, &lStatus);      
    }
while (lStatus != SPC_READY);
printf ("Board has stopped\n");
Register
Value
Direction
Description
SPC_COMMAND
0
r/w
Command register, of the board.
SPC_STARTANDWAIT
11
Starts the board with the current register settings in the interrupt driven mode.
SPC_STOP
20
Stops the board manually.
Register
Value
Direction
Description
SPC_TIMEOUT
295130
r/w
Defines a time in ms after which the function SPC_STARTANDWAIT terminates itself.
SpcSetParam (hDrv, SPC_TIMEOUT, 1000);                     // Define the timeout to 1000 ms = 1 second
nErr = SpcSetParam (hDrv, SPC_COMMAND, SPC_STARTANDWAIT);  // Starts the board in the interrupt driven mode
if (nErr == ERR_TIMEOUT)                                   // Checks for the timeout
    printf ("No trigger found. Timeout has expired.\n");