Moxa W406-T-LX [64/74] Example 2

Moxa W406-T-CE [64/74] Example 2
W315A/325A Linux User's Manual Programmer's Guide
6-5
exit(1);
}
swtd_enable(fd, 5000); // enable it and set it 5 seconds
while ( 1 ) {
// do user application want to do
.....
.....
swtd_ack(fd);
.....
.....
}
swtd_close(fd);
exit(0);
}
The makefile is shown below:
all:
arm-linux-gcc –o xxxx xxxx.c –lmoxalib
Example 2:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <moxadevice.h>
static void mydelay(unsigned long msec)
{
struct timeval time;
time.tv_sec = msec / 1000;
time.tv_usec = (msec % 1000) * 1000;
select(1, NULL, NULL, NULL, &time);
}
static int swtdfd;
static int stopflag=0;
static void stop_swatchdog()
{
stopflag = 1;
}
static void do_swatchdog(void)
{
swtd_enable(swtdfd, 500);
while ( stopflag == 0 ) {
mydelay(250);
swtd_ack(swtdfd);
}
swtd_disable(swtdfd);
}
int main(int argc, char *argv[])
{
pid_t sonpid;
signal(SIGUSR1, stop_swatchdog);
swtdfd = swtd_open();

Содержание

Скачать