Software, examples and documentation written by Thomas P. Engel, M.D.
The library consists of five files:
SerialBytes.p
MECIFTypes.p
MECIF.p
MECIFExamples.p
TestMECIF.p
The library is organized in three layers. The lowest layer uses the Macintosh Serial Drivers to configure the Macintosh serial ports and send bytes to and receive bytes from the Component Monitoring System. This layer is in SerialBytes.p.
The middle layer composes outgoing messages, decodes incoming messages, checks for errors and dispatches messages to the high level procedures. This layer includes data structure definitions and procedures in the files MECIFTypes.p and MECIF.p.
The high level layer consists of user supplied procedures specific to the purpose of the user program. These procedures are registered in the Middle layer and called automatically at the appropriate time. The file MECIFExamples.p includes some examples of high level procedures. The file TestMECIF.p is a very simple main program that uses the library.
These are the pin connections for such a cable:
CMS pin 2 (TXD) to Macintosh pin 5 (RXD-)
CMS pin 3 (RXD) to Macintosh pin 3 (TXD-)
CMS pin 4 (RTS) to CMS pin 8 (DCD)
CMS pin 5 (CTS) and CMS pin 6 (DSR) to Macintosh pin 1 (HSKo)
CMS pin 7 (GND) to Macintosh pin 4 (GND) and Macintosh pin 8 (RXD+)
CMS pin 20 (DTR) to Macintosh pin 2 (HSKi)
CMS pin 22 (RI) unused
Macintosh pin 6 (TXD-) unused
CMS to Macintosh Cable Diagram
Configure the Component Monitoring System to Computer On, Baud Rate 38400 and TX/RX Order High/Low in the RS-232 Instrument Configuration screen.
Include the files Serial.p, SerialBytes.p, MECIFTypes.p and MECIF.p in your project in that compilation order. Serial.p is supplied by Apple Computer, Inc.
Your application program should call MECIFOpen when it starts and MECIFClose when it ends. It should also call MECIFTask periodically, at least 60 times per second. A way to do this is to place MECIFTask in the main event loop of your program and call WaitTNextEvent with a sleepTicks of zero.
To receive MECIF messages, install a message handler procedure by passing a pointer to the procedure to InstallHandler.
The message handler should have the form:
procedure MyMessageHandler(theMessage: MessageHandle);You may use any handle type in place of MessageHandle. The Macintosh MECIF library will call your handler whenever it receives a message with its command code and destination ID. You may remove a handler by calling RemoveHandler. You may replace a handler by calling InstallHandler with the same command code and destination ID and a different procedure pointer. Your message handler must dispose of the message it receives by calling DisposeMessage.
To send a message to the Component Monitoring System, create the message with NewMessage, fill in any message specific data and send it with WriteMessage. Dispose of the message with DisposeMessage. NewMessage initializes all fields of the message to zero.
Here is a simple program that sends and recives a mirror request:
program Test; uses Serial, SerialBytes, MECIFTypes, MECIF; const ClientID = 100; var theMessage: MirrorRequestHandle; finished: Boolean; procedure MirrorResponseHandler (theMessage: MirrorResponseHandle); { Handle a mirror response. } begin if theMessage <> nil then begin WriteLn('Mirror response: ', theMessage^^.mirror1, ', ', theMessage^^.mirror2); DisposeMessage(MessageHandle(theMessage)) end end; begin MECIFOpen; InstallHandler(MirrorResponse, ClientID, @MirrorResponseHandler); NewMessage(SizeOf(MirrorRequestRecord), DirectoryServerID, ClientID, MirrorRequest, MessageHandle(theMessage)); theMessage^^.mirror1 := 1; theMessage^^.mirror2 := 2; WriteLn('Mirror request: ', theMessage^^.mirror1, ', ', theMessage^^.mirror2); WriteMessage(MessageHandle(theMessage)); DisposeMessage(MessageHandle(theMessage)); repeat MECIFTask until Button; MECIFClose; end.Alternatively, you may set up a single reading loop to handle all MECIF messages received from the Component Monitoring System as the Hewlett-Packard example program does. In this case do not call InstallHandler, DispatchMessage or MECIFTask. Call ReadMessage in your reading loop directly.
The file Alternate.p contains a main program that uses this technique.