[SunHELP] URGENT: TTL pulse on serial or parallel port

James Lockwood sunhelp at sunhelp.org
Fri Apr 20 01:44:59 CDT 2001


On Thu, 19 Apr 2001, Wolfgang Engelien wrote:

> Sounds good, but how do I do that?

A simple example of how to toggle RTS:

#include <fcntl.h>
#include <sys/termios.h>

#define OUTPUT_PORT "/dev/cua/a"

main()
{
    int fd, x;
    fd = open(OUTPUT_PORT, O_RDWR);

    x = TIOCM_RTS; /* enable RTS */
    ioctl(fd, TIOCMSET, &x);
    x = 0x0000; /* disable RTS */
    ioctl(fd, TIOCMSET, &x);

    close(fd);
}

You can use TIOCM_DTR to toggle DTR, but there appears to be an enforced
delay in the serial driver associated with this.

Naturally if you need more complex IO you would be better suited using
actual serial or parallel port data lines, but flipping RTS will give you
one bit of output with a minimum of effort.

-James




More information about the SunHELP mailing list