- The TX Series DPR driver for the UNIX systems (both UnixWare and Solaris) is a STREAMS driver and hence is directly accessed via the standard system calls: open, close, putmsg, getmsg, ioctl, etc. The driver communicates to applications using a specific driver-to-app protocol and hence direct access is not recommended. The CPI library uses a TX_HANDLE type as an object on which all I/O is done. In the UnixWare and Solaris systems, this object, retrieved using cpi_wait_obj, is just a standard UNIX File Descriptor and can be used as such. In particular, packets can be received by the host UnixWare or Solaris system from the TX Series board or boards asynchronously by using either the poll system call or the select system call.
- For example if you care to wait on both tty input and packets from a TX Series board your can use poll as follows:
.
struct pollfd fds[2];
.
.
cpi_init(0, &str);
mode = CPIM_PORT;
port = PORT((short)board, (short)chan);
if ((fd = cpi_open(port, mode, NULL)) < 0)
{
< Error handling code >
}
for (;;)
{
fds[0].fd = 0; /* fd for standard input */
fds[0].events = POLLIN;
fds[0].revents = 0;
fds[1].fd = fd; /* TXn000 fd */
fds[1].events = POLLIN;
fds[1].revents = 0;
if (poll(fds, 2, -1) < 0)
{
< Error handling code >
}
for (i = 0; i < 2; i++)
{
if (fds[i].revents & (POLLERR | POLLHUP | POLLNVAL))
{
< Error handling code >
}
if (fds[i].revents & POLLIN)
{
/* TXn000 receive */
if (fds[i].fd == fd)
{
if (ret = cpi_get_data(fd,&outbuf,&len))
{
< Error handling code >
}
.
.
< Code to process data >
.
.
}
/* Terminal input */
else if (fds[i].fd == 0)
{
}
}
} /* for i */
} /* for ever */