Thread View: comp.unix.bsd
1 messages
1 total messages
Started by Chris J. Mercer
Fri, 05 Nov 1993 10:09
Need 8 bit on the serial port (not only 7).
Author: Chris J. Mercer
Date: Fri, 05 Nov 1993 10:09
Date: Fri, 05 Nov 1993 10:09
122 lines
4281 bytes
4281 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads