[comp.sys.mac.programmer] Using serial ports

brian@fog.ann-arbor.mi.us (Brian S. Schang) (05/10/90)

I would like to write a simple program that uses the modem port.  I have never
really programmed the Macintosh before, except for copying the programs in The
Macintosh Programming Primer (I think that's the name of it).  Are there any
books out there that have examples of using the serial ports?  Are there any
sample sources available via anonymous FTP?  What part(s) of Inside Mac should
I read carefully, and what technotes are applicable?  And finally, what is the
Communications Manager, and do I have to/should I worry about that?

Thanks in advance!
-- 
Brian S. Schang   N8FOG          brian@fog.ann-arbor.mi.us
46131 Academy Drive              schang@caen.engin.umich.edu
Plymouth, MI  48170-3519

kazim@Apple.COM (Alex Kazim) (05/10/90)

In article <1990May9.172145.1096@fog.ann-arbor.mi.us> brian@fog.ann-arbor.mi.us (Brian S. Schang) writes:
>I read carefully, and what technotes are applicable?  And finally, what is the
>Communications Manager, and do I have to/should I worry about that?
 ^^^^^^^^^^^^^^^^^^^^^^
AAARGGGGHHHHHHHH!!!!!!  Okay, once more with feeling, Communications Toolbox.
Connection Manager.  Communications Manager is an evil creation of that other
computer company.

What the Connection Manager does is to abstract the application from the low
level stuff.  Underneath the manager, sits connection tools that handle the
low level stuff for you.  

How it works:  
The app makes a call to read or write data.  The manager relays this to the
current tool, which takes care of talking to an associated driver.  The choice
of the tool is left up to the app, and in some instances, the user. 

The big win is that the same code will work regardless of whether you're using
a Serial Connection tool, an ADSP connection tool, or the newly announced
Telepathic Conn tool.

==========================================================================
Alex Kazim, Apple Computer
CommToolbox dude.
==========================================================================
 

chesley@goofy.apple.com (Harry Chesley) (05/10/90)

In article <1990May9.172145.1096@fog.ann-arbor.mi.us> 
brian@fog.ann-arbor.mi.us (Brian S. Schang) writes:
> Are there any
> books out there that have examples of using the serial ports?  Are there 
any> sample sources available via anonymous FTP?  What part(s) of Inside Mac 
should
> I read carefully, and what technotes are applicable?  And finally, what is 
the
> Communications Manager, and do I have to/should I worry about that?

Using the basic facilities of the serial ports is actually pretty simple: 
Just open the driver, configure the baud rate, etc. with SerReset, then do 
FSReads and FSWrites, perhaps checking SerGetBuf to see if there's 
anything to read. If you're receiving a lot of data without flow control, 
you may need to call SerSetBuf to increase the buffer size (if so, be sure 
to free the buffer before leaving the application).

Read Inside Mac II, chapter 9: The Serial Drivers. There is at least one 
recent tech note updating things (it suggests not using RAMSDOpen, for 
example). I'm afraid I don't recall the number off-hand (doesn't everyone 
have the tech note stack, so you can let your computer do the searching?).

The HyperCard Serial Port Toolkit includes full source code for XCMDs to 
control the serial ports. It's available for anonymous FTP from apple.com. 
Note, however, that it does some things which are more complicated than 
you'll probably need. (For example, it does asynchronous I/O when sending 
in order to get control back to HyperCard ASAP.) But any example in a 
storm, eh?

The Comm Toolbox may be overkill for what you want at this point, 
especially since you need to get it and install it specially. Eventually, 
it'll be part of the system, and then it'll make more sense to use it. It 
helps isolate you from the specific of the communication channel, makes it 
likely that your program will work with new channels (such as an add-on 
card with additional serial ports), and gives you a user interface for 
setting things like baud-rate, stop bits, etc.

In article <40843@apple.Apple.COM> kazim@Apple.COM (Alex Kazim) writes:
> What the Connection Manager does is to abstract the application from the low
> level stuff.

Note, however, that it abstracts you to the point where you can't get at 
it at all. For example, you can't read the CTS or DCD lines when using the 
Serial tool.