Help using termios

G

goblin

Hi all

I'm struggeling to get my serial port settings changed using termios.
I can change the baud rate fine, but none of the control flags respond
to my changes. As an example:

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

int main (void) {
struct termios settings;
FILE* pPort;

if (!(pPort = fopen("/dev/ttyUSB0","r+"))) {
printf("Oops0\n");
return 1;
}

if (tcgetattr(fileno(pPort), &settings) != 0) printf("Oops1\n");
cfsetispeed(&settings, B9600);
cfsetospeed(&settings, B9600);
settings.c_iflag |= CSTOPB;
if (tcsetattr(fileno(pPort), TCSANOW, &settings) != 0)
printf("Oops2\n");

fclose(pPort);
}

This will change the current baud rate to the selected 9600, but the
will not set two stop bits as I think it should. What am I doing wrong
here?

Any help would be sincerely appreciated.

Piet
 
A

Antoninus Twink

I'm struggeling to get my serial port settings changed using termios.
I can change the baud rate fine, but none of the control flags respond
to my changes. [snip]
settings.c_iflag |= CSTOPB;

You mean settings.c_cflag (control settings, not input).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top