예제 #1
0
int xf86OpenSerial (pointer options)
{
	APIRET rc;
	HFILE fd, i;
	ULONG action;
	GLINECTL linectl;

	char* dev = xf86FindOptionValue (options, "Device");
	xf86MarkOptionUsedByName (options, "Device");
	if (!dev) {
		xf86Msg (X_ERROR, "xf86OpenSerial: No Device specified.\n");
		return -1;
	}

	rc = DosOpen(dev, &fd, &action, 0, FILE_NORMAL, FILE_OPEN,
		     OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, NULL);
	if (rc) {
		xf86Msg (X_ERROR,
			 "xf86OpenSerial: Cannot open device %s, rc=%d.\n",
			 dev, rc);
		return -1;
	}

	/* check whether it is an async device */
	if (_get_linectrl(fd,&linectl)) {
		xf86Msg (X_WARNING,
			 "xf86OpenSerial: Specified device %s is not a tty\n",
			 dev);
		DosClose(fd);
		return -1;
	}

	/* set up default port parameters */
	_set_baudrate(fd, 9600);

	linectl.databits = 8;
	linectl.parity = 0;
	linectl.stopbits = 0;
	_set_linectl(fd, &linectl);

	if (xf86SetSerial (fd, options) == -1) {
		DosClose(fd);
		return -1;
	}

	return fd;
}
예제 #2
0
int
xf86OpenSerial(XF86OptionPtr options)
{
    struct termios t;
    int fd, i;
    char *dev;

    dev = xf86SetStrOption(options, "Device", NULL);
    if (!dev) {
        xf86Msg(X_ERROR, "xf86OpenSerial: No Device specified.\n");
        return -1;
    }

    fd = xf86CheckIntOption(options, "fd", -1);

    if (fd == -1)
        SYSCALL(fd = open(dev, O_RDWR | O_NONBLOCK));

    if (fd == -1) {
        xf86Msg(X_ERROR,
                "xf86OpenSerial: Cannot open device %s\n\t%s.\n",
                dev, strerror(errno));
        free(dev);
        return -1;
    }

    if (!isatty(fd)) {
        /* Allow non-tty devices to be opened. */
        free(dev);
        return fd;
    }

    /* set up default port parameters */
    SYSCALL(tcgetattr(fd, &t));
    t.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR
                   | IGNCR | ICRNL | IXON);
    t.c_oflag &= ~OPOST;
    t.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
    t.c_cflag &= ~(CSIZE | PARENB);
    t.c_cflag |= CS8 | CLOCAL;

    cfsetispeed(&t, B9600);
    cfsetospeed(&t, B9600);
    t.c_cc[VMIN] = 1;
    t.c_cc[VTIME] = 0;

    SYSCALL(tcsetattr(fd, TCSANOW, &t));

    if (xf86SetSerial(fd, options) == -1) {
        SYSCALL(close(fd));
        free(dev);
        return -1;
    }

    SYSCALL(i = fcntl(fd, F_GETFL, 0));
    if (i == -1) {
        SYSCALL(close(fd));
        free(dev);
        return -1;
    }
    i &= ~O_NONBLOCK;
    SYSCALL(i = fcntl(fd, F_SETFL, i));
    if (i == -1) {
        SYSCALL(close(fd));
        free(dev);
        return -1;
    }
    free(dev);
    return fd;
}