Subject: Re: uplcom(4) problem [Re: CVS commit: src/sys/dev/usb]
To: Lubomir Sedlacik <salo@Xtrmntr.org>
From: Martin Husemann <martin@duskware.de>
List: tech-kern
Date: 09/25/2005 12:48:29
--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sun, Sep 25, 2005 at 08:14:52AM +0200, Lubomir Sedlacik wrote:
> i haven't tested the adapter with anything else (e.g., serial console).

Do you have a serial line tester? If so, could you use the attached program
to check that first RTS, then DTR blinks?

Martin


--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="sertest.c"

/*
 * Small serial line test program, for use with a serial line tester.
 * Called like sertest /dev/tty00, it "blinks" RTS twice, then DTR.
 */
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ttycom.h>

static void usage(void);
static void menu(int serial);
static void test(int serial, int flags);

int
main(int argc, char **argv) 
{
	int ser;

	if (argc != 2)
		usage();

	ser = open(argv[1], O_RDWR|O_EXLOCK|O_NONBLOCK, 0);
	if (ser == -1) {
		perror(argv[1]);
		return 1;
	}

	menu(ser);

	close(ser);
	return 0;
}

static void
usage()
{
	fprintf(stderr, 
	    "usage: %s (serial device)\n", getprogname());
	exit(1);
}

static void 
menu(int serial)
{
	int x;

	if (ioctl(serial, TIOCMGET, &x) == -1) {
		perror("ioctl(TIOCMGET)");
		return;
	}

	x |= TIOCM_RTS; test(serial, x);
	x &= ~TIOCM_RTS; test(serial, x);
	x |= TIOCM_RTS; test(serial, x);
	x &= ~TIOCM_RTS; x |= TIOCM_DTR; test(serial, x);
	x &= ~TIOCM_DTR; test(serial, x);
	x |= TIOCM_DTR; test(serial, x);
	x &= ~TIOCM_DTR; test(serial, x);
}

static void
test(int serial, int flags)
{
	if (ioctl(serial, TIOCMSET, &flags) == -1) {
		perror("ioctl(TIOCMSET)");
		exit(1);
	}
	sleep(2);
}

--wRRV7LY7NUeQGEoC--