RTP 6.0 with patch A. - read instruction on /dev/ser4 block

RTP 6.0 with patch A.
The read instruction on /dev/ser4 block until CTRL-J is sent or more then
195 characters are sent.

Do I miss something ? Experts please advise.

Janusz.



------------ Test program ---------------------

#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <string.h>

#define SERIAL4 “/dev/ser4”

int fd;
struct termios termios_p;


main()
{
int result;
fd = open(SERIAL4, O_RDWR | O_NOCTTY );

unsigned char buff[5]={32,32,32,32,32};

if (fd == -1 ) {

printf(“Could not open %s \n”, SERIAL4);
printf(“This means %s\n”, strerror( errno));
exit (1);
}

tcgetattr(fd, &termios_p);
cfmakeraw(&termios_p);

cfsetispeed(&termios_p, B9600);
cfsetospeed(&termios_p, B9600);

termios_p.c_cflag &= ~CSIZE;
termios_p.c_cflag &= ~PARENB;
termios_p.c_iflag &= ~INPCK;

// termios_p.c_cflag |= CREAD | CS7 | PARENB; // 7,1,even
// termios_p.c_iflag |= INPCK;

termios_p.c_cflag |= CREAD | CS8 ; // 8,n,1

termios_p.c_oflag = 0;
termios_p.c_lflag = 0xa00;
tcsetattr(fd, TCSANOW, &termios_p);

while ( 1 )
{

result = read(fd, buff, 1);
if (result == -1 )
{
printf(“Can not read %s\n”, strerror( errno));
}
else
{
printf("%d %c ",(int)buff[0], buff[0]);
}
}

}

Janusz <ruszelj@baxter.com> wrote:

RTP 6.0 with patch A.
The read instruction on /dev/ser4 block until CTRL-J is sent or more then
195 characters are sent.

Do I miss something ? Experts please advise.

Might be a canonical vs non-canonical mode issued. (edited vs raw
mode). Have you tried turning off I_CANON flag in termios.c_lflag?

Otherwise, I think the terminal does line-editing stuff, or at least
expects to, and won’t deliver data until a “line” is complete –
CTRL-J (linefeed) is a line completion character.

Not sure this is it… but seems likely.

-David

Janusz.



------------ Test program ---------------------

#include <stdio.h
#include <fcntl.h
#include <termios.h
#include <errno.h
#include <string.h

#define SERIAL4 “/dev/ser4”

int fd;
struct termios termios_p;



main()
{
int result;
fd = open(SERIAL4, O_RDWR | O_NOCTTY );

unsigned char buff[5]={32,32,32,32,32};

if (fd == -1 ) {

printf(“Could not open %s \n”, SERIAL4);
printf(“This means %s\n”, strerror( errno));
exit (1);
}

tcgetattr(fd, &termios_p);
cfmakeraw(&termios_p);

cfsetispeed(&termios_p, B9600);
cfsetospeed(&termios_p, B9600);

termios_p.c_cflag &= ~CSIZE;
termios_p.c_cflag &= ~PARENB;
termios_p.c_iflag &= ~INPCK;

// termios_p.c_cflag |= CREAD | CS7 | PARENB; // 7,1,even
// termios_p.c_iflag |= INPCK;

termios_p.c_cflag |= CREAD | CS8 ; // 8,n,1

termios_p.c_oflag = 0;
termios_p.c_lflag = 0xa00;
tcsetattr(fd, TCSANOW, &termios_p);

while ( 1 )
{

result = read(fd, buff, 1);
if (result == -1 )
{
printf(“Can not read %s\n”, strerror( errno));
}
else
{
printf("%d %c ",(int)buff[0], buff[0]);
}
}

}


QNX Training Services
I do not answer technical questions by email.

I have tried and still no luck.
Janusz.
“David Gibbs” <dagibbs@qnx.com> wrote in message
news:9r9atf$nji$1@nntp.qnx.com
Janusz <ruszelj@baxter.com> wrote:

RTP 6.0 with patch A.
The read instruction on /dev/ser4 block until CTRL-J is sent or more then
195 characters are sent.

Do I miss something ? Experts please advise.

Might be a canonical vs non-canonical mode issued. (edited vs raw
mode). Have you tried turning off I_CANON flag in termios.c_lflag?

Otherwise, I think the terminal does line-editing stuff, or at least
expects to, and won’t deliver data until a “line” is complete –
CTRL-J (linefeed) is a line completion character.

Not sure this is it… but seems likely.

-David

Janusz.



------------ Test program ---------------------

#include <stdio.h
#include <fcntl.h
#include <termios.h
#include <errno.h
#include <string.h

#define SERIAL4 “/dev/ser4”

int fd;
struct termios termios_p;



