Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcdc!hpfcmgw!rdg From: rdg@hpfcmgw.HP.COM (Rob Gardner) Newsgroups: comp.sys.hp Subject: Re: Need help setting up RS-232 port Message-ID: <1080055@hpfcmgw.HP.COM> Date: 5 Jun 89 21:07:43 GMT References: <8490001@weycord.WEYCO.COM> Organization: HP Fort Collins, CO Lines: 57 > The following should do what you need . Hope it helps . > > /* open device as read / write see mknod to make /dev/tty */ > /* mknod /dev/tty c 1 0xscpp04 */ > > if((tty = open("/dev/tty",O_RDWR)) < 1){ > fprintf(stderr,"Could not open /dev/tty ERRNO: %d\n",errno); Whoa. Stop. Hold it right there. Don't do any mknod's like this on /dev/tty or you will suffer very strange system behavior. Call the device something like /dev/tty02. (/dev/tty is a special device, not a serial port.) > term.c_oflag = OPOST; You don't need OPOST if there are no other oflag bits set. > term.c_iflag = IGNBRK; > term.c_lflag = 0; > term.c_cflag = B2400|CSIZE|CS8|CREAD|CLOCAL; CSIZE is a mask used to find out what the character size is, so you don't need it here. Since you created the tty device with "direct connect" mode (that digit 4 at the end of the minor number), CLOCAL will have no effect. See modem(7) for a very detailed description of this bit. I would also recommend setting term.c_cc[VMIN] to 1 if you want to be able to read 1 character at a time, otherwise you get whatever junk happens to be in an uninitialized variable. (And this will be the minimum number of characters that have to be read before the read() call completes.) > /* get BUFFER_SIZE bytes in character(byte) buffer */ > read(tty,buffer,BUFFER_SIZE); > /* write buffer to device */ > write(tty,buffer,BUFFER_SIZE); I would check the return value from the read() call, and use it in the write call: ret = read(tty, buffer, BUFFER_SIZE); if (ret > 0) if (write(tty, buffer, ret) != ret) perror("...."); etc, etc. The reason is that in 'raw' mode (ie, ICANON is not set), the read may complete before BUFFER_SIZE characters are read. Rob Gardner hplabs!hpfcmr!rdg Hewlett Packard or rdg%hpfcmr@hplabs.hp.com Fort Collins, Colorado 303-229-2048 80525-9599 "Ask me about Home Brewing"