Serial port read-write blocking?

I have two applications which are communicationg with serial
ports. Problem is totally blocking application when there is no device
attached to serial port. It looks like app is jammed when reading
port, regardless use of select, O_NONBLOCK, DevRead.

To details:

  • Serial drivers are started like this:
    /bin/Dev.ser -N/dev/ser1 3f8,4 &
    /bin/Dev.ser -N/dev/ser2 2f8,3 &

For 5554/8

/bin/Dev.ser -F -N/dev/ser3 100,7 -b 38400 108,7 110,7 118,7 &


\

  • Opening & using serial port:

serfile = open( serdev, O_RDWR | O_NONBLOCK );
tcgetattr(serfile, &CommSettings);
cfsetispeed(&CommSettings,portspeed);
cfsetospeed(&CommSettings,portspeed);
CommSettings.c_iflag = IGNBRK;
CommSettings.c_oflag &= ~OPOST;
CommSettings.c_cflag = CS8 | CSIZE | CREAD | CLOCAL| OHFLOW |
IHFLOW | CSTOPB;
CommSettings.c_lflag = IEXTEN;
RetVal = tcsetattr(serfile,TCSANOW, &CommSettings);

rval = write(serfile,&b,1);

FD_ZERO(&rfds);
FD_SET(serfile,&rfds);
memset(&timeout,0,sizeof(timeout));
if( select(serfile+1, &rfds, NULL, NULL, &timeout ) > 0) {
nBytesRead = dev_read( serfile, ((BYTE *)(&buff)),NUM_OF_ELEMENTS(buff),
0,0,0,0,0 );


M. Tavasti / tavastixx@iki.fi / +358-40-5078254
Poista sähköpostiosoitteesta molemmat x-kirjaimet
Remove x-letters from my e-mail address

Hi,

I’m new to programming in QNX, but I saw something in your code that I
thought I’d point out. I don’t know if it’ll fix your problem or not.

Look below for my comments.

Dan

“M. Tavasti” <tavastixx@iki.fi.invalid> wrote in message
news:m2zod64zdd.fsf@akvavitix.vuovasti.com

I have two applications which are communicationg with serial
ports. Problem is totally blocking application when there is no device
attached to serial port. It looks like app is jammed when reading
port, regardless use of select, O_NONBLOCK, DevRead.

To details:

  • Serial drivers are started like this:
    /bin/Dev.ser -N/dev/ser1 3f8,4 &
    /bin/Dev.ser -N/dev/ser2 2f8,3 &

For 5554/8

/bin/Dev.ser -F -N/dev/ser3 100,7 -b 38400 108,7 110,7 118,7 &


\

  • Opening & using serial port:

serfile = open( serdev, O_RDWR | O_NONBLOCK );
tcgetattr(serfile, &CommSettings);
cfsetispeed(&CommSettings,portspeed);
cfsetospeed(&CommSettings,portspeed);
CommSettings.c_iflag = IGNBRK;
CommSettings.c_oflag &= ~OPOST;
CommSettings.c_cflag = CS8 | CSIZE | CREAD | CLOCAL| OHFLOW | IHFLOW |
CSTOPB;

Correct me if I’m wrong but CSIZE is a bitmask for the character size. If I
understand what is going on then the line you have above would work the same
if you wrote it

CommSettings.c_cflag = CSIZE | CREAD | CLOCAL| OHFLOW | IHFLOW | CSTOPB;

because CSIZE ORed with any CS# will equal CSIZE

You can use CSIZE to find out what the current character size is
char_size = CommSettings.c_cflag &= CSIZE; //isolate the character size
bits

Or you can use CSIZE to clear the size bits before setting the character
size.
CommSettings.c_cflag &= ~CSIZE; //Set all size bits to 0
CommSettings.c_cflag |= CS8; //Now OR with CS8

CommSettings.c_lflag = IEXTEN;
RetVal = tcsetattr(serfile,TCSANOW, &CommSettings);

rval = write(serfile,&b,1);

FD_ZERO(&rfds);
FD_SET(serfile,&rfds);
memset(&timeout,0,sizeof(timeout));
if( select(serfile+1, &rfds, NULL, NULL, &timeout ) > 0) {
nBytesRead = dev_read( serfile, ((BYTE
*)(&buff)),NUM_OF_ELEMENTS(buff),
0,0,0,0,0 );


M. Tavasti / > tavastixx@iki.fi > / +358-40-5078254
Poista sähköpostiosoitteesta molemmat x-kirjaimet
Remove x-letters from my e-mail address