Porting NI-488.2 and NI-488 Applications Between Platforms and Operating Systems

Publish Date: Sep 06, 2006 | 7 Ratings | 3.71 out of 5 | Print | Submit your review

Overview

National Instruments has IEEE 488 Controller solutions for all popular computing platforms and operating systems. NI-488 software, an industry standard for GPIB Controller software, consists of a high-speed driver, language interfaces, configuration utilities, diagnostics, and interactive control utilities. The latest generation of NI-488 software, called NI-488.2, is completely compatible with the ANSI/IEEE 488.2-1987 Standard. NI-488 functions are a subset of the functions and routines provided in NI-488.2 software. Not only is NI-488.2 software compatible with NI-488, but it also works with both IEEE 488.1 and IEEE 488.2 instruments. For the purpose of this document, NI-488.2 refers to both the NI-488 and NI-488.2 family of drivers, unless otherwise specified.

NI-488.2 software is available for a wide range of GPIB hardware products, including plug-in boards for the PC/AT, MicroChannel (PS/2 and RS/6000), TURBOchannel, NuBus, and SBus, as well as external SCSI-to-GPIB, serial-to-GPIB, and Ethernet-to-GPIB Controller boxes. NI-488.2 drivers also work with all popular operating systems. One of the most striking features of NI-488.2 driver software is the ease of portability of applications from one computing platform to another. With this versatility, you can change platforms and not sacrifice the time you invested in development. The wide range of platforms and operating systems for which NI-488.2 hardware and software products are available offers you a large number of options in platform selection.

This document gives instructions so that you can create an NI-488.2 application in DOS, Windows, OS/2, UNIX, and the Macintosh operating system. It describes the design characteristics of the NI-488.2 driver that facilitate portability, and presents the NI-488 functions that are unique to the different operating systems. Finally, the document includes a C language NI-488.2 application that is portable across platforms.

Table of Contents

  1. Platforms, Operating Systems, and Compilers
  2. NI-488.2 Application and the NI-488.2 Driver Interaction
  3. Platform-Specific Functions
  4. Sample Program
  5. Summary

1. Platforms, Operating Systems, and Compilers

The range of platforms, operating systems, and compilers briefly discussed in this document is only a small representation of the extensive number of platforms compatible with the National Instruments NI-488.2 software. This document discusses these platforms because they are the most widely used. Table 1 summarizes the most widely used platforms and operating systems that work with the NI-488.2 software.

Table 1. Some Platforms, Operating Systems, and Compilers Compatible with NI-488.2 Software
Computing Platform
Operating System
Compiler
PCMS-DOS, Windows, OS/2Microsoft C
IBM PS/2MS-DOS, Windows, OS/2Microsoft C
Sun SPARCstationSolaris (Sun OS)cc
IBM RS/6000RS/6000 AIXcc
DECstation 5000ULTRIXcc
MacintoshSystem 6,7Think C


Porting NI-488.2 applications to other platforms involves similar steps to those outlined in this document. For more information regarding porting between platforms not addressed in this document, contact National Instruments.

Back to Top

2. NI-488.2 Application and the NI-488.2 Driver Interaction


Figure 1 represents how your NI-488.2 application interacts with the NI-488.2 driver.


Figure 1. Interaction between an NI-488.2 Application and the NI-488.2 Driver

The optional NI-488.2 language interface, available through National Instruments, links your application to the NI-488.2 driver. The NI-488.2 driver is part of the operating system on the host computer. The language interface references the driver entry points while the driver makes operating system calls to control the GPIB hardware.

The language interface consists of an include file that you place in your application program and an object file that you link with the compiled application code. The include file contains prototypes for the NI-488 functions and NI-488.2 routines as well as useful constant declarations. The object file contains references to the NI-488.2 driver entry points. The actual source code for the object file is distributed with the NI-488.2 software for UNIX, OS/2, and Macintosh. You can optionally purchase the source code to the object files for NI-488.2 for MS-DOS and Windows. Typically, you do not need the language interface source code unless you are using a compiler that is not directly compatible with NI-488.2 software.

