User`s manual

UC-8410/8416/8418/8430 Programmer's Guide
5-8
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();
if ( swtdfd < 0 ) {
printf(“Open sWatchDog device fail !\n”);
exit(1);
}
if ( (sonpid=fork()) == 0 )
do_swatchdog();
// do user application main function
…..
…..
…..
// end user application
kill(sonpid, SIGUSR1);
swtd_close(swtdfd);
exit(1);
}
The makefile is shown below:
all:
xscale-linux-gcc –o xxxx xxxx.c –lmoxalib
Digital I/O
Digital Output channels can be set to high or low. The channels are controlled by the function call
set_dout_state( ). The Digital Input channels can be used to detect the state change of the digital input
signal. The DI channels can also be used to detect whether or not the state of a digital signal changes during
a fixed period of time. This can be done with the function call set_din_event( ). Moxa provides 5 function calls
to handle digital I/O state changes and event handling.
Application Programming Interface
Return error code definitions:
#define DIO_ERROR_PORT -1 // no such port
#define DIO_ERROR_MODE -2 // no such mode or state
#define DIO_ERROR_CONTROL -3 // open or ioctl fail