Program

NOTE

Use of communications features. This program allows the user to attach a line and enter a conversational mode with a device connected to the line.

 

EQU ESC TO CHAR(27) ; * ESC used for control sequence

*

PROMPT '-'

MYLINE = SYSTEM(101); * Get current LINKED line # LOOP

   PRINT "ENTER LINE NUMBER OR 'END'":

      ; *Prompt for target line

   INPUT LINE

UNTIL LINE = "END" DO

   LOOP

      EXECUTE "LINE-ATT ":LINE RETURNING

            ERR ; *Attempt to attach line

   UNTIL ERR = "8013" DO REPEAT ; * Errmsg 8013 =

      'LINE ATTACHED'

REPEAT

*

IF LINE = "END" THEN STOP

*

ESCAPE = 0;  EXIT = 0 ; * Initialize flags

ECHO OFF ; * Full duplex:  device will echo input

*

LOOP

   GET BYTE FROM MYLINE THEN ; * Get single char from terminal

      IF ESCAPE THEN ; * Is this second char of ESC seq?

         IF BYTE = "X" THEN EXIT = 1 ;* exit from conversation

         IF BYTE = ESC THEN

            SEND BYTE:  TO LINE ELSE EXIT = 1

         END   

      END ELSE

         IF BYTE = ESC THEN

             ESCAPE = 1 ELSE ; *If char is ESC set flag

         END ELSE

            SEND BYTE:  TO LINE ELSE EXIT = 1

               ; * Send char without CR LF

         END

      END

END ELSE ; * If no terminal input then

   GET BYTE FROM LINE THEN CRT BYTE:

      ;* get char from target line

END ; * if any, send to terminal

UNTIL EXIT DO REPEAT

*

ECHO ON ; * Turn echo back on

EXECUTE "LINE-DET ":LINE ; * Detach the line

PRINT "CONVERSATION ENDED"

Program Notes

This program is similar in operation to the CONVERSE verb. The local echo is turned off because the program assumes a full-duplex mode with the attached device. All input will be echoed back to its line.

The main loop of the program alternately tests for input from the terminal and the device by using the conditional GET statements. When a character is received from a terminal, it is sent to the device and vice versa. Escape sequences, consisting of an ESC character followed by another single character, are used for control. The two sequences implemented in this program are: ESC X to exit the program and ESC ESC to transmit an ESC character.

The EXECUTE statement is used to perform the LINE-ATT and LINE-DET functions.

See Also

Appendix C: mvBASIC Program Examples

General Coding Techniques

Example 1: Triples

Example 2: Guess

Example 3: INV-INQ

Example 4: Format

Example 5: Lot-update

Example 6: Communications