[comp.sys.mac.programmer] TN.249.Opening Serial Driver code in error.

earleh@eleazar.dartmouth.edu (Earle R. Horton) (09/08/89)

There is a problem with the example code supplied in Technote 249 for
opening the serial drivers.  Here is the relevent text, quoted from
the Technote.  (August, 1989 version)

>By using just the OpenDriver call to the serial driver, you ensure
>that your code is both user-friendly and compatible with future
>versions fo the System Software.
>
>Pascal
>
>	result := OpenDriver('AOut',AOutRefNum);  {Check result codes in a real application}
>	result := OpenDriver('AIn',AInRefNum);    {See failure mechanism in Sample Code    }
>
>C
>
>	result = OpenDriver('AOut',AOutRefNum);  /*Check result codes in a real application*/
>	result = OpenDriver('AIn',AInRefNum);    /*See failure mechanism in Sample Code    */
>

Driver names start with a period ('.').  The second parameter to
OpenDriver is a VAR integer parameter, or the address of a short int.
A Pascal compiler should catch the second error, but a C compiler
might not.  Neither compiler will catch the first.  The proper
spellings are aoutRefNum and ainRefNum, anyway.  The proper delimiters
for character strings in C are double quotes ('"').  Gosh, as long as
I am correcting things, proper English sentences end with a period ('.').

        /* See failure mechanism in Sample Code. */
                                               ^
There is at least one other error in the quoted text.

For maximum future compatibility, the driver names should be kept in
string resources or in a configuration file.  This is because in the
future more serial drivers may exist than the present two.  Then you
can instruct your customers that if they ever need to use ".DOut" they
can modify something to make this possible.  (This may also be
possible with third party add-on serial boards now.)  Likewise, the
constants [ab]{in,out}RefNum are probably not needed by most
application programs, since the Device Manager gives you a reference
number to use on a successful OpenDriver call.

By the way, the suggestion about the failure mechanism in Sample Code
is a very good one.  UFailure is designed for MPW Pascal and MPW C,
but I have been using it for some time now with Aztec C.  Porting to
other systems should be straightforward, as long as you have a means
of assembling 68000 assembler code.  UFailure allows you to define
exception handlers and to send yourself software signals when the
unexpected occurs.  It is much more useful at present than the partial
implementation defined in MPW C "signal.h."

Earle R. Horton