Using PtTty in Photon App

Using PhAB version 1.13, (QNX 4.25) but there is no drag-and-drop
symbol for the PtTty widget showing up in PhAB.

Would really like to use PtTty in my photon application.

Since it is missing, how should I:

  • add the symbol, or;
  • create the widget in source code using PtCreateWidget;

Ideas?

tia,

  • GF

OK, I was able to create the PtTty using PtCreateWidget (see code below).

A file descriptor is returned and printed, (and the TTY appears in my GUI)
but the returned path info is not a recognizable string.

What did I do wrong?

-GF


char tty_name [20];
int *tty_fd;

int
main_setup( PtWidget_t *link_instance, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )
{
PtArg_t args [2];

/* Attach to unused pseudo-tty device */
strcpy (tty_name, “/dev”);
PtSetArg (&args[0], Pt_ARG_TTY_PSEUDO, tty_name, strlen (tty_name));
tty_widget = PtCreateWidget (PtTty, NULL, 1, args);
if (tty_widget == NULL)
{
fprintf (stderr, “Error: Failed to create TTY widget. \n”);
return (Pt_CONTINUE);
}

/* Attach succeeded, so get file descriptor and path. */
PtSetArg (&args[0], Pt_ARG_TTY_MFD, &tty_fd, 1);
PtSetArg (&args[1], Pt_ARG_TTY_PATH, tty_name, 20);
PtGetResources (tty_widget, 2, args);
if (*tty_fd == -1)
{
fprintf (stderr, “Error: No TTY Device attached! \n”);
}
else
{
fprintf (stdout, “TTY Device file descriptor %d\n”, &tty_fd);
fprintf (stdout, “TTY Device path: %s\n”, tty_name);
}
return( Pt_CONTINUE );
}

output:
TTY Device file descriptor 1914268
TTY Device path:

“Gordon Freeman” <gf@bigfoot.com> wrote in message
news:dsgnb0$a3v$1@inn.qnx.com

OK, I was able to create the PtTty using PtCreateWidget (see code below).

A file descriptor is returned and printed, (and the TTY appears in my GUI)
but the returned path info is not a recognizable string.

What did I do wrong?

You set up the arguments for PtGetResources() incorrectly. See below.

char tty_name [20];
int *tty_fd;

strcpy (tty_name, “/dev”);
PtSetArg (&args[0], Pt_ARG_TTY_PSEUDO, tty_name, strlen (tty_name));

The copying and the strlen are unnecessary here – you could do a simple

PtSetArg (&args[0], Pt_ARG_TTY_PSEUDO, “/dev/”, 0 );

/* Attach succeeded, so get file descriptor and path. */
PtSetArg (&args[0], Pt_ARG_TTY_MFD, &tty_fd, 1);
PtSetArg (&args[1], Pt_ARG_TTY_PATH, tty_name, 20);

This is the problem. PtGetResources() doesn’t copy characters – it just
copies pointers. You should use a char pointer, not an array:

char *tty_name_ptr;
PtSetArg (&args[1], Pt_ARG_TTY_PATH, &tty_name_ptr, 0);

fprintf (stdout, “TTY Device file descriptor %d\n”, &tty_fd);

You meant *tty_fd rather than &tty_fd, right?

What did I do wrong?

You set up the arguments for PtGetResources() incorrectly. See below.

Thank you Wojtek. It seems I am rusty about the important details.

It works great with these changes. e.g. file descriptor = 6, path =
/dev/ttyp6

My purpose is to run a script from the gui, and display the output
of the script in a window, just like when you compile gui code from PhAB.

-GF