Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

QBasic FAQ

I/O

Simple comms
Posted: 9 Jan 03

This simple program will allow you to communicate with a modem or to chat thry serial port

'MINIMAL TERMINAL By Antoni Gual 15/11/02
'Serial Comms with QB.

CONST TIMEOUT = .2 'seconds

'CS0,CD0,DS0,OP0,RS makes comms work with a simple 3 wire connection"
'change COM2 TO COM1 if your modem is there. QB does not operate with COM3 and 4

OPEN "COM2: 9600,N,8,1,CS0,CD0,DS0,OP0,RS" FOR RANDOM AS #1

'screen header
COLOR 14, 1
CLS : PRINT "AGV QB Terminal: Key in your message, ENTER to send, ESC to quit":
PRINT STRING$(80, 45); : VIEW PRINT 3 TO 25: COLOR 7, 1

'send and receive loop
DO
 'get key
 K$ = INKEY$

 'if key pressed then process it
 IF LEN(K$) THEN
    SELECT CASE ASC(K$)
   
    'enter ends message and sends it to port
    CASE 13:
      IF LEN(TX$) THEN PRINT #1, TX$: TX$ = ""
   
    'backspace erases rightmost char
    CASE 8
      IF LEN(TX$) THEN
        'erase it in the user string
        TX$ = LEFT$(TX$, LEN(TX$) - 1)
        'erase it in the screen
        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 port and add chars to receive buffer
WHILE NOT EOF(1)
   RX$ = RX$ + INPUT$(LOC(1), 1)
   T! = TIMER + TIMEOUT
WEND

'if timeout is exceeded we suppose line end
'display received message and clear buffer
IF TIMER > T! THEN
   IF LEN(RX$) THEN COLOR 15, 1: PRINT RX$; : COLOR 7, 1: RX$ = ""
   T! = TIMER + TIMEOUT
END IF
LOOP

CLOSE
END


To test it with your modem:
Well, adapt the program to use the COM1 if your modem is there, run it and key in "AT", the modem should answer "Ok" or "0".
NOTE: Winmodems are unusable in DOS and will not answer.

To connect with another PC in the same room, just buy or make a null modem cable.
To make it you will need two DB9 connectors and a 3 or more wire screened cable. Wire pin 2 to pin 3 in the otther conector, pin 3 to 2 and pin 5 to pin 5.
Serious cables will have handshake pins wired to allow faster and more reliable comms, but it's not needed for a test with 2 PC's close together.
Interconnect serial ports and run the program on both PC's, you should be able to communicate.

If you want to try a modem chat:
Be sure both modems answer to the terminal program in both PC's. Run the program in both.
Decide which PC will start the session an which one will answer the phone.
Key in this command in the PC that must answer the phone:
ATS0=1<ENTER>  
modem should answer  "ok". This tells the modem to answer the phone at the first ring.
In the PC starting the session:
ATDT<telephone number to call><ENTER>
The modem should initiate the call and answer"Ok" or "0"
The guy at the other side must be sure no one will answer the phone and let the modem do it.
The modems will handshake automatically, then you both will
have the message "CONNECTED AT xxxx"  xxxx being the connection speed.
You can chat as you want.
when you are ready to finish, key in
+++<ENTER>
and then
ATH0<ENTER>
so the modem hangs the line.

To disable the autoanswer mode in the modem that answered  the calls you will have to key in:
ATS0=0<ENTER>



Have fun!




Back to QBasic FAQ Index
Back to QBasic Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close