Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I NEED HELP WITH USING THE COM PORT IN QBASIC

Status
Not open for further replies.

N0NKU

Technical User
Dec 5, 2002
3
US
I AM TRYING TO ACCOMPLISH THE FOLLOWNG;

I WANT TO COMMUNICATE WITH A WIRELESS MODEM THAT USES RS232. I WOULD LIKE TO BE ABLE TO DISPLAY ON THE SCREEN WHAT THE MODEM IS SENDING OUT THE RS232 PORT IN REAL TIME. THE MODEM CAN SEND UP TO 20 LINES OF DATA.

I WOULD LKE TO BE ABLE TO SEND COMMANDS TO THE MODEM AS WELL, HOWEVER I WOULD LIKE TO BE ABLE TO TYPE MY COMMANDS LOCALLY AND SEE WHAT I AM TYPING BEFORE I SEND IT TO THE MODEM. I WOULD LIKE TO SEND THE DATA TO THE MODEM ONCE I PRESS ENTER.

PLEASE HELP.

THANKS
 
You probably won't be able to send anything to your wireless modem in qbasic, because it's wireless.
 
The Modem is wireless in that it makes it possible for you to send ascii over two way radio. The computer is connected to the modem via cable.
 
This should in theory not differ from talking to a regular line modem. As long as the wireless modem is connected to one of the standard COM ports, you can access the modem using [tt]PRINT[/tt] and [tt]LINE INPUT[/tt]. The following statement should allow you to access the modem if it is on COM1 with no parity, 8 bits per byte and 1 stop bit with a baud rate of 19200:
[tt]
f% = FREEFILE
OPEN
"COM1:19200,N,8,1" FOR RANDOM AS #f%
[/tt]
To send a command to the modem:
[tt]
PRINT #f%, "ATH" 'put the command here
[/tt]
To read a line of text from the modem (note that this will halt your program until a line of text is available):
[tt]
LINE INPUT #f%, newLine$
[/tt]
When you are done with the modem, you can close the connection to the COM port with: [tt]CLOSE #f%[/tt]
 
'MINIMAL TERMINAL By Antoni Gual 15/11/02
'Comms using PC's serial ports.

CONST TIMEOUT = .2 'receive timeout in seconds

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

CLS
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 Antoni
 
Well I tried both program examples and the second one does not send or receive. The first program sends to the modem just fine, but I am not receiving data from the modem, at least the data is being sent out the modem but is not being displayed on the computer screen.

PLEASE HELP

THANKS
 
Here's a little hack job I did back in my BBSing years. I assume it works. It seems similar to one of the examples already posted. If this code does not work, then your modem may not be following the RS232 specification correctly.
[tt]
DECLARE SUB prunt (a$)
OPEN "COM4:" FOR RANDOM AS #1
LOCATE , , 1, 14, 15
DO
IF LOC
(1) THEN
IF ABS
(TIMER - loctimer#) > .1 THEN
prunt INPUT$(LOC(1), 1)
loctimer# = TIMER
END IF
END IF

a$ = INKEY$: IF a$ <> &quot;&quot; THEN PRINT #1, a$;
LOOP UNTIL a$ = CHR$(0) + &quot;-&quot;

SUB prunt (a$)
FOR i% = 1 TO LEN(a$)
SELECT CASE MID$(a$, i%, 1)
CASE CHR$(13): LOCATE , 1
CASE CHR$(10): x% = POS(0): PRINT : LOCATE , x%
CASE CHR$(8): IF POS(0) - 1 THEN LOCATE , POS(0) - 1: PRINT &quot; &quot;: LOCATE , POS(0) - 1
CASE ELSE: PRINT MID$(a$, i%, 1);
END SELECT
NEXT
i%
END SUB
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top