janusz ruszel
|
QNX 6.5.0 readcond blocks on serial port open in RAW mode
|
janusz ruszel
01/30/2012 7:12 PM
post91235
|
QNX 6.5.0 readcond blocks on serial port open in RAW mode
The readcond function blocks on seril port open in RAW mode and min, time and timeout set to 0. The QNX 6.5 reference
says that function should return immeadiately with as many bytes as are currently available.
IS IT A POSSIBLE BUG ? or please advice.
Thanks
The test code is listed below:
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int nn_fd = 0;
int
nn_start(int _baud, char *_device)
{
struct termios attr;
int data, ret;
switch (_baud)
{
case 9600: _baud = B9600; break;
case 19200: _baud = B19200; break;
case 38400: _baud = B38400; break;
case 57600: _baud = B57600; break;
case 115200: _baud = B115200; break;
default:
return -1;
}
nn_fd = open(_device, O_RDWR );
if (nn_fd == -1)
return -1;
// tcgetattr(nn_fd, &attr);
memset(&attr, 0, sizeof(attr));
cfmakeraw(&attr);
cfsetospeed(&attr, _baud);
cfsetispeed(&attr, _baud);
/* enable incomming read data */
attr.c_cflag = (CREAD | CLOCAL );
/* set raw data device attributes */
cfmakeraw(&attr);
/* Configure 7 bits, even parity, 1 stop bit */
attr.c_cflag |= PARENB;
attr.c_cflag &= ~CSTOPB;
attr.c_cflag &= ~CSIZE;
attr.c_cflag |= CS7;
/* disable software flow control */
attr.c_iflag &= ~(IXON | IXOFF | IXANY);
/* disable hardware flow control */
attr.c_cflag &= ~(IHFLOW | OHFLOW);
/* define forward character that is used to bypass min, time and timeout */
/* of the readcond function parameters */
attr.c_cc[VFWD] = '\n';
attr.c_cc[VMIN] = 0;
attr.c_cc[VTIME] = 0;
tcsetattr(nn_fd, TCSADRAIN, &attr);
printf("Start conditional read \n");
while (1)
{
data = 0;
ret = readcond(nn_fd, &data, 1, 0 ,0,0);
if (ret > 0) printf("%c", (char)data);
else
{
printf("Status %d\n", ret);
}
}
return 0;
}
int main()
{
nn_start(9600, "/dev/ser2");
exit(0);
}
|
|
|