[comp.os.msdos.programmer] modem programming in BASIC

dmm0t@holmes.acc.Virginia.EDU (Dave Meyer) (06/19/91)

I'm trying to write a string to my modem in BASIC, but when
I try to open the COM port I get device timeouts.  I'm using
OPEN "COM1:9600,n,8,1" as #1
to get these timeouts.  I vaguely remember reading about this,
and there was a very simple solution to the problem.  Sadly,
I don't remember what it was.

Does anyone happen to remember how to open a COM port with
a modem attached?  If it matters, I have a USR HST 9600.

		Thanks,
				Dave
-- 
David M. Meyer                                   | dmm0t@virginia.edu
Department of Mechanical & Aerospace Engineering | (804) 924-7926
University of Virginia                           |

david@kessner.denver.co.us (David Kessner) (06/19/91)

In article <1991Jun18.175638.8957@murdoch.acc.Virginia.EDU> dmm0t@holmes.acc.Virginia.EDU (Dave Meyer) writes:
>I'm trying to write a string to my modem in BASIC, but when
>I try to open the COM port I get device timeouts.  I'm using
>OPEN "COM1:9600,n,8,1" as #1
>to get these timeouts.  I vaguely remember reading about this,
>and there was a very simple solution to the problem.  Sadly,
>I don't remember what it was.
>
>Does anyone happen to remember how to open a COM port with
>a modem attached?  If it matters, I have a USR HST 9600.
>
>David M. Meyer                                   | dmm0t@virginia.edu

I strongly reccomend that you don't access the modem in that way-- or
if you do, don't run it at anything above 1200 baud.  The reason why is
because you are going though DOS _and_ the BIOS.  The BIOS is pittifully
slow and putting DOn on top of that is asking for trouble.  The other reason
is that the DOS/BIOS routines are not intterupt driven, essentally giving
you a ONE byte buffer.  If you cannot read that byte before the next one
comes in then you will loose characters, and in BASIC this is highly possible.

The 'proper' way to access the serial ports in MS-DOS is to write a small
assembly language driver with an 'interface' to the language of choice (BASIC,
C, Pascal, etc).

Given that here is how I would access the modem using _your_ way.  (Please
keep in mind that I have not written in BASIC for five years.)  Anyway, I
would use the DOS 'mode' command to set the baud rate, parity, etc.  Then,
in BASIC I would open the file 'com1' for READ AND WRITE.  I don't believe 
that you can set the baud rate from the open command-- but I could be 
wrong.  At any rate, this method is only reliable at slow speeds and
is only useful when sending to a printer...

-- 
David Kessner - david@kessner.denver.co.us            |
1135 Fairfax, Denver CO  80220  (303) 377-1801 (p.m.) | Reunite PANGEA!
Compuserve?  Isn't that some sort of FIDO BBS?        |

resnicks@netcom.COM (Steve Resnick) (06/20/91)

In article <1991Jun19.060721.26616@kessner.denver.co.us> david@kessner.denver.co.us (David Kessner) writes:
>In article <1991Jun18.175638.8957@murdoch.acc.Virginia.EDU> dmm0t@holmes.acc.Virginia.EDU (Dave Meyer) writes:
>>I'm trying to write a string to my modem in BASIC, but when
>>I try to open the COM port I get device timeouts.  I'm using
>>OPEN "COM1:9600,n,8,1" as #1
>>to get these timeouts.  I vaguely remember reading about this,
>>and there was a very simple solution to the problem.  Sadly,
>>I don't remember what it was.
>>
>>Does anyone happen to remember how to open a COM port with
>>a modem attached?  If it matters, I have a USR HST 9600.
>>
>
>I strongly reccomend that you don't access the modem in that way-- or
>if you do, don't run it at anything above 1200 baud.  The reason why is
>because you are going though DOS _and_ the BIOS.  The BIOS is pittifully
>slow and putting DOn on top of that is asking for trouble.  The other reason
>is that the DOS/BIOS routines are not intterupt driven, essentally giving
>you a ONE byte buffer.  If you cannot read that byte before the next one
>comes in then you will loose characters, and in BASIC this is highly possible.
>

The BASIC interpreter (or compiler) uses an interupt driven asynch driver.
BASIC can talk at higher speeds than 1200 baud w/o polling. The problem here
is that of signals, since BASIC expects DSR to be active before allowing
communications. (This is according to my GW-BASIC user's manual)

To open the port, try this:

OPEN "COM1:9600,n,8,1,rs,ds,cd" as #1

This will keep basic from bitching....

>The 'proper' way to access the serial ports in MS-DOS is to write a small
>assembly language driver with an 'interface' to the language of choice (BASIC,
>C, Pascal, etc).
>
>Given that here is how I would access the modem using _your_ way.  (Please
>keep in mind that I have not written in BASIC for five years.)

I don't want to sound like an asshole or anything, but your absence from BASIC
shows. BASIC, BASICA, GWBASIC, IBM BASIC Compiler, and ALL of the MS BASIC and
QuickBASIC compilers have always worked this way.

SoapBox: On

Being a long time reader on the net, contributing here and taking there,
I have found that incorrect information can be more damaging than no
information at all.

SoapBox: Off

> Anyway, I
>would use the DOS 'mode' command to set the baud rate, parity, etc.  Then,
>in BASIC I would open the file 'com1' for READ AND WRITE.  I don't believe 
>that you can set the baud rate from the open command-- but I could be 
>wrong.  At any rate, this method is only reliable at slow speeds and
>is only useful when sending to a printer...
>

The DOS mode command is useless in this instance, since BASIC wants to
open the port itself, and initialize its parameters. OPEN "file" and
OPEN "COMn:" are treated differently. Also note that when BASIC is
dealing with a device, the device name MUST be preceded by a colon.


>David Kessner - david@kessner.denver.co.us            |
>1135 Fairfax, Denver CO  80220  (303) 377-1801 (p.m.) | Reunite PANGEA!
>Compuserve?  Isn't that some sort of FIDO BBS?        |
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Nah .... Fido has more class!
              

Really, I'm not trying to flame you. :)

- Steve

-- 
-------------------------------------------------------------------------------
        resnicks@netcom.com, steve@camphq, IFNA:        1:143/105.0, 
                 co moderator for comp.binaries.os2
 Real life: Steve Resnick. Chief Software Architect, Process Scientific, Inc
 Flames, grammar and spelling errors >/dev/null
 The Asylum OS/2 BBS - (408)263-8017 12/2400,8,1 - Running Maximus CBCS 1.2
-------------------------------------------------------------------------------