How to capture communication event under QNX

Hi, all
I’m writing a serial communication program under QNX. I know that I should
use ionotify() to get notification from the resource manager devc-ser8250
when the data arrives, but I still don¡¯t know how to capture this
notification. I¡¯m quite familiar with this kind of programming by using VB
in which the OnComm event of MSComm widget capture all the communication
event for us. Could someone tell me that by what way my program can capture
the communication event under QNX ? Where can I find the sample code to deal
with this kind of things?

Thanks

Flying

lp wrote:

Hi, all
I’m writing a serial communication program under QNX. I know that I should
use ionotify() to get notification from the resource manager devc-ser8250
when the data arrives, but I still don¡¯t know how to capture this
notification. I¡¯m quite familiar with this kind of programming by using VB
in which the OnComm event of MSComm widget capture all the communication
event for us. Could someone tell me that by what way my program can capture
the communication event under QNX ? Where can I find the sample code to deal
with this kind of things?

You’re probably best off using select(). There are plenty of books that
explain how to use select(). Below is a link to a Dr. Dobbs article
on the subject. If you are from the M$ world you may be familiar with
select() from winsock programming, if so, then you need to be aware that
there is essentially no difference between a select() on a fd that was
returned by opening a serial port (i.e. open("/dev/ser1"…)), or via an
open of any other “device” (including sockets). In QNX, “everything is a
file”.

In a nutshell the code you need in order to be “notified” when data
arrives is something like:

fd_set rdset;
struct timeval to = { 0, 100000 };

fd=open("/dev/ser1", O_RDWR);

FD_ZERO(&rdset);
FD_SET(fd, &rdset);

switch(n=select(fd+1, &rdset, NULL, NULL, &to))
{
case 0:
do_other_stuff_every_tenth_of_a_second_while_waiting_for_comms();
break;
case -1:
printf(“hmmm…\n”);
break;
default:
if(FD_ISSET(fd, &rdset)) {
/* fd is readable */
}
break;
}

http://www.ddj.com/documents/s=916/ddj9809e/9809e.htm