MEV

From Concept to Market

+44 161 477 1898

Support

DIO Device Driver Support

For more information e-mail . David Cooper

What is the Amplicon DIO Driver?

The Windows AMPDIO Drivers are Windows 32-bit (and x64) software drivers that support a range of Amplicon digital and analogue data acquisition cards. They consist of low-level drivers, a comprehensive application level Windows Dynamic link library (DLL) interface and example software. The software can handle most analogue and digital signal types. The drivers supports the following functional categories:

  • Digital I/O
  • Counter Timer Functions
  • Analogue Input
  • Analogue output

The drivers are fully compatible with all Windows operating systems.

The driver consists of two parts:

  • The low-level device driver
  • The wrapper / interface DLL.

The Windows Dynamic Link Library (DLL) contains over 50 functions and provides a common Applications Program Interface (API) to the supported boards. The library functions allow the boards to be easily applied to many different applications, and also provides an easy way of accessing the board's features. The 32-bit DLL can be used by any language that supports the Windows _stdcall calling convention. The programming interface for this DLL is detailed in chapter 5, with any later updates detailed in the README.TXT file installed in the DIO_CODE subdirectory.

The low-level drivers provide a common, low-level interface to supported cards in Windows. A complete description of this interface is given in the additional document AMPIOCTL.RTF that is installed into AMPDIO/DIO_CODE directory.

Example programs written in Microsoft Visual Basic, Borland Delphi and HP VEE are also provided.

Please note that the Dynamic Link Library is NOT compatible with National Instruments LabVIEW or LabWindows as LabVIEW C does not support Windows _stdcall calling convention.

The low-level device driver is different for NT family and 95 family platforms. In NT it is called AMPDIO.SYS and is a kernel mode driver. In 95 it is called AMPDIO.VXD and is a virtual machine.

The device driver(s) support an IOCTL interface that allow direct communication with amplicon hardware. Details of the IOCTL interface are given in 'Ampioctl.rtf' file installed as part of the DIO_TC source code. DIO_TC.DLL is a wrapper that translates the low-level IOCTL interface into the functional API detailed in the hardware instruction manual. The wrapper DLL is common to NT and 95 and its source code is supplied.

DLL Interface

Why is the DLL interface the way it is?

The wrapper DLL (DIO_TC.DLL) provides the same application interface (API) as the Amplicon's existing Windows 3.11 driver. This interface is detailed in the ampdio.pdf Instruction Manual supplied with the Amplicon AMPDIO driver. The DLL is an example of an interface to the Driver. The complete source of the DLL is provided as well as the executable version. It is likely that if you are trying to use the advanced features of the Amplicon DIO / Counter Timer cards you will need to modify the DLL to add your own functions.

  • The wrapper DLL is equivalent to the 16 bit version.
  • The device drivers provided support card(s) features.
  • The wrapper DLL is provided as an example of how to interface to the driver.
  • The wrapper DLL provides high level support for many card features.
  • The wrapper DLL does not support the bi-directional or strobed data transfer on the DIO ports as implement in the 16 bit DLL.

Using Interrupts - Interrupt Callbacks

The driver provides a mechanism that allows an external user supplied function to be called when an interrupt occurs. This is a very powerful mechanism. Using it, you can implement sophisticated interrupt routines without having to write a completely new interface to the low-level driver. Many languages support this callback method including Borland Delphi, Visual C and Visual Basic 5. Examples of how to use it are given with the Driver. Note that due to a new feature of Visual Basic 6 the interrupt callbacks can no longer be used in this language.

Using Interrupts Without Callbacks

As an alternative to the interrupt callback mechanism a none callback mechanism is also provided, which allows the main thread to poll the interface to see if data is ready. In some programming environments this is impossible to handle interrupt callbacks (e.g. HP Vee, Excel VBA). This none callback mechanism allows the full features of the cards to be used in these environments.

Transferring Buffers Under Interrupt Control

The driver supports a number of different buffered user interrupt functions that allow a user to read or write large buffers of information to the driver. The callback function is only called / or None Call back function ready when a buffer full of data has been read or another buffer full of data is required to be written. The functions allow the user to specify the interrupt source, the type of data transfer required and any other parameters required to specify where the data is to be read from or written to. They allow the driver to be used to acquire or playback multi-channel analogue ac signals.

Asynchronous Communications

Buffer transfer has not been implemented for mode 1 and mode 2 asynchronous communications using the 82C55. However, versions above 2.0 of the driver support mode 1 and mode 2 asynchronous communications using an ISR_READ_PPIC service which fetches one word at a time. #define ISR_READ_PPIC 6 // reads Port C of 82C55

With this service call back occurs with the contents of Port C pre-loaded. This enables you to determine whether to send or receive data during the interrupt service. The problem with this is the latency. There is about 140uS latency associated with the above operations. Limiting data rate to 5 KBytes / sec per channel.

A console application to demonstrate is available. To download a zip file containing the complete project right-click here. IE users "save target as", Netscape users "save link as".

