Page 1 of 1

COM PORTS 3 & 4

Posted: Tue Nov 20, 2012 4:42 pm
by Tony Amos
I need to access COM Ports ! through 4 in a program that allows me to use the OPEN COM statement. At one time there was some code posted here that showed how to force ports 3 & 4 to temprarily be 1 & 2 and then reverse back so that all 4 could have separate inputs/outputs. Any ideas? Also sorry, I forgot to put a subject header!

Posted: Wed Nov 21, 2012 12:26 am
by burger2227
This can only be done on older computers like a 98. Newer PC's block port access unless you use Port Talk.

Below a routine swaps COM1 and COM3:

Code: Select all

DEF SEG = 0 'DOS BIOS settings. QB will read COM1 with COM3 values
COM1L% = PEEK(&H400): COM1H% = PEEK(&H401)  'COM1 port values
COM3L% = PEEK(&H404): COM3H% = PEEK(&H405)  'COM3 port values
POKE &H400, COM3L%: POKE &H401, COM3H%    'change COM1 to COM3 settings
POKE &H404, COM1L%: POKE &H405, COM1H%    'change COM3 to COM1 settings
DEF SEG         'reset to default memory segment"
'To swap COM2 and COM4, with the same IRQ, use the swap routine below:

Code: Select all

DEF SEG = 0 'DOS BIOS settings. QB will read COM2 with COM4 values
COM2L% = PEEK(&H402): COM2H% = PEEK(&H403)  'COM2 port values
COM4L% = PEEK(&H406): COM4H% = PEEK(&H407)  'COM4 port values
POKE &H402, COM4L%: POKE &H403, COM4H%    'change COM2 to COM4 settings
POKE &H406, COM2L%: POKE &H407, COM2H%    'change COM4 to COM2 settings
DEF SEG         'reset to default memory segment"
To swap them back just change the values back the same way.