#Serial Port Ownership
4 messages in this thread
Hi there – Anybody out there have a suggestion, or some code, as to
how I can detect if an application other than my own is using a
serial port? Right now the app I'm trying to fix just makes the
OpenDriver call and takes over the port from anything else that may
be using it in the background. Since all the supporting toolbox
routines seem to require the refNum from OpenDriver, I get the
feeling there's a system global I need to look at. Any help would be
much appreciated. Thanks.
In case anybody's interested, here's how I solved it: The Macsbug
Reference has a pretty good description of debugging and snooping
around device drivers with Macsbug. I basically used the Unit Table
address ($11C) to get at the DCE dCtlFlags field for the drivers in
question (.AIn, .AOut, .BIn, .BOut). I then tested bit 5, which
flags whether or not the driver is open. I sure hope there *isn't*
an easier way to do this, 'cause it took me all day yesterday to
figure it out :-). If anybody wants the code (MPW Pascal), let me
know and I'll email it to you.
Steve McDonnell
Epsilon, Inc.
You'll be happy to know that you figured out the current "right" way
to do it. To ensure that you're really clean, you should be scanning
through the unit table looking for a driver with the right name, not
just the right reference number.
There's a Mac Tech Note that alludes to this situation, but I think it
has more to do with whether a driver is installed as opposed to
whether it's open. But as you can tell, once you know the first part,
the second part is pretty easy to check.
"…you figured out the current "right" way to do it." Thanks, that's
good to know!
"To ensure that you're really clean, you should be scanning through
the unit table looking for a driver with the right name" Yup, good
point. That's a change I'll definitely make.