CLOCAL and TIOCM_DTR interact with the serial driver in ways which are
less than obvious. The following code should serve your purpose.
--------cut here--------
#include <termio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#define DEV "/dev/ttyS1"
#define bool char
#define not !
#define TRUE (0 == 0)
#define FALSE (not TRUE)
static bool process( ),
complain( char *, ...);
int
main( )
{
return (process( )? 0: 1);
static bool
process( )
{
struct termio t;
int n,
a,
i;
int fd = open( DEV, O_RDWR|O_NONBLOCK);
if (fd < 0)
return (complain( "cannot open %s (%s)", DEV, strerror( errno)));
i = ioctl( fd, TCGETA, &t);
if (i < 0)
return (complain( "TCGETA failed (%s)", strerror( errno)));
t.c_cflag |= CLOCAL;
i = ioctl( fd, TCSETA, &t);
if (i < 0)
return (complain( "TCSETA failed (%s)", strerror( errno)));
for (n=0; n<5; ++n) {
a = TIOCM_RTS | TIOCM_DTR;
i = ioctl( fd, TIOCMBIS, &a);
if (i < 0)
return (complain( "TIOCMBIS failed (%s)", strerror( errno)));
sleep( 1);
a = TIOCM_RTS | TIOCM_DTR;
i = ioctl( fd, TIOCMBIC, &a);
if (i < 0)
return (complain( "TIOCMBIC failed (%s)", strerror( errno)));
sleep( 1);
}
return (TRUE);
static bool
complain( char *mesg, ...)
{
va_list ap;
va_start( ap, mesg);
vfprintf( stderr, mesg, ap);
fprintf( stderr, "\n");
return (FALSE);
--------