COM3 & COM4 in Quickbasic 
Author Message
 COM3 & COM4 in Quickbasic

How i can open files on COM3 and COM4 in QuickBasic?
Thanks.
--
--------------
Davide Zam



Tue, 23 Mar 1999 03:00:00 GMT  
 COM3 & COM4 in Quickbasic

Quote:

> How i can open files on COM3 and COM4 in QuickBasic?
> Thanks.

Darn it seems like I just posted this yesterday.
Come to think of it...it WAS yesterday.
Anyway here it is again.

QuickBasic does not directly support com3 and com4 but you can fake it by
reassigning the port addresses for com1 and/or com2 so QuickBasic thinks
it is opening say com1 when it is really opening com3.

It goes something like this.
Down in low memory at segment 0040 offset 0000 thru 0007 is where the BIOS
stores the base I/O address for com1 thru com 4.

If you start Debug and type d40:0 at the prompt the first line of the
output will look something like this.

0040:0000  F8 03 F8 02 E8 03 00 00-78 03 00 00 00 00 06 02   ........x....
           com1  com2  com3  com4

When Basic opens a com port it looks at the above addresses to determine
the base port address for the com port.
All you need to do is swap the F8 03 with the E8 03 so when basic trys to
open com1 it actually finds the base address for com3.

So you tell basic to open com1 and it thinks it did but it is really com3.

The following bit of code will swap the port addresses for com1 and com3.
It easy enough to change it for com2/com4 or whatever.

DEF SEG &H40
Com1LO = PEEK(0):Com1HI = PEEK(1)
Com3LO = PEEK(4):Com3HI = PEEK(5)
POKE 0, Com3LO: POKE 1, Com3HI
POKE 4, Com1LO: POKE 5, Com1HI
DEF SEG

--


Bangor, Pa. USA



Tue, 23 Mar 1999 03:00:00 GMT  
 COM3 & COM4 in Quickbasic

Quote:

>How i can open files on COM3 and COM4 in QuickBasic?
>Thanks.

Hi DZ!

1) Check the 10/2 and 10/3 posts for this group. Code on how to do
this was JUST posted here on those dates.

Ep
Ed Parry - Southern California, USA



Wed, 24 Mar 1999 03:00:00 GMT  
 COM3 & COM4 in Quickbasic

Quote:

> How i can open files on COM3 and COM4 in QuickBasic?
> Thanks.
> --
> --------------
> Davide Zam


'When you start your computer, of the many things it checks and
'keeps track of, is the presence and location of com ports.
'
'For each com port found, its number is sequentially stored in the
'bios data area starting at address &H400 to &H407.  Each port number
'occupy two bytes AS follows:
'
'     com 1   &H4000 to &H4001
'     com 2   &H4002 to &H4003
'     com 3   &H4004 to &H4005
'     com 4   &H4006 to &H4007

'in a PC/AT compatible machine the port numbers for the com ports are:
'
'     com1 = &H3F8
'     com2 = &H2F8
'     com3 = &H3E8
'     com4 = &H2E8
'  
'Since these port numbers are stored in the bios sequentially,
'if the computer has say, only 3 com ports  (1, 2 and 4), their
'port numbers will be stored from &H4000 to &H4005.
'In this case, the number stored at the address of com 3 will be
'&H2E8 which is for com 4, and at the address of com 4 will be 0.

'To open com3 or com4 in a programming language that can't open them
'directly, use com1 or com2 as aliases by:
'
' 1 - read and keep the port number stored at the alias's address.
' 2 - write the port number of the com you want to open at the
'     alias's address
' 3 - open the alias com port ( 1 or 2)...  do whatever you want...
'     when done, close the com port and...
' 4 - put back the original port number of the alias com port.

'QuickBasic  COM4  Example:

'This example uses com 2 as an alias for com 4.
'NB: This is just an illustration for opening of com4 as com2.
'    Opening, initializing and dialling details are more involving
'    than what is shown in this example for a Hayes compatible modem.
'  
'    The modem is physically set to com 4 and is using an IRQ that was
'    free before hooking it up to the computer.  Com port 2 is free.

DEFINT A-Z
CLS

'read the port numbers stored at the address of com 2
 DEF SEG = 0
 com2org = PEEK(&H402) + 256 * PEEK(&H403)

'write the com port number of com 4 to the address of com 2
 com4 = &H2E8
 POKE &H402, com4 AND 255
 POKE &H403, com4 \ 256

'now, open com 2 (but actually you are opening com 4)
 OPEN "COM2:9600,N,8,1" FOR RANDOM AS #1

'Initialize the modem
 PRINT #1, "at&fm2l3"
 SLEEP 1

'test by dialling some phone number (use your number ==> busy)
 PRINT #1, "atdt 8888888,,,"
 SLEEP 1

PRINT "Press any key to hangup the modem... "

DO
k$ = INKEY$
LOOP UNTIL k$ <> ""

'Hangup and close the com port  
 PRINT #1, "ath"
 SLEEP 1
 CLOSE #1

'****THIS IS IMPORTANT.
'put back the original port number at the address of com 2
   POKE &H402, com2org AND 255
   POKE &H403, com2org \ 256

END

'Disclaimer:
'
'This tip is provided on an "AS IS" basis.  You are responsible for
'any risks involved in using it.
'
'Have fun,



Sat, 27 Mar 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. COM3 and COM4 in QuickBasic

2. Com3 and Com4 from QuickBasic 4.5

3. PDS (Qbasic 7.1) and com3: & com4:

4. VBDOS and COM3 & COM4

5. Ports COM3,COM4 in Qbasic.

6. Supporting Com3 and Com4 in QBasic

7. Supporting Com3 and Com4 in QBasic

8. problem whith com3, com4

9. Accessing COM3 and COM4

10. Com3 in Quickbasic under Windows NT

11. MIDI & QuickBasic

12. QuickBasic 4.5 & Serial Port under Win9x

 

 
Powered by phpBB® Forum Software