[comp.sys.mac.programmer] Serial Port, Resources etc

ralph@computing-maths.cardiff.ac.uk (Ralph Martin) (05/09/88)

I am posting this for a friend, please reply to him not me!
========forwarded posting=========
Please reply to
 
Sak Wathanasin
 
uucp:     ...!ukc!kernel!sw
JANET:  sw%kernel.uucp@uk.ac.ukc
BITNET: sw%kernel.uucp%ukc.ac.uk@ukacrl.bitnet
other:    sw%kernel.uucp@ukc.ac.uk
phone:    (+44) 532 465311
snail:    Kernel Technology Ltd, 21 Queen Street, Leeds LS1 2TW
 
I've been trying to get a program to work as a background task under
MultiFinder. The problem is that I cannot find out if some other
program is already using the serial port. IM Vol 4 chp 22 says
"The new Serial Driver verifies that the serial port is correctly
configured and free; if not, the result code portNotCf or portInUse
is returned."
 
Well, as far as I can tell it does no such thing: with, e.g., kermit already
running in an MF partition, I open the serial port in my program,
and I get this:
 
Open input SERD returns: 0
Open output SERD returns: 0 innum = -6 outnum = -7
RAMSDOpen returns: 0
 
Here is a fragment of the LSC code I use:
 
err=OpenDriver("\p.AIn", &innum);
/* display err msg here */
err=OpenDriver("\p.AOut", &outnum);
/* display err no here */
err=RAMSDOpen(sPortA);        /* I need to run with 64K roms */
/* display error no */
 
You may say "why do you care? - just grab the port anyway".  Well, on quitting
my program I do a RAMSDClose as prescribed by Apple, and, boy, does kermit
(or whatever's using the port) get upset, and I don't blame it either. The
same thing happens to my program if you exit the other first, of course.
 
Now, I dug around IM some more, and found that the PRAM contains some info,
but this is simply the default startup configuration, and is not affected
by an application opening the serial port(s). Does anyone know how to tell
if a port is already in use, and if so, how to get the current port
configuration (baud rate etc)? More important, how can I stop some
other application from stealing the port from me?
 
I can't believe Apple didn't think about resolving requests for a scarce
resource (I use the term in the ordinary sense) when they introduced
MultiFinder, so how is it done?
 
On another tack: is there a way to use ResEdit to look at resources in ROM?
I played around for a bit, but gave up in the end, and wrote a little program
to read out what I wanted. Just wondered if there was an easier way....
 
Also, does anyone know what errors -4100, -4101 from the PAP driver mean?
 
Thanks in advance for any help,
 
Sak

han@Apple.COM (Byron Han, fire fighter) (05/14/88)

>I've been trying to get a program to work as a background task under
>MultiFinder. The problem is that I cannot find out if some other
>program is already using the serial port. IM Vol 4 chp 22 says
>"The new Serial Driver verifies that the serial port is correctly
>configured and free; if not, the result code portNotCf or portInUse
>is returned."

Well, the only arbitration is that if LocalTalk is active, portBUse is set
to signify that portB is in use by LocalTalk.  In fact, I believe if
any AppleTalk is active, portBUse is set to signify Appletalk is active.
This is because AppleTalk uses some low memory printer port serial driver
globals for AppleTalk globals.

Many applications (such as the much beloved AppleL*nk) are bad - they do
not close the serial driver when they are done.  

Always always always close the serial driver when your application terminates.

The fact that applications do not close the serial driver complicates
arbitration of the serial ports a great deal.  Arbitration would be nice.

The existing serial driver merely checks to see if the port is available.  if
the port has been already opened by the serial driver before, it allows it
and allocates new space for the buffers (losing the memory for the old
buffers in the process).  This is not good.  We know about it.
> 
>Well, as far as I can tell it does no such thing: with, e.g., kermit already
>running in an MF partition, I open the serial port in my program,
>and I get this:
> 
>Now, I dug around IM some more, and found that the PRAM contains some info,
>but this is simply the default startup configuration, and is not affected
>by an application opening the serial port(s). Does anyone know how to tell
>if a port is already in use, and if so, how to get the current port
>configuration (baud rate etc)? More important, how can I stop some
>other application from stealing the port from me?

You cannot at this time.  Sorry.

> 
>I can't believe Apple didn't think about resolving requests for a scarce
>resource (I use the term in the ordinary sense) when they introduced
>MultiFinder, so how is it done?

It isn't at this time.  Sorry.

> 
>On another tack: is there a way to use ResEdit to look at resources in ROM?
>I played around for a bit, but gave up in the end, and wrote a little program
>to read out what I wanted. Just wondered if there was an easier way....
> 

No.  There is no way to have ResEdit look at resources in ROM.  (as of 1.2a1)
Sorry.

>Also, does anyone know what errors -4100, -4101 from the PAP driver mean?

Here is what "geterrortext" in MPW returned:
Error -4100: Connection to printer closed
Error -4101: Printer not found or closed.

> 
>Thanks in advance for any help,

Sorry that I cannot help too much, but this is the best I can do.

-- 
Byron Han,  Communications Tool            "OS/2 - Half of an operating system."
Apple Computer, Inc. MS 27Y                -------------------------------------
ATTnet:408-973-6450     applelink:HAN1     domain:han@apple.COM       MacNET:HAN
GENIE:BYRONHAN    COMPUSERVE:72167,1664    UUCP:{sun,voder,nsc,decwrl}!apple!han