ITEM: G8260L

Questions on psuedo ttys and porting X-window application




Question:

Two questions on ports X application:  
1)  Needs to know which device to use for input and which to use for output
   (/dev/ptc - master and /dev/pts - slave).
2)  In a multi-plexed environment need to know how to open two psuedo ttys.

Not sure if this is what she is after, but the so called multiplexed
special files are:  /dev/pts and /dev/ptc.  Special links are created
so that the control side looks like this:
        /dev/ptyp0 to /dev/ptypf  --> /dev/ptc/0 to /dev/ptc/15
        /dev/ptyq0 to /dev/ptyqf  --> /dev/ptc/16 to /dev/ptc/31
        /dev/ptyr0 to /dev/ptyrf  --> /dev/ptc/32 to /dev/ptc/47
        /dev/ptys0 to /dev/ptysf  --> /dev/ptc/48 to /dev/ptc/63
The slave notes are similar but use:
        /dev/ttyp0 to /dev/ttypf  --> /dev/pts/0 to /dev/pts/15
        /dev/ttyq0 to /dev/ttyqf  --> /dev/pts/16 to /dev/pts/31
        /dev/ttyr0 to /dev/ttyrf  --> /dev/pts/32 to /dev/pts/47
        /dev/ttys0 to /dev/ttysf  --> /dev/pts/48 to /dev/pts/63

the 'ttyname' subroutine will always return the slave name, even
if the control side was opened first.

I used tty on one window on my hft
tty
pts/7

I then wrote a program that I opened /dev/ttyp7, and wrote data to
it opening /dev/ttyp7 as the port.  Data showed up in the window.

Next I wrote a program to write data to a pseudo terminal not in use:
and one to read. The write program looked like this:

/*                                                                     *
 * EXAMPLE PROGRAM: Open a pty and write data out to the pty.          *
 *                  I have a window on my screen tty=/dev/pts/         */

\#include \
\#include \

\#include \
\#include \

\#define PORT "/dev/ttypf"
extern errno;

main()
{int     port;
        char c;                 /* Charater read    */
        int status;             /* read status      */
        char buf[2048];
        int i, ichw;

        for ( i=0 ; i\<20 ; i++ )  /* Create some data to send */
                buf[i] = 'b';

        port = open(PORT,O_RDWR );
        if ( ! port )
        {
                printf("ttyset: cannot open port %s\\n", PORT);
                perror("ttyset");
                exit(errno);
        }
        printf("Open worked for /dev/ttypf\\n");

        for ( i=1 ; i\<=20 ; i++ )
        {
        ichw = write(port,buf,8);
        printf ("Bits %d\\n",ichw);
        sleep(1);
        }
}
The READ program looked like this:
/*                                                                     *
 * EXAMPLE PROGRAM: Open a pty and write data out to the pty.          *
 *                  I have a window on my screen tty=/dev/pts/         *
/
\#include \
\#include \
\#include \
\#include \
\#define PORT "/dev/ptypf"
extern errno;

main()
{
int     port;
        char c;                 /* Charater read    */
        int status;             /* read status      */
        char buf[2048];
        int i, ichw;

        for ( i=0 ; i\<2048 ; i++ )  /* Create some data to send */
                buf[i] = 'a';
                buf[10] = NULL;

        port = open(PORT,O_RDWR );
        if ( ! port )
        {
                printf("ttyset: cannot open port %s\\n", PORT);
                perror("ttyset");
                exit(errno);
        }
        printf("Open worked\\n");

        for ( i=1 ; i\<=20 ; i++ )
        {
        ichw = read(port,buf,8);
        printf ("Read %d bytes: %s\\n",ichw,buf);
        sleep(1);
        }

Note that /dev/ttypf open waited for /dev/ptypf open to occur.  Data
was send between the two with no problems.  I reversed the read and
write in the to programs and was not able to send data from /dev/ptypf
to /dev/ttypf.


Support Line: Questions on psuedo ttys and porting X-window application ITEM: G8260L
Dated: February 1994 Category: N/A
This HTML file was generated 99/06/24~13:30:49
Comments or suggestions? Contact us