User Tools

Site Tools


simple_20terminal_20program

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
simple_20terminal_20program [2018/03/31 13:19] – external edit 127.0.0.1simple_20terminal_20program [2024/01/05 00:21] (current) – external edit 127.0.0.1
Line 2: Line 2:
  
 //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.\\  //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.\\ 
 +<code bb4w>
         REM a simple terminal program.         REM a simple terminal program.
         Port% = OPENUP "COM1: baud=9600 parity=N data=8 stop=1"         Port% = OPENUP "COM1: baud=9600 parity=N data=8 stop=1"
Line 9: Line 10:
         DIM commtimeouts{rit%, rttm%, rttc%, wttm%, wttc%}         DIM commtimeouts{rit%, rttm%, rttc%, wttm%, wttc%}
         SYS "SetCommTimeouts", @hfile%(Port%), commtimeouts{}         SYS "SetCommTimeouts", @hfile%(Port%), commtimeouts{}
 +</code>
 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.\\  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.\\ 
 +<code bb4w>
         REM  chars%  This is the number of characters.         REM  chars%  This is the number of characters.
         REPEAT         REPEAT
           REM get the number of characters.           REM get the number of characters.
           chars% = EXT#Port%           chars% = EXT#Port%
 +</code>
 **chars%** is the number characters waiting to be read. If there are no characters in the serial buffer, the keyboard is read with **INKEY**.\\  **chars%** is the number characters waiting to be read. If there are no characters in the serial buffer, the keyboard is read with **INKEY**.\\ 
 +<code bb4w>
           REM Number of characters waiting in the serial input buffer, for a read action.           REM Number of characters waiting in the serial input buffer, for a read action.
           IF chars%=0 THEN           IF chars%=0 THEN
Line 22: Line 27:
             k% = INKEY(0)             k% = INKEY(0)
           ENDIF           ENDIF
 +</code>
 If **k% = -1** nothing was entered on the keyboard.\\  If **k% = -1** nothing was entered on the keyboard.\\ 
-=====   ===== +<code bb4w>
-\\ +
           REM If a character has been entered via keyboard, send it to serial output buffer           REM If a character has been entered via keyboard, send it to serial output buffer
           IF k%>-1 THEN BPUT#Port%,k%           IF k%>-1 THEN BPUT#Port%,k%
         UNTIL FALSE         UNTIL FALSE
         END         END
 +</code>
 Otherwise the number of characters, is passed as a parameter to **PROCSendToVDU**\\  Otherwise the number of characters, is passed as a parameter to **PROCSendToVDU**\\ 
 +<code bb4w>
         DEF PROCSendToVDU(chrs%)         DEF PROCSendToVDU(chrs%)
         LOCAL index%, Data%         LOCAL index%, Data%
Line 40: Line 47:
         ENDIF         ENDIF
         ENDPROC         ENDPROC
 +</code>
simple_20terminal_20program.1522502382.txt.gz · Last modified: 2024/01/05 00:16 (external edit)