beautypg.com

4 event capture functions – Sensoray 2410 API User Manual

Page 22

background image

Sensoray 24xx Programming Guide

18

Model 2410 Digital I/O Module

Example:

// Set LED brightness to 1 (dim, but visible).

u32 err = ERR_NONE;

if

( !s2410_SetLedBrightness( sess, &err, 1 ) )

printf( "Error: %s\n", s24xx_ErrorText(err) );

6.4 Event Capture Functions

6.4.1 Overview

The module’s 48 digital inputs are sampled by the module once per millisecond. After passing through debounce filters, the
channels are monitored for state changes. Model 2410 implements an event capture system that enables the module to
automatically record occurrences of debounced state changes.

The application program can access records of captured events by polling the module at convenient times, or by activating an
asynchronous notification system that will callback into the application program whenever an event is captured. Application
programs may employ either polling or callbacks to handle captured events, but both methods should not be used simultaneously.

Several API functions issue a command to the event capture system and return when the module acknowledges receipt of the
command. Since the capture system is a synchronous state machine (SM), all received commands are enqueued and then executed
synchronously in the order they were received at the next SM clock. When asynchronous notification is active, the application’s
callback function will be called when each command is executed so that the application can synchronize to the SM. In polled mode,
however, there is no way to know exactly when a command is executed.

Some of the event capture functions convey boolean flags for the 48 DIO channels through an array of three 16-bit words, with
each bit representing one DIO channel. In such cases, the first word (array index 0) represents channels 0-15 (lsb-msb), the second
word represents channels 16-31, and the third word represents channels 32-47.

6.4.2 s2410_ReadCapFlags()

Function:

Read event capture flags from all DIO channels.

Prototype:

BOOL s2410_ReadCapFlags( SESSION sess, u32 *err, u16 *flags );

Returns:

True if the operation was successful, otherwise False is returned and

err

will contain the associated error code.

Notes:

This function reads, and then immediately clears, the event capture flags from all 48 digital input channels. It can
be used to poll for captured events at convenient times. Alternatively,

s2410_AsyncCapBegin()

may be called to

enable asynchronous event notification and thus make polling unnecessary. As a general rule, an application can
receive notification of captured events either by polling or by means of asynchronous event notification, but these
two methods should not be mixed.

s2410_ReadCapFlags()

should not be called while asynchronous event

notification is active.

Event flags will accumulate until

s2410_ReadCapFlags()

is called. When the function is called, all channels that

experienced events since the previous call will be indicated by logic ones in

flags[]

. All event flags are

synchronously cleared to zero when they are read from the board. If a channel’s event flag is set, and then another
event is detected on that channel before

s2410_ReadCapFlags()

is called, there will be no indication that two

events have occurred on the channel.

Example:

// Poll and display the event capture flags.

u32 err = ERR_NONE;

Argument

Description

sess

Session handle obtained from

s24xx_SessionOpen()

.

err

Pointer to error code. See Section 4.3.1 for details.

flags

Pointer to three-word array that will receive the event flags. Each bit has the following
meaning:

1 - event captured.
0 - no event captured.