Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title How can a program determine what state a printer is in?
Ref. No. QNX.000009303
Category(ies) Development
Issue How can a program determine what state a printer is in?
Solution To check or control the state of a device, you can use qnx_ioctl(), which lets your application communicate directly with a device driver. The following program, 'dev_check.c', uses qnx_ioctl() to check a device, then dumps the info on the screen.

Here's an example of how you would use dev_check:

x09dev-check /dev/par1

and here's the source:

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/dev.h>
#include <sys/qioctl.h>

#define IS_CONx091
#define IS_SERx092
#define IS_PARx093

struct controls {
x09char *ctrt_name;
x09unsigned ctrl_bits;
x09};
struct controls pcontrols[] ={
x09"ERROR",x090x0800,
x09"Online",x090x1000,
x09"PaperOut",x090x2000,
x090
x09};

char term_char = 'n';

struct termios tios;

main(argc, argv)
int argc;
char *argv[];
x09{
x09struct _dev_info_entry dinfo;
x09long Ival[2];

x09x09if(tcgetatt(stdin, &tios) = -1) {
x09x09fprintf(stderr, "%s: Not a terminal devicen", argv[0]);
x09x09exit(EXIT_FAILURE);
x09x09}

x09dev_into(stdin, &dinfo);

x09printf("Name: %sn", &dinfo.tty_name[0]);
x09printf("Type: %sn", &dinfo.driver_type[0]);
x09printf("Opens: %d (%c%c)n", dinfo.open_count,
x09x09(dinfo.flags & _DEY_IS_READERS) ? 'R' : '-'
x09x09(dinfo.flags & _DEV_IS_WRITERS) ? 'W' : '-'
x09x09);

// Get state of hardware lines
x09lval[0] = 0;
x09lval[1] = 0;
x09if(qnx_ioctl( stdin, QCTL_DEV_CTL, &lval[0], 8, &lval[0], 4 ) = 0 {
x09x09printf("Printer State: ");
x09x09printf(" %cERR", (lval[0] & 0x0008L) ? '-' : '+';
x09x09printf(" %cONL", (lval[0] & 0x0010L) ? '-' : '+';
x09x09printf(" %cPE", (lval[0] & 0x0020L) ? '-' : '+';
x09x09printf(" %cBSY", (lval[0] & 0x0080L) ? '-' : '+';
x09x09printf(" %c", term_char);
x09x09}
}

For more information on qnx ioctl(), see the WATCOM C Library Reference.