[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

C Programming problem (termios)

  I am writing a C program to interface with a Weather Station
connected to /dev/ttyS2.  I has the program working, to a point, with
kernel 2.2.3 on slink. I was using the following post initialization:

void SetBaudCOM(int new_baud)
        int baudrate;

                case 0x00:      baudrate = B9600;
                case 0x02:      baudrate = B19200;
                case 0x04:      baudrate = B57600;
                case 0x06:      baudrate = B115200;
        bzero(&newtio, sizeof(newtio));
        newtio.c_cflag = baudrate | CS8 | CLOCAL | CREAD;
        newtio.c_iflag = IGNPAR;
        newtio.c_oflag = 0;
		newtio.c_lflag = 0;
        newtio.c_cc[VMIN] = 6;
        newtio.c_cc[VTIME] = 25;
        tcflush(fd, TCIFLUSH);
        tcsetattr(fd, TCSANOW, &newtio);

  The VMIN & VTIME seemed wierd but the program was communicating with
the Weather Station and reading all the sensors. I had left it while I
was working out the user interface and decided to upgrade to kernel
2.2.5.  After the upgrade the program no longer worked.  I then went
tru the process of finding out what required changing and finally got
it working with the following items changed.  BUT, it only works if I
strace it.  Running it without strace, it fails when reading in data
from the WS.

	newtio.c_cflag &= ~CRTSCTS;
    newtio.c_iflag &= ~(IXON | IXOFF | IXANY);
    newtio.c_lflag &=~ICANON;
    newtio.c_lflag &= ~(ECHO | ECHOCTL | ECHONL);
    newtio.c_lflag |= HUPCL;
    newtio.c_cc[VMIN] = 0;
    newtio.c_cc[VTIME] = 25;

  I then put the source on a Hamm, Potato (not current) and a
Slackeare dist, all on the same box.  The program dosn't run on any of
them, even with strace.  They all fail whine trying to read in the
data from the Weather Station.

Question.  Has termios changed form 2.0.35 to 2.2.3 -> 2.2.5?
Slackware is running 2.2.3, hamm is on 2.0.36 and Potato 2.0.35.
Hamm & Potato required changes due to ncurses changes.

As this is my first attempt at a C program on Linux I would appreciate
any pointers to what I 'must' be missing.  I have the (ugh) Win95 and DOS
versions running fine so I don't think there is a problem with ttyS2.

Anny pointers would be appreciated.

TIA  Wayne

Linux - for those that deserve the Very Best!
Wayne T. Topa <wtopa@ix.netcom.com>

Reply to: