“Alain Achkar” <js@simplytech.com> wrote in message
news:d2i5te$njr$1@inn.qnx.com…
Thanks, this was quite helpful to get me started.
Now, can I tell it which pseudo-tty to use? I prefer not to have the
Photon application spawn the other program, but have the other program
“find” the pseudo tty.
Of course, you can tell the widget which pseudo-tty to use, by giving it an
fd or a path to open. Just remember that you want the widget to use the
“master” (the /dev/ptypx) and the other program the “slave” (the
/dev/ttypx). The “master” is not a fully functional terminal device.
Of course, you need to make sure that the pseudo-tty isn’t already being
used by a pterm, telnetd, or some other program. One way is to just try –
an attempt to open the master will fail if someone else has it already open.
Another way is by using openpty(). And yet another way is by asking the
PtTty widget to find and open an unused pseudo-tty for you (that’s what the
Pt_ARG_TTY_PSEUDO resource does), reading the Pt_ARG_TTY_PATH resource to
get the path to the slave, and telling the other program to open that path.
I am actually writing something similar to a terminal emulator, but it
does not connect to a serial port. It should present a path, e.g.
/dev/ttyq1 which the other application would use for input/output. In a
way, it’s similar to starting pterm like this:
pterm -d /dev/ptyq1
and then echoing chars from my application to /dev/ttyq1, e.g.
ls > /dev/ttyq1
Or like
ls > $(pterm -N1&)
It is still not clear to me why Pt_ARG_TTY_PATH returns something like
/dev/ttyp5 and not /dev/ptyp5. The documentation is not clear about which
is master and which is slave?
The master is the end that the widget uses to read the other program’s
output from (Pt_ARG_TTY_RFD), and to write Photon keyboard input to
(Pt_ARG_TTY_WFD). The slave is the end that the other program should read
the keyboard input from and write its output to (Pt_ARG_TTY_SFD). The
Pt_ARG_TTY_PATH resource is the path to the slave, rather than the master,
to allow you to pass the path to your other program, in case the other
program wants to open the device itself, instead of being spawned by the
widget and inheriting the fd. The path to the master would be useless to
you – you’re not supposed to try to open it or do any I/O to it.
Which of the above do you think the documentation is not clear enough about?
Also, should my terminal emulator write to /dev/ptyp5 or should it use
the Photon functions?
The PtTty widget will handle writing to and reading from the master. All
you need to do is run PtMainLoop().
Does QNX supply the code for pterm? (maybe wishful thinking >
There isn’t that much code in pterm, and pretty much all of it deals with
parsing command-line arguments, reading and saving the configuration file,
and figuring out what to display on the title bar. Some of the command-line
options correspond directly to the resources of PtTty:
-d – set Pt_ARG_TTY_PATH to
-D – set Pt_ARG_TTY_RFD and Pt_ARG_TTY_WFD to
-N – set Pt_ARG_TTY_PSEUDO, write the Pt_ARG_TTY_PATH string to ,
close
None of the above – set Pt_ARG_TTY_PSEUDO and then Pt_ARG_TTY_ARGV.
Wojtek Lerch wrote:
… The Pt_ARG_TTY_PATH resource isn’t very useful with pseudo
terminals – it would be a better choice if your goal were to write a
terminal emulator talking to a serial port connected to another system.
This didn’t come out quite clear, did it… What I meant was that if you
know you’re using a pseudo-terminal, setting Pt_ARG_TTY_PSEUDO makes your
life easier than setting Pt_ARG_TTY_PATH because it finds an unused pty pair
for you. But after it has found a pty, reading Pt_ARG_TTY_PATH back may be
useful.