simple_20terminal_20program

Simple Terminal Program

by Colin McDonagh, April 2007

In my work, I often need to communicate with older pieces of equipment via RS232 cables. Of course there are many such applications available, but it's quite easy in BBC BASIC. First we set up the com port we want to use, in this case com1.

        REM a simple terminal program.
        Port% = OPENUP "COM1: baud=9600 parity=N data=8 stop=1"
        REM Port% is a global variable
        IF Port% = 0 PRINT "Could not open COM1" : END
        PRINT "We are using port number: ", Port% : REM Prints the port number 1 to 4.
        DIM commtimeouts{rit%, rttm%, rttc%, wttm%, wttc%}
        SYS "SetCommTimeouts", @hfile%(Port%), commtimeouts{}

If the com port is being used by another application, you will get “Could not open COM1”. The main body of the program is an infinite loop.

        REM  chars%  This is the number of characters.
        REPEAT
          REM get the number of characters.
          chars% = EXT#Port%

chars% is the number characters waiting to be read. If there are no characters in the serial buffer, the keyboard is read with INKEY.

          REM Number of characters waiting in the serial input buffer, for a read action.
          IF chars%=0 THEN
            k% = INKEY(1)
          ELSE
            PROCSendToVDU(chars%)
            k% = INKEY(0)
          ENDIF

If k% = -1 nothing was entered on the keyboard.

          REM If a character has been entered via keyboard, send it to serial output buffer
          IF k%>-1 THEN BPUT#Port%,k%
        UNTIL FALSE
        END

Otherwise the number of characters, is passed as a parameter to PROCSendToVDU

        DEF PROCSendToVDU(chrs%)
        LOCAL index%, Data%
        IF chrs% > 0 THEN
          REM Get each character in turn and send to the VDU
          FOR index% = 1 TO chrs%
            Data% = BGET#Port%
            VDU Data%
          NEXT index%
        ENDIF
        ENDPROC
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
simple_20terminal_20program.txt · Last modified: 2024/01/05 00:21 by 127.0.0.1