'===========================================================================
' Subject: Minimal Modem                      Date: 12-14-02 (  :  )       
'  Author: Antoni Gual                        Code: QB,PDS                 
'  Origin: agual@eic.ictnet.es              Packet: MODEM.ABC
'===========================================================================
'MINIMAL TERMINAL By Antoni Gual 15/11/02
'Comms using PC's serial ports.

CONST TIMEOUT = .2 'seconds

OPEN "COM2: 9600,N,8,1,CS0,CD0,DS0,OP0,RS" FOR RANDOM AS #1

'NOTES on QB comms:
'QB can't open a link with 8 data bits with a parity dirrerent from
'  no parity!
'Only COM1 and 2 are available to QB.
'QB does drop DTR at exit, it causes modems to drop lines.

'WIRING:
'The PC side should work with only 3 wires. The device at the other
'side may need more wires connected.
'
'If you want to connect to another PC, you must use a null modem
'cable in which pin 2 connects to other device's pin 3 and vice-versa.
'
'PC (MALE SOCKET)                           PC(MALE SOCKET)
' DB25    DB9                                  DB9  DB25
'
'  2      3  ----------------\/---------------- 3     2
'  3      2  ----------------/\---------------- 2     3
'
'  7      1  -----------------------------------1     7
'

'If you have a true modem (not a winmodem), you can test this program
'sending AT to the modem. It should answer "Ok" or "0"

DO
 'get key
 K$ = INKEY$

 'process key pressed
 IF LEN(K$) THEN
    SELECT CASE ASC(K$)
   
    'enter ends message and sends it
    CASE 13:
      IF LEN(TX$) THEN PRINT #1, TX$: TX$ = ""
   
    'backspace erases rightmost char
    CASE 8
      IF LEN(TX$) THEN
        TX$ = LEFT$(TX$, LEN(TX$) - 1)
        p = POS(0): LOCATE , p - 1: PRINT " "; : LOCATE , p - 1
      END IF
   
    'escape quits
    CASE 27
      EXIT DO
   
    'any other key is added to message
    CASE ELSE
      TX$ = TX$ + K$: PRINT K$;
    END SELECT

 END IF

 'read receive buffer
 WHILE NOT EOF(1)
    RX$ = RX$ + INPUT$(LOC(1), 1)
    T! = TIMER + TIMEOUT
 WEND

 'if rx timeout, display received message and clear buffer
 IF TIMER > T! THEN
    IF LEN(RX$) THEN COLOR 15, 0: PRINT RX$; : COLOR 7, 0: RX$ = ""
    T! = TIMER + TIMEOUT
 END IF
LOOP

CLOSE
END

