Moxa V2426A-C7 [28/88] Implementing timer functions on digital io ports

Moxa V2426A-C2 [28/88] Implementing timer functions on digital io ports
V2400A Series Expansion Modules Software Installation and Programming Guide
4-8
The following example illustrates the use of the initialization function for registering a callback event:
mngr = digit_io_timer_init();
if (digit_io_timer_add_callback (mngr, HWIndex, port, DGTIO_GET_INPUT_STATE_CHANGE,
interval, input_chg_cb, &port) < 0) {
}
if (digit_io_timer_add_callback (mngr, HWIndex, port, DGTIO_GET_INPUT, interval,
input_get_cb, &port) < 0) {
}
if (di
git_io_timer_add_callback (mngr, HWIndex, port, DGTIO_SET_OUTPUT, interval,
output_set_cb, &port) < 0) {
}
if (digit_io_timer_add_callback (mngr, HWIndex, port, DGTIO_GET_OUTPUT, interval,
output_get_cb, &port) < 0) {
}
digit_io_timer_dispatch(mngr);
Implementing Timer Functions on Digital IO Ports
The examples in this section show how to implement timer functions on Digital IO ports. The first example has
two parts.
Example 1-1: (Routines to Operate Timer Function on a Digital IO
Port.)
Folder and file: /examples/ExpansionCard/LX/EPM3438/digit_input_change/digit_io_timer.c
#include <stdio.h>
#include <stdlib.h>
#if !defined(_WIN32_WCE) && !defined(WIN32)
#include <time.h>
#endif
#include "digit_io_timer.h"
/* callback function */
static void
dgio_input_change_exec(DGIOMNGR *mngr, DGIOITEM *item)
{
int sig;
HANDLE fd=mngr->fd[item->HWIndex];
switch(item->mode)
{
case DGTIO_GET_INPUT:
sig = mxdgio_get_input_signal(fd, item->port);
item->cb(item->HWIndex, item->port, sig, item->arg);
break;
case DGTIO_GET_OUTPUT:
sig = mxdgio_get_output_signal(fd, item->port);

Содержание

Скачать