[Previous]
[Contents]
[Next]

console_protocol()

change a console's protocol emulation

Synopsis:

#include <sys/console.h>
int console_protocol( struct _console_ctrl *cc,
                      int console, 
                      int protocol );

Description:

The console_protocol() function is used to change a console's protocol emulation.

The console argument has a value of 1 to represent the device named /dev/con1, a value of 2 for /dev/con2, and so on. A value of 0 for console indicates the default console (that is, the one used by console_open()). A value of -1 for console indicates the currently visible console.

The currently available protocols are:

CON_PROT_QNX4
QNX4 escape codes and QNX4 keyboard
CON_PROT_ANSI
ANSI X3.64 escape codes and ANSI generating keyboard.

If protocol is -1, the protocol for the specified console is unchanged. (This allows you to query a console protocol without changing it, since the previous protocol value is returned.)

Returns:

Upon successful completion, the console_protocol() function returns the previous protocol value; otherwise -1 is returned and errno is set.

Errors:

EACCES
You don't have write permission
EINVAL
One of the arguments is invalid
ENOSYS
Console driver does not support this function. Assume QNX4 protocol.

Examples:

#include <stdio.h>
#include <fcntl.h>
#include <sys/console.h>
#include <errno.h>
#include <stdlib.h>

main()
  {
    struct _console_ctrl *cc;
    int protocol;

    /*
     * Open up a channel to the console driver
     * associated with standard input
     */
    cc = console_open(fileno(stdin), O_RDWR);
    if( cc ) {
      /*
       * Query the current protocol of stdin's console
       */
      protocol = console_protocol(cc, 0, -1);
      if( protocol == -1 ) {
        if( errno == ENOSYS ) {
          protocol = _CON_PROT_QNX4;
        } else {
          perror("console_protocol");
          exit(EXIT_FAILURE);
        }
      }
      printf("Current protocol is %d\n", protocol);

      /*
       * Change to ANSI protocol
       */
      protocol = console_protocol(cc, 0, _CON_PROT_ANSI);
      if( protocol == -1 ) {
        perror("console_protocol");
        exit(EXIT_FAILURE);
      }
      printf("This is now in ANSI mode\n");

      /*
       * Restore protocol
       */
      console_protocol(cc, 0, protocol);
      printf( "This is now returned to previous mode\n" );

      console_close(cc);
    }
  }

Classification:

QNX

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

console_active(), console_arm(), console_close(), console_ctrl(), console_font(), console_info(), console_open(), console_read(), console_size(), console_state(), console_write(), errno


[Previous]
[Contents]
[Next]