Macintosh MECIF Library

Revised 7 December 1996.

Software, examples and documentation written by Thomas P. Engel, M.D.

Introduction

This library allows an Apple Macintosh computer to capture patient information from a Hewlett-Packard Component Monitoring System equipped with a serial interface board. The Macintosh library is written in Pascal. The Macintosh library corresponds to the unparsed MS-DOS MECIF library written in C. The Macintosh library uses common Macintosh data types and record data structure definitions to decode the messages.

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.

Documentation

The text files README.DOC, COMMAND.DOC and SPI.DOC from Hewlett-Packard contain critical information on the format of MECIF messages and are required to to use this Macintosh library.

Using the Macintosh Library

The Component Monitoring System requires a special hardware handshake cable to connect to the Macintosh. The CMS uses a DB-25 connector and Macintosh uses a Mini DIN-8 connector. Both are configured DTE.

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.

Download the Macintosh MECIF Library

Click here to download the Macintosh MECIF Library and Documentation.

Macintosh Serial References

  1. Apple Computer, Inc.The Serial Drivers, Inside Macintosh, vol. II, p. 245, Reading, Addison-Wesley, 1985.
  2. Apple Computer, Inc.The Serial Driver, Inside Macintosh, vol. IV, p. 227, Reading, Addison-Wesley, 1986.
  3. Apple Computer, Inc. New Macintosh Technical Notes, Pinouts, Hardware, M.HW.Pinouts, April, 1985, revised July, 1985. Formerly Macintosh Technical Note #10.
  4. Apple Computer, Inc. New Macintosh Technical Notes, Macintosh Plus Pinouts, Hardware, M.HW.MacPlusPinouts, January, 1986, revised March, 1988. Formerly Technical Note #65.
  5. Apple Computer, Inc. New Macintosh Technical Notes, Opening the Serial Driver, Devices, M.DV.SerialDriver, December, 1989, revised August 1989. Formerly Technical Note #249.
  6. Apple Computer, Inc. New Macintosh Technical Notes, Serial I/O Port Q&As, Hardware, M.HW.Serial.Q&As, October, 1990, revised October, 1992.
  7. Apple Computer, Inc. New Macintosh Technical Notes, Serial Driver Q&As, Devices, M.DV.SerialDriver.Q&As, October, 1990, revised October, 1992.
  8. Scheiderich, Tom. Serial Port Demo. MacTutor, vol. 4, no. 6, June, 1988.
  9. Henriquez, Frank. Serial I/O. MacTutor, vol. 5, no. 7, July, 1989.
  10. Campbell, Joe. The RS-232 Solution: How to use your serial port. Second edition for PC and Macintosh. San Francisco, Sybex, 1989.

Tom's Macintosh Page | Tom's Picture | More Pictures | Curriculum Vitae | Abstracts | Interactive Books | Software | Advice to Companies | GASNet Anesthesiology Home Page
Macintosh MECIF Library / Thomas Engel, M.D. / tengel@aol.com