[mod.computers.vax] Detecting Baud rate.

TWADE@CSVAX.UCD.HEA.IRL.UUCP (04/10/87)

>   Is there any system service (I think not) or other technique
>that I can use to determine the baud rate for a process' controlling
>terminal?  I have a need for such code.  It would be preferable to
>allow a suitably privileged program to determine it based on PID, but
>it would also be feasible to use code that determined this only for
>the current job.  (NO, SHO TERMINAL to a file and parsing the result
>is NOT suitable.)

Here is a routine that I ripped out of a program, and turned into a
callable procedure. It will return the transmit and receive speeds for
the process's own controlling terminal. The codes are defined by the $TTDEF
macro as TT$C_BAUD_300, TT$C_BAUD_9600 etc. I am not sure how many there
are, but that isn't difficult to find out. The calling sequence is

        success = GET_SPEED (t_speed, r_speed)
Both args are longwords passed by reference.
--------------- SPEED.MAR -------X Cut here X----------------------------
        .Title    GET_TTY_SPEED

;   This procedure returns the speed of the process's controlling terminal.
;   It returns SS$_NORMAL for success, or any error code from $ASSIGN, $DASSGN
;   or $QIOW if failed.
;
;   The actual speeds are returned in the I/O status block when a SENSEMODE
;   QIO if performed (p 8-49, IO User Guide part 1). I notice that the
;   documentation states that the receive speed is only returned if different
;   from the transmit, but when I tried it I got both fields set to 10 Hex
;   (19200 baud). Parity flags are also returned, though this routine ignores
;   them.

        $TTDEF

Ttchan:        .Long    0            ; channel
Ttdev:        .Ascid    "SYS$COMMAND"

Iosb:                        ; I/O Status Block.
Status:        .Word    0            ; return status.
T_speed:    .Byte    0            ; transmit speed.
R_speed:    .Byte    0            ; receive speed.
Cr_fill:    .Byte    0            ; CR characters inserted.
Lf_fill:    .Byte    0            ; LF characters inserted.
Parity:        .Byte    0            ; parity flags.
        .Byte    0            ; unused.


        .Entry    GET_SPEED    M <>

        $ASSIGN_S -
            chan = ttchan, -
            devnam = ttdev
        Blbs    R0,    10$
        Ret

10$:        $QIOW_S -
            chan = ttchan, -
            func = #IO$_SENSEMODE, -
            iosb = iosb, -
            p1 = #0, -        ; we are not interested
            p2 = #0            ; in various mode settings.

        Blbs    R0,    20$
15$:           Ret

20$:        Movzwl    status,    R0        ; check status return.
        Blbc    R0,    15$

        Movzbl    t_speed, @4(AP)        ; return transmit speed.
        Tstb    r_speed            ; receive speed present?
        Bneq    30$            ; yes - return it.
        Movb    t_speed, r_speed    ; no - set it = transmit.

30$:        Movzbl    r_speed, @8(AP)        ; return receive speed.

        $DASSGN_S -            ; Close the channel.
            chan = ttchan

        Blbc    R0,    15$

        Movzwl    #SS$_NORMAL, R0        ; indicate success.
        Ret

        .End

----------- EOF SPEED.MAR -------X Cut Here X---------------------------------

As I say, I just hacked this together. It worked when I tried it on my
terminal, but the normal totally irresponsible disclaimers apply.
-------------------------------------------------------------------------
Tom Wade            Internet:    twade@csvax.ucd.hea.irl
Systems Programmer        Ean:        twade@csvax.ucd.irl
Dept Computer Science        PSI:        PSI%27243154000721::TWADE
University College Dublin    Telex:        (0500) 91196 UCD EI
Ireland.            Voice:        +353-1-693244 Ext 2472
-------------------------------------------------------------------------