serial comm problems

Hello,

I’m trying to communicate with a serial device with RTP 6.1.

I’ve written the code below to set up the comm port. I try to run the
program and it doesn’t work.

Then, from the command line, I issue the stty command as follows:

stty +ixon +ixoff baud=9600 bits=7 stopb=1 par=even </dev/ser1

Now, I run the program and everything works perfectly.

So, obviously, the stty command must be setting some flags that I’m not
setting manually in the code.

Can anyone tell me what flags the stty command is setting that I am not?

Thanks much in advance.

-Dan


OrionFd = open("/dev/ser1", O_RDWR | O_NONBLOCK);
if (OrionFd == -1) {
printf(“error opening port\n”);
return -1;
}

// get control structure
tcgetattr(OrionFd, &termios_p);

// set I/O baud rate
cfsetispeed(&termios_p, 9600);
cfsetospeed(&termios_p, 9600);

// set I/O flags
termios_p.c_cflag |= CS7|PARENB; // 7, even, 1
termios_p.c_iflag |= IXON|IXOFF;

// apply these settings immediately
if ((tcsetattr(OrionFd, TCSANOW, &termios_p)) == -1 ) {
printf(“error setting port parameters\n”);
close(OrionFd);
return -1;
}

dan helmick <danielhelmick@earthlink.net> wrote:

Hello,

I’m trying to communicate with a serial device with RTP 6.1.

I’ve written the code below to set up the comm port. I try to run the
program and it doesn’t work.

Then, from the command line, I issue the stty command as follows:

stty +ixon +ixoff baud=9600 bits=7 stopb=1 par=even </dev/ser1

Now, I run the program and everything works perfectly.

So, obviously, the stty command must be setting some flags that I’m not
setting manually in the code.

Can anyone tell me what flags the stty command is setting that I am not?

Thanks much in advance.

-Dan

Hi Dan,

You can use stty -a </dev/ser1 to display all the settings. What you could do
is run your program then check the ser1 settings and compare them to the settings
after using stty from the command line. Hope this helps.


Barry


OrionFd = open("/dev/ser1", O_RDWR | O_NONBLOCK);
if (OrionFd == -1) {
printf(“error opening port\n”);
return -1;
}

// get control structure
tcgetattr(OrionFd, &termios_p);

// set I/O baud rate
cfsetispeed(&termios_p, 9600);
cfsetospeed(&termios_p, 9600);

// set I/O flags
termios_p.c_cflag |= CS7|PARENB; // 7, even, 1
termios_p.c_iflag |= IXON|IXOFF;

// apply these settings immediately
if ((tcsetattr(OrionFd, TCSANOW, &termios_p)) == -1 ) {
printf(“error setting port parameters\n”);
close(OrionFd);
return -1;
}

Either I’m doing something fundamentally wrong or you guys are gonna be
interested in this.

I do a: stty -a </dev/ser1 and get (on the last line):

par=none +inpck bits=8 stopb=1 baud=57600 rows=0,0

I run the following program:


int main()
{
int OrionFd;
struct termios termios_p;

OrionFd = open("/dev/ser1", O_RDWR);
if (OrionFd == -1) {
printf(“error opening port\n”);
return -1;
}

// get control structure
tcgetattr(OrionFd, &termios_p);

termios_p.c_cflag |= CS7;

// apply these settings immediately
if ((tcsetattr(OrionFd, TCSANOW, &termios_p)) == -1 ) {
printf(“error setting port parameters\n”);
close(OrionFd);
return -1;
}
}


I do a: stty -a </dev/ser1 again and get (on the last line, again)
(notice the number of bits is still 8 instead of the expected 7):

par=none +inpck bits=8 stopb=1 baud=57600 rows=0,0


Any ideas?

Thanks,
Dan







“Operating System for Tech Supp” <os@qnx.com> wrote in message
news:9p9sge$q48$2@nntp.qnx.com

dan helmick <> danielhelmick@earthlink.net> > wrote:
Hello,

I’m trying to communicate with a serial device with RTP 6.1.

I’ve written the code below to set up the comm port. I try to run the
program and it doesn’t work.

Then, from the command line, I issue the stty command as follows:

stty +ixon +ixoff baud=9600 bits=7 stopb=1 par=even </dev/ser1

Now, I run the program and everything works perfectly.

So, obviously, the stty command must be setting some flags that I’m not
setting manually in the code.

Can anyone tell me what flags the stty command is setting that I am not?

Thanks much in advance.

-Dan


Hi Dan,

You can use stty -a </dev/ser1 to display all the settings. What you could
do
is run your program then check the ser1 settings and compare them to the
settings
after using stty from the command line. Hope this helps.


Barry


OrionFd = open("/dev/ser1", O_RDWR | O_NONBLOCK);
if (OrionFd == -1) {
printf(“error opening port\n”);
return -1;
}

// get control structure
tcgetattr(OrionFd, &termios_p);

// set I/O baud rate
cfsetispeed(&termios_p, 9600);
cfsetospeed(&termios_p, 9600);

// set I/O flags
termios_p.c_cflag |= CS7|PARENB; // 7, even, 1
termios_p.c_iflag |= IXON|IXOFF;

// apply these settings immediately
if ((tcsetattr(OrionFd, TCSANOW, &termios_p)) == -1 ) {
printf(“error setting port parameters\n”);
close(OrionFd);
return -1;
}

i might be wrong, but i think terminal settings are reset
after close().

–martijn

Dan Helmick <danielhelmick@earthlink.net> wrote:

Either I’m doing something fundamentally wrong or you guys are gonna be
interested in this.

The first one. :wink:

termios_p.c_cflag |= CS7;

Try this instead:

termios_p.c_cflag = termios_p.c_cflag & ~CSIZE | CS7;


Wojtek Lerch QNX Software Systems Ltd.

Thanks Wojtek! That worked… it makes sense that you have to clear those
bits before setting them again.

-Dan


“Wojtek Lerch” <wojtek_l@yahoo.ca> wrote in message
news:9pcho7$hji$1@nntp.qnx.com

Dan Helmick <> danielhelmick@earthlink.net> > wrote:
Either I’m doing something fundamentally wrong or you guys are gonna be
interested in this.

The first one. > :wink:

termios_p.c_cflag |= CS7;

Try this instead:

termios_p.c_cflag = termios_p.c_cflag & ~CSIZE | CS7;


Wojtek Lerch QNX Software Systems Ltd.