*BSD News Article 23332


Return to BSD News archive

Xref: sserve comp.unix.bsd:12874 comp.unix.programmer:12912 comp.unix.questions:41390
Newsgroups: comp.unix.bsd,comp.unix.programmer,comp.unix.questions,bln.comp.unix,bln.comp.sun
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!elroy.jpl.nasa.gov!swrinde!cs.utexas.edu!uunet!Germany.EU.net!scotty!wegy!chris
From: chris@wegy.waldorf-gmbh.de (Chris J. Mercer)
Subject: Need 8 bit on the serial port (not only 7).
Nntp-Posting-Host: wegy
Keywords: BSD SERIAL PORT 8 BIT
Sender: chris@wegy (Chris J. Mercer)
Organization: Waldorf Electronics GmbH, Germany
Date: Fri, 5 Nov 1993 10:09:55 GMT
Message-ID: <1993Nov5.100955.15346@scotty.waldorf-gmbh.de>
Lines: 122

I am writing a program on a MIPS Magnum, that I want to
publish with the GPL-license.

Luckily the MIPS allows you to choose between System V and BSD 4.3 .
Unluckily the program does not work properly when I set the BSD-option.

The only problem I have, is that the serial port only returns 7 bit and I
need all 8 bit.

The following program opens a tty and sets the sg_flags to raw as
well as the local mode to LPASS8.

I know that 8 bit are passed properly when  writing to the port,
and that the highest bit is stripped when reading.

Does anyone have an idea what's wrong ? Could you test this program ?
(It should compile like that, its only 90 lines.)

If you should answer, please do it via e-mail, as we do
not subscribe to these newsgroups.

The test-program:

----------------------- snip here --------------------
#include <stdio.h>
#include <sgtty.h>

#include <fcntl.h>

static fd_set rdfdset;
static int ttyfd;
static struct sgttyb mysgttyb;
				/* no control characters */
static struct tchars mytchars = {-1,-1,-1,-1,-1,-1};


#ifndef TTY_SERIAL
#define TTY_SERIAL "/dev/tty1"
#endif


main () {
  int i, err;

  ttyfd=open(TTY_SERIAL,O_RDWR,0); /* open serial interface device */
  if(ttyfd < 0)
    {
      fprintf(stderr,"initio() : Could not open %s\n", TTY_SERIAL);
      exit (ttyfd);
    }
  
  mysgttyb.sg_ispeed = B9600;
  mysgttyb.sg_ospeed = B9600;
  mysgttyb.sg_erase  = 0xFF;	/* hope this disables erase */
  mysgttyb.sg_kill   = 0xFF;	/* hope this disables kill */
  mysgttyb.sg_flags  = (RAW);
  err = ioctl(ttyfd,TIOCSETP,&mysgttyb);
  if(err < 0)
    {
      perror("ioctl(ttyfd,TIOCGETP,&mysgttyb) :");
      return err;
    }

  err = ioctl(ttyfd,TIOCSETC,&mytchars);
  if(err < 0)
    {
      perror("ioctl(ttyfd,TIOCSETC,&mytchars) :");
      return err;
    }
  err = ioctl(ttyfd,TIOCSLTC,&mytchars);
  if(err < 0)
    {
      perror("ioctl(ttyfd,TIOCSLTC,&mytchars) :");
      return err;
    }
  i = (LPASS8);
  err = ioctl(ttyfd,TIOCLSET,&i);
  if(err < 0)
    {
      perror("ioctl(ttyfd,TIOCLSET,&i) :");
      return err;
    }
				/* simulate input. 
                                                                                    only works if you
                                                                                    are root.  Anyone
                                                                                    know why ??? */
  {
    char c=0xFD;
    printf ("ioctl=%d\n", ioctl(ttyfd, TIOCSTI, &c));
  }

  readSerial();
}

int readSerial () {
  unsigned char buf[512];
  int i, nbytes;

    FD_ZERO(&rdfdset);
    FD_SET(ttyfd,&rdfdset);
    select(10,&rdfdset,0,0,0);
    if(FD_ISSET(ttyfd,&rdfdset)) {
      nbytes=read(ttyfd,buf,512);
      if(nbytes < 0) {
	perror("tty read error");
	exit(1);
      }

      for (i=0; i<nbytes; ++i)
	printf ("readSerial():%d,%2X\n", i, buf[i]&255);
    }
}
--------------------- snip here again ------------------

Many Thanks in advance

If you should answer, please do it via e-mail, as we do
not subscribe to these newsgroups.

Chris J. Mercer

chris@waldorf-gmbh.de