From: lupe@ukw.uucp (Lupe Christoph)
Newsgroups: comp.sys.sun.hardware
Subject: Re: Controlling DTR and CTS
Date: 26 Sep 92 13:35:02 GMT
Organization: cic

tal@Warren.MENTORG.COM (Tom Limoncelli) writes:

>To control a little device I have, I need to be able to read the state
>of a pin on the serial port, and set the state of another pin.  I
>figure that CTS and DTR are good choices.

>So, my question is, on a SPARC 1, how does one read DTR and set CTS?
>(or any two pins are fine.)

>(and if I've reversing DTR and CTS's readability and setability
>please reply by mail, I don't want to flood the net with corrections.)

You did, and I would advise to use RTS and CTS for this purpose.
Here is an example that reads CTS and sets/resets RTS:

int
get_CTS(fd)
    int fd;
{
    int line_state;

    ioctl(fd, TIOCMGET, &line_state);
    return (line_state & TIOCM_CTS) != 0;
}

void
set_RTS(fd, on)
    int fd;
    int on;
{
    int line_state = TIOCM_RTS;

    ioctl(fd, on ? TIOCMBIS : TIOCMBIC, &line_state);
}

NOTE: This code has not been tested, and it does not check for errors!


As background info, here is an extract from "man termio":

  Modem Lines
     On special files representing serial ports, the  modem  con-
     trol  lines  supported  by  the hardware can be read and the
     modem status lines supported by the hardware can be changed.
     The  following  modem  control  and status lines may be sup-
     ported by a device; they are defined by <sys/termios.h>:

          TIOCM_LE   0001       line enable
          TIOCM_DTR  0002       data terminal ready
          TIOCM_RTS  0004       request to send
          TIOCM_ST   0010       secondary transmit

          TIOCM_SR   0020       secondary receive
          TIOCM_CTS  0040       clear to send
          TIOCM_CAR  0100       carrier detect
          TIOCM_RNG  0200       ring
          TIOCM_DSR  0400       data set ready

     TIOCM_CD is a synonym  for  TIOCM_CAR,  and  TIOCM_RI  is  a
     synonym for TIOCM_RNG.

     Not all of these will necessarily be supported by  any  par-
     ticular  device;  check  the  manual  page for the device in
     question.

...

     TIOCMGET          The argument is a pointer to an int.   The
                       current state of the modem status lines is
                       fetched and stored in the int  pointed  to
                       by  the  argument.   This  call is allowed
                       from a background process.

     TIOCMBIS          The argument is a pointer to an int  whose
                       value  is  a mask containing modem control
                       lines to be turned on.  The control  lines
                       whose  bits  are  set  in the argument are
                       turned on;  no  other  control  lines  are
                       affected.

     TIOCMBIC          The argument is a pointer to an int  whose
                       value  is  a mask containing modem control
                       lines to be turned off.  The control lines
                       whose  bits  are  set  in the argument are
                       turned off; no  other  control  lines  are
                       affected.

     TIOCMSET          The argument is a pointer to an  int  con-
                       taining  a new set of modem control lines.
                       The modem control lines are turned  on  or
                       off, depending on whether the bit for that
                       mode is set or clear.


-- 
| ...!unido!ukw!lupe  (German EUNet, "bang")     |  Disclaimer:            |
| lupe@ukw.UUCP       (German EUNet, domain)     |  As I am self-employed, |
| suninfo!alanya!lupe (Sun Germany)              |  this *is* the opinion  |
| Res non sunt complicanda praeter necessitatem. |  of my employer.        |
Newsgroups: comp.sys.sun.hardware