main()
{
int result;
fd = open(SERIAL4, O_RDWR | O_NOCTTY );

unsigned char buff[5]={32,32,32,32,32};

if (fd == -1 ) {

printf(“Could not open %s \n”, SERIAL4);
printf(“This means %s\n”, strerror( errno));
exit (1);
}

tcgetattr(fd, &termios_p);
cfmakeraw(&termios_p);

cfsetispeed(&termios_p, B9600);
cfsetospeed(&termios_p, B9600);

termios_p.c_cflag &= ~CSIZE;
termios_p.c_cflag &= ~PARENB;
termios_p.c_iflag &= ~INPCK;

// termios_p.c_cflag |= CREAD | CS7 | PARENB; // 7,1,even
// termios_p.c_iflag |= INPCK;

termios_p.c_cflag |= CREAD | CS8 ; // 8,n,1

termios_p.c_oflag = 0;
termios_p.c_lflag = 0xa00;
tcsetattr(fd, TCSANOW, &termios_p);

while ( 1 )
{

result = read(fd, buff, 1);
if (result == -1 )
{
printf(“Can not read %s\n”, strerror( errno));
}
else
{
printf("%d %c ",(int)buff[0], buff[0]);
}
}

}


QNX Training Services
I do not answer technical questions by email.

I made it working.

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>

#define MODEMDEVICE “/dev/ser4”

#define FALSE 0
#define TRUE 1

volatile int STOP=FALSE;

main()
{
int fd,c, res;
struct termios oldtio,newtio;
char buf[255];

fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
if (fd <0) {perror(MODEMDEVICE); exit(-1); }

tcgetattr(fd,&oldtio); /* save current port settings */


memset( &newtio, 0,sizeof(newtio));


cfsetispeed(&newtio, B9600);
cfsetospeed(&newtio, B9600);

newtio.c_cflag &= ~CSIZE;

newtio.c_cflag &= ~PARENB;
newtio.c_iflag &= ~INPCK;

newtio.c_cflag |= CREAD | CS7 | PARENB; // 7,1,even
newtio.c_iflag |= INPCK;

newtio.c_oflag = 0;

/* set input mode (non-canonical, no echo,…) */
newtio.c_lflag = 0;

newtio.c_cc[VTIME] = 0; /* inter-character timer unused /
newtio.c_cc[VMIN] = 1; /
blocking read until 1 char received
*/

tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);


while (STOP==FALSE) { /* loop for input /
res = read(fd,buf,255); /
returns after 1 char1 has been input
/
buf[res]=0; /
so we can printf… */
printf(":%s:%d\n", buf, res);
if (buf[0]==‘z’) STOP=TRUE;
}
tcsetattr(fd,TCSANOW,&oldtio);
}


“Janusz” <ruszelj@baxter.com> wrote in message
news:9rbslj$h2v$1@inn.qnx.com
I have tried and still no luck.
Janusz.
“David Gibbs” <dagibbs@qnx.com> wrote in message
news:9r9atf$nji$1@nntp.qnx.com
Janusz <ruszelj@baxter.com> wrote:

RTP 6.0 with patch A.
The read instruction on /dev/ser4 block until CTRL-J is sent or more then
195 characters are sent.

Do I miss something ? Experts please advise.

Might be a canonical vs non-canonical mode issued. (edited vs raw
mode). Have you tried turning off I_CANON flag in termios.c_lflag?

Otherwise, I think the terminal does line-editing stuff, or at least
expects to, and won’t deliver data until a “line” is complete –
CTRL-J (linefeed) is a line completion character.

Not sure this is it… but seems likely.

-David

Janusz.



------------ Test program ---------------------

#include <stdio.h
#include <fcntl.h
#include <termios.h
#include <errno.h
#include <string.h

#define SERIAL4 “/dev/ser4”

int fd;
struct termios termios_p;



main()
{
int result;
fd = open(SERIAL4, O_RDWR | O_NOCTTY );

unsigned char buff[5]={32,32,32,32,32};

if (fd == -1 ) {

printf(“Could not open %s \n”, SERIAL4);
printf(“This means %s\n”, strerror( errno));
exit (1);
}

tcgetattr(fd, &termios_p);
cfmakeraw(&termios_p);

cfsetispeed(&termios_p, B9600);
cfsetospeed(&termios_p, B9600);

termios_p.c_cflag &= ~CSIZE;
termios_p.c_cflag &= ~PARENB;
termios_p.c_iflag &= ~INPCK;

// termios_p.c_cflag |= CREAD | CS7 | PARENB; // 7,1,even
// termios_p.c_iflag |= INPCK;

termios_p.c_cflag |= CREAD | CS8 ; // 8,n,1

termios_p.c_oflag = 0;
termios_p.c_lflag = 0xa00;
tcsetattr(fd, TCSANOW, &termios_p);

while ( 1 )
{

result = read(fd, buff, 1);
if (result == -1 )
{
printf(“Can not read %s\n”, strerror( errno));
}
else
{
printf("%d %c ",(int)buff[0], buff[0]);
}
}

}


QNX Training Services
I do not answer technical questions by email.