Subject: serial port control
To: None <current-users@NetBSD.ORG>
From: Jaromir Dolecek <>
List: current-users
Date: 02/10/1998 16:40:30
I would like to write a small utility to control UPS, connected
through RC232C cabel to serial port (/dev/tty00). Can some kind
soul say what all I must care of ?

I've tried to write a rather simplistic program, but it blocks on 
open(2). I've looked at some sources and tried O_NONBLOCK
option to open. Now the program doesn't block, but I can't write
anything (Input/Ouput error on write(2)). read(2) returns without error,
but doesn't read anything too.

I'm using i386 port, if it matters. The serial port seems to be okay,
mouse works when connected to it. And yes, the cable to UPS _is_
connected ;-b

Any help is greatly appreciated.


P.S. Here is a program:

#include <fcntl.h>
#include <stdio.h>
#include <termios.h>

void main() {
	int i, d = open("/dev/tty00", O_RDWR|O_NONBLOCK);
	char buf[200];
	struct termios tty;

	tcgetattr(d, &tty);
	cfsetspeed(&tty, 1200);
	i = write(d, "vAa?\r", 5);
	printf("written: %d\n", i);
	i = read(d, &buf, 5);
	buf[i] = 0;
	printf("read: len=%d, value=%s\n", i, buf);

the output of it is:
written: -1
read: len=0, value=

Jaromir Dolecek <>
It is better never to have been born.  But who among us has such luck?
One in a million, perhaps.