When you are writing your application, the application acts like a module that is separate from the operating system or platform. Because the calling syntax and parameters of the NI-488 functions and NI-488.2 routines in this module are the same on most platforms, you only need to concentrate on developing the GPIB application. Once your application is complete, you can easily port the application source code from one platform to another by including the appropriate file and linking with the language interface.

Compiling with Microsoft C under MS-DOS
The NI-488.2 software for MS-DOS includes a language interface for Microsoft C and QuickC. Language interfaces for other MS-DOS compilers are available for purchase separately from National Instruments. The language interface consists of an include file called DECL.H and an object file called MCIB.OBJ. The include file contains useful variable and constant declarations as well as the prototypes of the NI-488 functions and NI-488.2 routines. The object file is derived from assembly language code that accesses the GPIB driver. To create an NI-488.2 application written in Microsoft C in DOS, perform the following steps:
  1. Insert the following C statement at the beginning of your application program:

    #include "decl.h"
  2. Link the file MCIB.OBJ with the compiled C source code of your application. The Microsoft C command that compiles the C source code file cprog.c and links it with the language interface object file is as follows:

    cl cprog.c mcib.obj

    This creates the file cprog.exe.
  3. To run the new file, enter the filename at the command line as follows:

    cprog.exe
    Compiling with Microsoft C under Windows
    The NI-488.2 software for Windows includes a generic C language interface for Microsoft C and Borland C. Language interfaces for other Windows compilers are available for purchase separately from National Instruments. The language interface is made up of an include file called WINDECL.H and an import library called GPIB.LIB. The include file contains useful variable and constant declarations as well as the prototypes of the NI-488 functions and NI-488.2 routines. The import library accesses GPIB.DLL, the NI-488.2 driver for Windows. To create an NI-488.2 application written in Microsoft C for Windows, perform the following steps:
    1. Insert the following C statement at the beginning of your application program:

      #include "windecl.h"
    2. Link the file GPIB.LIB with the compiled C source code of your application. The Microsoft C command that compiles the C source code file cprog.c and links it with the import library file is as follows:

      cl cprog.c gpib.lib

      This creates the file cprog.exe.
    3. To run the new file in Windows, select Run from the File menu.
    4. Enter cprog.exe.

    Compiling under OS/2
    OS/2 programs access NI-488 functions through an object file NI488.OBJ and an include file DECL.H. The source code to NI488.OBJ consists of NI488.C and the include files NICTL.H and NICODE.H. The NI-488 software for OS/2 distribution disks for the drivers up to version 1.4 contain all of these files. NI488.C contains source code that translates NI-488 functions to OS/2 Application Programming Interface (API) functions. With this interface to NI-488 functions, you can quickly port applications to the OS/2 environment because many NI-488 functions translate to multiple OS/2 API functions. The file DECL.H contains necessary interface statements as well as useful variable and constant declarations.
      Complete the following steps to create an NI-488 application in Microsoft C for OS/2:
      1. Include the following C statement at the beginning of your application program:

        #include "decl.h"
      2. Link the file NI488.OBJ with the C source code of your application. The Microsoft C command that compiles the C source code file cprog.c and links it with the language interface object file is as follows:

        cl cprog.c ni488.obj

        This creates the file cprog.exe.
      3. To run the new file, enter the file name at the command line as follows:

        cprog.exe

      Compiling under UNIX
      NI-488.2M is a subset of the family of NI-488.2 drivers. The M indicates the multitasking capability of the driver. The two files that make up the UNIX language interfaces for NI-488.2M drivers are cib.c and ugpib.h. The file cib.c contains the source code to the language interface. This file is the interface to the NI-488.2M driver; you have to compile and link it with your application. The file ugpib.h is an include file which contains useful constant declarations and prototypes for the NI-488 functions and NI-488.2 routines. Complete the following steps to create an NI-488.2M application in UNIX:
        1. Compile the language interface file cib.c. To do this, enter the following command at the UNIX prompt:

          cc -c cib.c

          An object file cib.o is created as a result.
        2. Include the following C statement at the beginning of the application program:

          #include "ugpib.h"
        3. Compile the application source code and link it with the object code derived from compiling cib.c. You can use the following command to compile a C source code file called cprog.c and link it with the language interface object file in the UNIX environment:

          cc cprog.c cib.o

          This command creates a file in the current working directory called a.out which is the executable GPIB application.
        4. To run the new file, enter the file name at the command line as follows:

          a.out

        Compiling under Macintosh Systems 6 and 7
        NI-488.2 for the Macintosh comes with a C language interface that recognizes Think C and MPW C. It consists of the files LI.c and decl.h. The file LI.c is a C source code file that contains the Macintosh system calls that interface to the NI-488.2 driver and control the GPIB hardware. The file decl.h is an include file that contains useful declarations and prototypes for NI-488 functions and NI-488.2 routines. Complete the following steps to create a GPIB application with Think C under Macintosh Systems 6 and 7:
          1. Open a project in Think C which includes the application source code file LI.c, ANSI, and MacTraps.
          2. Open the language interface file LI.c and add the following line at the beginning of the file:

            #define THINK

            You can use LI.c with Think C or MPW C. You must use the define statement to specify what compiler you are using. To write an MPW C application, use the following define statement:

            #define MPW
          3. Include the following C statement at the beginning of your application program:

            #include "decl.h"
          4. Create the application by selecting Build Application . . . under the Project menu. This creates an icon for your application.
          5. To run your application, double-click on the icon.

            Back to Top

            3. Platform-Specific Functions

          Some functions are not directly portable between platforms. If portability is a requirement, you should consider alternative implementations of the following functions because they are not portable across all platforms.

          Functions Specific to NI-488.2 for DOS, Windows, and Macintosh
          Asynchronous Functions
          The NI-488.2 drivers for DOS, Windows, and Macintosh have asynchronous input and output function calls. Asynchronous calls return control to the application program and process GPIB input or output using interrupts. Using asynchronous functions, you can execute non-GPIB I/O tasks in the application while completing GPIB I/O tasks. The NI-488.2 drivers for UNIX do not have asynchronous functions. In order to achieve asynchronous GPIB I/O, you must fork a child process from the application performing the GPIB I/O.

          Note: NI-488 software for OS/2 has ibrda, ibwrta, and so on, but these functions are executed synchronously.

          The ibsrq Function
          Using the SRQ interrupt routine ibsrq, you can register a routine that is called whenever the driver notices the SRQI bit set in the GPIB status variable ibsta (ibsta is updated after every NI-488.2 call). This function is typically issued at the beginning of your application. The NI-488.2 driver lets you know the SRQ line is asserted by setting the SRQI bit in the status word. When the SRQI bit is set and the ibsrq function is registered, the routine specified by the ibsrq function is executed. The ibsrq function works only with the NI-488.2 software for MS-DOS.

          Miscellaneous Functions and Routines
          The NI-488.2 software for DOS and Windows recognizes the following NI-488 functions and NI-488.2 routines. This document outlines these calls because they are not as frequently used as other calls:

          ibevent–This function detects and stores the sequence of clear and trigger events initiated by an external Controller in Talker/Listener applications.

          GenerateREQT and GenerateREQF–These routines request service and cancel requests for service (respectively).

          GotoMultAddr–This function simulates several devices with multiple primary addresses or one device with multiple secondary addresses.

          Functions Specific to NI-488.2M Software for UNIX
          The ibsgnl Function
          The NI-488.2M drivers for UNIX allow true hardware interrupts on GPIB events with the ibsgnl function. This function is used with the UNIX system call signal. First, the application issues a call to signal passing two parameters, the UNIX signal level and a function name. The signal function is called when the interrupt occurs. Next, the application issues a call to the NI-488M function ibsgnl passing two parameters, the unit descriptor for the GPIB interface and a mask variable that tells the driver under what conditions to generate an interrupt or signal. You cannot use the NI-488.2M function ibsgnl when using the GPIB-SCSI-A or GPIB-SCSI.

          The ibllo Function
          This function places a device in Local Lockout state which usually inhibits recognition of front panel input. Even though this function is exclusive to NI-488.2M drivers, you can implement any NI-488.2 driver using the ibcmd function.

          Back to Top

          4. Sample Program


          / * Sample program to control a National Instruments GPIB
          * device emulator. This program illustrates NI-488.2/NI-488
          * application portability. You can compile and run it on
          * all platforms supported by NI-488/NI-488.2 drivers
          * provided you use the correct language interface files.
          */

          #include <stdio.h>
          /* #include "decl.h" if using DOS, OS/2, or Macintosh */
          /* #include "windecl.h" if using Windows */
          /* #include "ugpib.h" if using UNIX */
          /* #define THINK if using THINK C for Macintosh */
          /* #define MPW if using MPW C for Macintosh */

          /* Application program variables passed to GPIB functions.
            */
          char rd[1024];   /* read data buffer          */
          int  emul; /* device handle             */
          char spr; /* serial poll response byte */
          char *msg; /* stores function           */

          main() {
          /* Assign unique identifier to the device and store in
          * variable emul. ibfind returns a negative value if an
          * error occurs.
           */
          if ((emul = ibfind ("dev1")) < 0) finderr();

          /* Clear the device.  Check for error on each GPIB call
          * to be safe.  Notice that GPIB status is available both
          * through global variable ibsta and through
          * the return values of all GPIB functions except IBFIND.
          */
          if (ibclr (emul) & ERR) {
          msg = "ibclr";
          error();
          }

          /* Write instructions to the emulator to make it assert
          * SRQ when it has finished generating a binary
          * encoded sinusoidal waveform.
          */
          if (ibwrt (emul,"G0 E0x40 W1",11L) & ERR) {
          msg = "ibwrt";
          error();
          }

          /* Wait for the emulator to set RQS or for a timeout.
            */
          if (ibwait (emul,TIMO|RQS)&(ERR|TIMO)) {
          msg = "ibwait";
          error();
          }

          /* Since neither a timeout nor an error occurred, ibwait
          * must have returned on RQS. Next serial poll the device.
          */
             if (ibrsp (emul,&spr) & ERR) {
          msg = "ibrsp";
          error();
          }
          /* Request 1 kilobyte of data from the emulator, it asserts
          * EOI when it sends its last data byte.
          */
          if (ibrd (emul,rd,1024L) & ERR) {
          msg = "ibrd";
          error();
          } else printf("Number of bytes read = %d\n",ibcnt);

          /* To close out a programming sequence, clear the device
          * again and call the ibonl function to disable the
          * hardware and software.
          */
          if (ibclr (emul) & ERR) error();
          if (ibonl (emul,0) & ERR) error();
          }

          finderr() {
          /* This routine would notify you that the ibfind call failed,
          * and refer you to the driver software configuration
          * procedures.
          */
          printf("Ibfind error; does device or board\n");
          printf("name given match configuration name?\n");
          exit();
          }

          error() {
          /* An error checking routine at this location checks iberr to
          * determine the exact cause of the error condition and then
          * takes action appropriate to the application.  For errors
          * during data transfers, you can examine ibcnt to determine
          * the actual number of bytes transferred.
          */
          printf("GPIB error on function %s\n",msg);
          printf("ibsta=0x%x, iberr=%d, ibcnt=%d\n\n",ibsta,iberr,ibcnt);
          msg = "";
          }

          Back to Top

          5. Summary


          The versatility of NI-488.2 software makes it easy for you to port your NI-488.2 and NI-488 applications between platforms and operating systems. By including the proper files in your application and linking it with the appropriate language interface, you can quickly and easily change platforms without sacrificing the investment you have made in development time.

          Back to Top

          Bookmark & Share


          Ratings

          Rate this document

          Answered Your Question?
          Yes No

          Submit