The TX driver for UNIX systems is either a streams driver or a character driver, depending on the specific TX board type. In either case, the driver is directly accessed through the standard system calls, open, close, putmsg(streams)/write(character), getmsg(streams)/read(character), and ioctl.
Because the driver communicates with applications using a specific driver-to-application protocol, direct access is not recommended. The CPI library provides a common communication interface regardless of the specific TX device driver being used to communicate with any given TX board.
The CPI library uses a TX_HANDLE type as an object on which all I/O is done. In UNIX systems, pass the TX_HANDLE to cpi_wait_obj to obtain a standard UNIX file descriptor. The host UNIX system can asynchronously receive packets from a TX board using the poll system call or the select system call.
For example, to wait on both input and packets from a TX board, use poll on a UNIX system as follows:
.
struct pollfd fds[2];
.
.
cpi_init(0, &str);
mode = CPIM_PORT;
port = PORT((S16)board, (S16)chan);
if ((txhandle = cpi_open(port, mode, NULL)) < 0)
{
< Error handling code >
}
fd = cpi_wait_obj (txhandle);
for (;;)
{
fds[0].fd = 0; /* fd for standard input */
fds[0].events = POLLIN;
fds[0].revents = 0;
fds[1].fd = fd; /* TX 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)
{
/* TX receive */
if (fds[i].fd == fd)
{ len = sizeof (CPIPKT);
if (ret = cpi_get_data(txhandle,&inbuf,&len))
{
< Error handling code >
}
.
.
< Code to process data >
.
.
}
/* Terminal input */
else if (fds[i].fd == 0)
{
}
}
} /* for i */
} /* for ever */