I am considering further extending to the NT driver to support faster (160 Kbytes / sec) asynchronous communications with the 82C55 in modes 1 and 2. Is there any demand for this?

Your feedback appreciated . David Cooper

Microsoft C and C++

The DIO_TC.DLL was written in Microsoft Visual C++ 4.0 and complete source for the user DLL is supplied. Example console applications written in C are available for download. Please note that the function calls are case sensitive.

Microsoft Visual Basic 4, 5 and 6

Examples are supplied for Visual Basic as part of the driver installation. Note that due to a new feature of Visual Basic 6 the examples that rely on interrupt call back will no longer work. See Microsoft's MSDN article (Q198607), available in the download area. In order to use interrupts in Visual Basic 6 the non-callback methods will need to be used, see VBA.

Microsoft Visual Basic for Applications VBA

VBA is used by many Microsoft applications, such as Excel, Access. It is a subset of Visual Basic that can be used to add program functionality to spreadsheets or databases. Interrupts can be used using VBA using the none call back methods, see the following example.

Public Type DataArray
  DataBuf(250, 3) As Long
End Type
Sub RegBoardEx()

  Dim n As Byte
  Dim hBoard As Integer, hBoard30AT As Integer
  Dim BoardType As Integer

  Dim reply_ As Integer Dim buflen As Long
  Dim inthand As Integer

  hBoard = -1
  hBoard30AT = -1
  BoardType = 0

  ' search for right card
  For n = 0 To 5
   hBoard = registerBoardEx(n)
   If hBoard >= 0 Then
      BoardType = GetBoardModel(hBoard)
    If BoardType = 30 Then hBoard30AT = hBoard
    End If
  Next n

  ' if we found a PC30AT
  If hBoard30AT <> -1 Then
    ' set the card to be bipolar
    reply_ = AIOsetAllADCchanMode(ByVal hBoard30AT, 0, ALLBIPOLAR)
    ' generate a 1 KHz pulse train to drive conversions
    reply_ = TCgeneratePulse(ByVal hBoard30AT, X2, 1, 1000)
    ' set the timer to be the conversion source
    reply_ = AIOsetADCconvSource(ByVal hBoard30AT, 0, CNV_CT1)
    ' Set up a non callback interrupt to get 750 samples, 250 from
    ' each channel 0,1,2
    inthand = TCsetNCBufferUserInterruptAIO(ByVal hBoard30AT, ADC0, _
    inthand 750, False, ISR_READ_ADCS, 0, 7)
    ' Start the interrupts
    Reply = enableInterrupts(hBoard30AT)
    ' wait for the data to be ready
    If TCwaitNCBufferReady(hBoard30AT, inthandle, 2000) > 0 Then
      ' get the data
      reply_ = TCdriveNCBufferUserInterrupt(ByVal hBoard30AT, ByVal _
      inthand, databuf, buflen)
    End If
    ' Stop the interrupts
    disableInterrupts (hBoard30AT)
  End If

  ' free the card
  If hBoard30AT <> -1 Then FreeBoard hBoard30AT

End Sub

Borland C and C++

The DLL source can be compiled with Borland Visual C++ Version 4.0. The project file, 'DIO_TC.IDE', is supplied with the DIO_TC.DLL source to enable the DLL to be rebuild with Borland C++ if required. The resultant DLL is larger than the Microsoft one.

If you wish to use the supplied DLL as part of Borland C++ application you will need to regenerate the '.LIB' file as the one supplied is in Microsoft Visual C++ format. You can do this by using the Borland C++ IMPLIB utility.

Borland Delphi 3, 4 and 5

There are examples of how to use the driver in Delphi supplied as part of the driver. Note that the oscilloscope example uses a custom VCL component. If you wish to use this in Delphi 5, the source for this component is available in the download area.

Borland C Builder

To use the driver in Borland C++ Builder 5.0 you must do the following:

First Run IMPDEF utility to create a definition file for the DIO_TC.DLL

  IMPDEF dio_tc.def dio_tc.dll

then you must run the IMPLIB utility to create a library file

  IMPLIB dio_tc.lib dio_tc.def

then include the library file dio_tc.lib in your project using "add to project"
and add following line to the include section of the source files

  #include "dio_tc.h"

The driver can be used in Borland C Builder 3 but it is not as straight forward. One of our customers has used the driver and supplied us with details of how to use it. If you want more information please email us.

Hewlett Packard HP VEE

Examples of using the driver with HP VEE are supplied with the driver. There are also some more examples available in the download area. In addition, active X controls for the PCI230 and PCI260 cards will soon be available which simplify the use of these cards dramatically in HP VEE. If you want beta releases or more information, please contact us.

Recommended Books

If you are writing your own device driver I can recommend the following useful reference material

Writing Windows VxDs and Device Drivers
  By Karen Hazzah
  ISBN 0-87930-438-3
   
The Windows NT Device Driver Book
  By Art Baker
  ISBN 0-13-184474-1
   

and the following news group comp.os.ms-windows.programmer.vxd

Please let me know how you're getting on :-) . David Cooper