modula-2 home

  Home  
  Tutorial  
  Win32 API  
  Reference  
  Projects  
 

 

Interfacing GPIB Add-On Boards

by Shigeo Hayashi

This project uses XDS Modula-2 to interface GPIB Add-On Boards


Contec API-GPIB(98/PC)W95

1. Rewrite GpibAc.H to GpibAc.Def

You can do it with little difficulty. For a portion of the result, see the codes below.

<* +M2EXTENSIONS *>
<* +NOHEADER *>
<* +CSTDLIB *>
DEFINITION MODULE ["StdCall"] Gpibac;

IMPORT SYSTEM;
FROM Windows IMPORT DWORD, WORD, BYTE, HWND;

PROCEDURE ["StdCall"] GpIni(): DWORD;
PROCEDURE ["StdCall"] GpTalk(VAR cmd: ARRAY OF DWORD;
				   len: DWORD;
			       VAR str: ARRAY OF CHAR): DWORD;
......

2. Rewrite SubClass.H to SubClass.DEF and SubClass.MOD

The procedures therein are not of great importance.

3. Modify ApiGpib1.Lib

xlib /implib /useord ApiGpib1 ApiGpib1.DLL

This is necessary because MSVC .LIB files are in COFF format, whereas XDS uses OMF format.


National Instruments NI-488.2

Direct access to Gpib-32.DLL

1. Rewrite Gpib-32.H

Use the H2D utility to create h2d_Gpib_32.DEF using the project file below.

H2D (.h to .def) project file (gpib_32.h2d)
!header <*.h>
#define __stdcall
!end

Type in command line: h2d =p Gpib_32.h2d to obtain h2d_gpib_32.DEF

2. Get the run-time control procedures and status variables

See an example below.

TYPE
  Pf001 = PROCEDURE ["StdCall"] (SYSTEM.int,
                                 SYSTEM.int,
                             VAR SYSTEM.int ): SYSTEM.int;
VAR
  Gpib32Lib : Windows.HINSTANCE;
  Pibsta    : Windows.PINT;
  ibsta     : SYSTEM.int;
  ibask     : Pf001;
  i, ivalue : SYSTEM.int;
BEGIN
  Gpib32Lib := Windows.LoadLibrary("gpib-32.dll");
  IF (Gpib32Lib # NIL) THEN
    Pibsta := SYSTEM.CAST( Windows.PINT,
              Windows.GetProcAddress(Gpib32Lib, "user_ibsta") );
    ibsta  := Pibsta^;

    ibask  := SYSTEM.CAST(Pf001,
              Windows.GetProcAddress(Gpib32Lib, "ibask"));
    i      := ibask(0, h2d_Decl_32.IbaEOSchar, ivalue);
    WrStr(' ibask, status return = '); WrHex(ORD(i),2); WrLn;
    WrStr('      parameter value = '); WrInt(ivalue,1); WrLn;

The author thanks to Dmitry Leskov and Excelsior Support for help.

July 23, 2000 - Modified February 4, 2003