It is currently Wed, 22 Mar 2023 05:21:31 GMT



 
Author Message
 Modem line control redux
Thanks to Dave Platt for pointing me in the right direction for RTS / DTR
control from a user app.  However, I'm still not able to get it to work.
I'm using the following test code (port open code not shown, purloined from
a Ham Radio application):

int arg, q;

arg = TIOCM_RTS | TIOCM_DTR;
while(TRUE) {
    if ( ioctl(fd, q ? TIOCMBIS : TIOCMBIC, &arg) < 0 ) printf("ioctl
Error\n");
   q = !q;
   sleep(1);

But the lines don't wiggle.  I've also used the TIOCMSET function to try to
wiggle them.  I've looked through serial.c (Redhat Linux 6.2 on PC) and
didn't see anything (like a particular open mode) that would prevent the
calls from working.  Anybody have any ideas how to proceed with debugging?

Thanks, Doug



 Wed, 16 Feb 2005 06:48:14 GMT   
 Modem line control redux
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);

--------



 Wed, 16 Feb 2005 14:40:39 GMT   
 
   [ 2 post ] 

Similar Threads

1. RTS/DTR control Redux

2. modem control lines and other serial befuddlements...

3. iijppp and modem control lines

4. iijppp and modem control lines

5. How to control modem line for Hpux

6. Direct modem line control in user app.

7. Enabling Modem control lines for serial I/O

8. Modem control lines


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software