WFDB .NET Wrappers Notes

This package provides WFDB wrappers for .NET applications, using the P/Invoke
mechanism.  The wrappers allow use of the WFDB library functions from .NET
programs, on systems where the WFDB library is installed.  The wrappers should
be accessible from any .NET enabled language, and have been tested in C# and
Visual Basic.

.......................................................................

Requirements

All of the software required to create and use WFDB .NET applications is
freely available, open-source software.  Proprietary tools may be
substituted for some of the open-source tools if desired.

The WFDB .NET wrappers can be used on any operating system on which WFDB
and .NET are supported, including MS Windows, GNU/Linux, and Mac OS X.

To run precompiled applications that use the WFDB .NET wrappers, you will need
a WFDB dynamic library (http://www.physionet.org/physiotools/wfdb.shtml) for
your platform, and a .NET Runtime Environment for your platform.  Novell's
open-source implementation of .NET, Mono (http://go-mono.com/), is freely
available for MS Windows, GNU/Linux and Mac OS X.  Of course, on Windows, you
can also use the Microsoft framework.

To build applications that use the WFDB .NET wrappers, you must also have a
.NET compiler for your platform.  Suitable C# compilers include Mono's freely
available mcs (http://go-mono.com) on all platforms, and Microsoft's csc on
Windows.  Microsoft's Visual Basic.NET has also been tested with these
wrappers.

To build the WFDB .NET wrappers, you must also have an ANSI C compiler for your
platform.  The freely available GNU gcc (http://gcc.gnu.org/) is recommended
(also for compiling the WFDB library itself).  Other ANSI C compilers may also
work; please write to wfdb-swig@physionet.org and let us know what you discover
if you try another compiler.

_______________________________________________________________________


Usage


A Trivial Example Program in C#

This program translates the `atr' annotations for the record named in
its argument into an AHA-format annotation file with the annotator
name `aha'.

 using System;
 using Wfdb;

 public class example2 {
	
	 static void Main(string[] argv) {
		
 		WFDB_AnninfoArray an = new WFDB_AnninfoArray(2);
		WFDB_Annotation annot = new WFDB_Annotation();
		
		if (argv.Length < 1) {
			Console.WriteLine("usage: " + "fixme" + " record");
			Environment.Exit(1);
		}
		WFDB_Anninfo a = an.getitem(0);
		a.name = "atr"; a.stat = wfdb.WFDB_READ;
		an.setitem(0, a);
		a = an.getitem(1);
		a.name = "aha"; a.stat = wfdb.WFDB_AHA_WRITE;
		an.setitem(1,a);
		if (wfdb.annopen(argv[0], an.cast(), 2) < 0)
			Environment.Exit(2);
		while (wfdb.getann(0, annot) == 0 && wfdb.putann(0,annot) == 0)
			;
		wfdb.wfdbquit();
	}
 }

First, note that you must include the wfdb package with 'using Wfdb'.

The functions used in this example are described in detail in the WFDB
Programmer's Guide, all functions are methods of the "wfdb" class. For
now note that wfdb.annopen prepares a record to read by wfdb.getann,
which reads an annotation each time it is called. Also notice that
WFDB constants are also members of the "wfdb" class.

The WFDB data types are described in the WFDB Programmer's Guide.  In
C#, each WFDB structure is paired with an accessor class that allows
you to work with pointers to the native C structures in memory.  These
classes are often referred to as "shadow classes".

In addition, there are several 'Array' special classes, which are used
in place of pointer arrays in C.  Note that the 'cast' method must be
used when passing an 'Array' object to a method, as in

  wfdb.annopen(argv[0], an.cast(), 2)

The items in the 'Array' object can be accessed using the 'getitem'
and 'setitem' methods.  Special care must be taken when manipulating
the members of an array.  As shown in the example, you must first
obtain a shadow class object for an item using 'getitem', 

  WFDB_Anninfo a = an.getitem(0);

which can then be used to get or set structure members. 

  a.name = "atr"; a.stat = wfdb.WFDB_READ;

Take special note that you must use 'setitem' to copy your changes
back to the array. 

  an.setitem(0, a);

This may seem unintuitive, but remember that the Array classes only
manipulate underlying C structures.

.......................................................................

Compiling a C# Program with the WFDB Library

To compile the example program with Mono's mcs compiler, we can say:

 mcs -r:/usr/lib/mono/wfdb-csharp/wfdb-csharp.dll example2.cs

to produce a executable class called example2.exe. You may use any
other compiler options you choose, but you must reference the full path
of the wfdb-csharp.dll.

.......................................................................

Running a C# Program with the WFDB Library

Executable .NET programs have names with the suffix 'exe' on all platforms, not
only MS Windows.  Under MS Windows you can run them as you would any other
application. When using Mono, we can say:

 mono psamples.exe

Under GNU/Linux and Mac OS X, make sure the libwfdbsharpglue and libwfdb
dynamic libraries are stored in directories in your dynamic library load path
(LD_LIBRARY_PATH under GNU/Linux, DYLD_LIBRARY_PATH under Mac OS X). Under
Windows, the wfdb and wfdbsharpglue DLLs must be in your PATH (typically, in
the directory where the .exe files that use the DLLs are stored).
