/* ======================================================================== */
/*                                                                          */
/*               DASYLab - Data Acquisition Laboratory                      */
/*               =====================================                      */
/*                                                                          */
/* Interface definition between DASYLab and the hardware driver             */
/*                                                                          */
/* Copyright (c) 1992-94 by DATALOG GmbH, Moenchengladbach, Germany         */
/* All rights reserved.                                                     */
/*                                                                          */
/* Created     : R. Borghoff  02-APR-1992                                   */
/* Modified    : C. Strunk    03-JUN-1993  partly translated into english   */
/*               C. Strunk    21-APR-1994  finished translation             */
/*               C. Strunk    09-MAY-1994  Adapted to Interface Ver 0x10    */
/*                                                                          */
/* ======================================================================== */

#ifndef _TREIBER_H
#define _TREIBER_H

#include <WINDOWS.H>                         /* Import Typedefs for DWORD etc.                 */

/* We specify a definite packing for the following data structures */
#ifndef RC_INVOKED
#pragma pack(1)
#endif  /* RC_INVOKED */

#ifdef __cplusplus
extern "C" {            /* Assume C declarations for C++ */
#endif   /* __cplusplus */

#ifndef _TIME_T_DEFINED
typedef long    time_t;
#define _TIME_T_DEFINED
#endif 

/************** CONSTANTS    ****************/

/* Driver interface version number in DRV_INFOSTRUCT.Version */
#define DRV_VERSION           0x0010         /* Driver interface version (hardware driver)     */
#define DRV_VERSION_DEMO      0x8010         /* Driver interface version (demo driver)         */
#define SUPPORT_LEVEL         0              /* DASYLab's current support level                */

/* Return codes for most of the functions */
#define DRV_FUNCTION_OK       1              /* Ok. Everything worked well.                    */
#define DRV_FUNCTION_FALSE    0              /* An error occured. DRV_INFOSTRUCT.Error         */
                                             /* contains an error code now                     */
/* Dialog box codes (first parameter to DRV_ShowDialog) */
#define DRV_DLG_CARD_DEF      1              /* Show the 'Hardware Setup' dialog               */
#define DRV_DLG_CHANNEL_DEF   2              /* Show the 'Channel Setup' dialog                */
#define DRV_DLG_ABOUT         99             /* Show the 'Driver Info' dialog                  */

/* Acquisition modes for SupportedAcqModes and AcquisitionMode */
#define DRV_AQM_CONTINUOUS    0x00000001L    /* Continuous gap-free acquisition                */
#define DRV_AQM_BLOCK         0x00000002L    /* Gap after every ContinouosBlocks blocks        */
#define DRV_AQM_STOP          0x00000004L    /* Stop after capturing ContinouosBlocks blocks   */

/* Status bits as returned by DRV_GetMeasInfo */
#define DRV_MEASRUN           0x00010000L    /* Experiment is (still) running                  */
#define DRV_AI_OVRRN          0x00020000L    /* Input buffer overrun                           */
#define DRV_AO_BLOCKEND       0x00040000L    /* Ouput buffer overrun                           */
#define DRV_DATA_LOST         0x00080000L    /* Lost data (e.g. because of lost interrupts)    */

/* Input/Output range in AI_CHDEF.BaseUnit */
#define DRV_BASE_UNIT_U             0        /* Samples are unsigned short (zero for Min)      */
#define DRV_BASE_UNIT_2COMP         1        /* Samples are signed short (zero for 0.0)        */
#define DRV_BASE_UNIT_INV_U         2        /* Bit-Complement of DRV_BASE_U                   */
#define DRV_BASE_UNIT_INV_2COMP     3        /* Bit-Complement of DRV_BASE_2COMP               */
#define DRV_BASE_UNIT_FLOAT         4        /* Samples are IEEE 32bit float                   */

/* Flag values in AI_CHDEF.Flags */
#define AI_FLG_UNAVAILABLE           0x0001  /* This channel is not available                  */
                                             
/* Flag values in DI_CHDEF.Flags */
#define DI_FLG_UNAVAILABLE           0x0001  /* This channel is not available                  */
#define DI_FLG_PROG_DIRECTION        0x0010  /* This digital port supports software prg dir    */

/* Flag values in CT_CHDEF.Flags */
#define CT_FLG_UNAVAILABLE           0x0001  /* This channel is not available                  */
#define CT_FLG_NON_DESTRUCTIVE_READ  0x0010  /* Reading does not reset the counter value       */

/* Flag values in AO_CHDEF.Flags */
#define AO_FLG_UNAVAILABLE           0x0001  /* This channel is not available                  */

/* Flag values in DO_CHDEF.Flags */
#define DO_FLG_UNAVAILABLE           0x0001  /* This channel is not available                  */
#define DO_FLG_PROG_DIRECTION        0x0010  /* This digital port supports software prg dir    */

/* Error codes and warnings in DRV_INFOSTRUCT.Error */
#define DRV_ERR_OK            0x00           /* No error -- everything is fine.                */
#define DRV_ERR_NO386MODE     0x01           /* This driver can only be run in 386enh. mode    */
#define DRV_ERR_NOVDALOGD     0x02           /* The virtual device driver is missing           */
#define DRV_ERR_BUFSIZETOBIG  0x03           /* The driver buffer is too large                 */
#define DRV_ERR_NOCHANNEL     0x04           /* No channel has been specified                  */
#define DRV_ERR_DEVICENOTINIT 0x05           /* The driver is not initialized yet.             */
#define DRV_ERR_NOTENOUGHMEM  0x06           /* Out of memory                                  */
#define DRV_ERR_DLL2DEVICE    0x07           /* DLL + VxD driver don't fit together            */
#define DRV_ERR_OPENCOMX      0x08           /* Error opening the selected COM port            */
#define DRV_ERR_NOHWSUPPORT   0x09           /* No support for this hardware                   */
#define DRV_ERR_MEASRUN       0x0A           /* This function is not allowed during experiment */
#define DRV_ERR_CARDNOTFOUND  0x0B           /* No Hardware was found                          */
#define DRV_ERR_CHANGEGAIN    0x0C           /* Gain list had to be changed                    */
#define DRV_ERR_CHECKHARDWARE 0x0D           /* Installed hardware did not match the setup     */
#define DRV_ERR_WRONGVXD      0x0E           /* Wrong VxD driver                               */
#define DRV_ERR_HARD_CONFLICT 0x0F           /* Experiment could not start due to hardw. confl.*/
#define DRV_WARN_CHANGEFREQ   0x10           /* AI_Frequency had to be changed                 */
#define DRV_WARN_CHANGECHLIST 0x11           /* Channel list had to be changed                 */

/* Output mode in DRV_INFOSTRUCT.AO_Mode and DRV_INFOSTRUCT.DO_Mode */
#define DRV_OUT_CONTIMODE     0x00           /* Do continuous output                           */
#define DRV_OUT_BLOCKMODE     0x01           /* Do repeated block output of one block only     */

/* Flags for supported features in DRV_INFOSTRUCT.Features */
#define SUPPORT_DEFAULT       0x00000000L    /* Support default features */
#define SUPPORT_THERMOMEAS    0x00000002L    /* Support Thermo element + CJC measurement       */
#define SUPPORT_NO_SYNC_AO    0x00000004L    /* Don't support synchronous AO                   */
#define SUPPORT_NO_SYNC_DI    0x00000008L    /* Don't support synchronous DI                   */
#define SUPPORT_NO_SYNC_DO    0x00000010L    /* Don't support synchronous DO                   */
#define SUPPORT_NO_SYNC_CT    0x00000020L    /* Don't support synchronous CT                   */
#define SUPPORT_NO_ASYNC_AO   0x00000040L    /* Don't support asynchronous AO                  */
#define SUPPORT_AO_CONTIMODE  0x00000080L    /* Support continuous output                      */
#define SUPPORT_AO_BLOCKMODE  0x00000100L    /* Support repeated block output                  */
#define SUPPORT_ALT_COUNT     0x00000200L    /* Count channels starting from 1 instead of 0    */
#define SUPPORT_ENHANCED_DLG  0x00000400L    /* Support the 'Channel Setup' dialog             */
#define SUPPORT_NO_ADI_BUFFER 0x00001000L    /* Don't support a driver buffer                  */
#define SUPPORT_OUT_ALL       0x00002000L    /* Output all AO or DO channels simultaneously    */
#define SUPPORT_SLOW_CHANNELS 0x00004000L    /* Support slow channels that read one value/block*/
#define SUPPORT_NO_FAST_DI    0x00008000L    /* No fast digital input is possible              */
#define SUPPORT_NO_FAST_CT    0x00010000L    /* No fast Counter input is possible              */

/* Setup flags in DRV_INFOSTRUCT.HWSetup */
#define SETUP_THERMOMEAS      0x00000001L    /* Setup for CJC temperature measurement          */

/* The first parameter of DRV_ReadCounter, DRV_ReadDI, DRV_WriteAO, and DRV_WriteDO */
/* is the channel code computed by this macro. I.e. channel 0 has code 0x01,        */
/* channel 3 has code 0x08                                                          */
#define ChannelCode(ch) (1L<<(ch))

/* *** Scan list layout *** */

/* The SCAN_ENTRY type is used for items inside the scan list and for   */
/* the first parameter of the DRV_ExplainGainCode() function.           */

/* The scan list consists of unsigned short values */
typedef unsigned short SCAN_ENTRY;

/* Each scan list entry is an ORed combination of one type and one channel number   */
#define SCAN_TYPE(ent) ( ent & 0xF000 )
#define SCAN_CHAN(ent) ( ent & 0x0FFF )

/* The scan list may contain entries of the following types */
#define SCAN_TYPE_SPECIAL     0x0000         /* Special entry like dummy channel    */
#define SCAN_TYPE_AI          0x1000         /* Analog input channel                */
#define SCAN_TYPE_DI          0x2000         /* Digital input channel               */
#define SCAN_TYPE_CT          0x3000         /* Counter input channel               */

/* The following scan types are not used inside a scan list */
#define SCAN_TYPE_AO          0x4000         /* Analog input channel                */
#define SCAN_TYPE_DO          0x5000         /* Digital input channel               */


/************** TYPES ***********************/

typedef DWORD         HBUFFER;
typedef HBUFFER FAR * LPHBUFFER;

/* All data (analog, digital and counter) is transferred in the SAMPLE data type   */
/* which is a synonym to 'short' at the moment. Please do not use 'short' or 'int' */
/* types directly as we may eventually change this type in a future release of the */
/* interface. Write 'sizeof(SAMPLE)' instead of 'sizeof(int)' and so on.           */

typedef short          SAMPLE;
typedef unsigned short USAMPLE;
typedef SAMPLE _huge * LPSAMPLE;

/* Analog input channel specifications */
typedef struct
{
   double InputRange_Max;
   double InputRange_Min;
   DWORD  Resolution;
   UINT   Flags;
   UINT   BaseUnit;
   char FAR *Unit;
   UINT  __rsv[4];                     /* reserved for future use */
} AI_CHDEF;

/* Analog input channel setup */
typedef struct
{
   UINT  GainCode;
   DWORD DriverParam;
   UINT  __rsv[4];                     /* reserved for future use */
} AI_CHSET;

/* Digital input channel specifications */
typedef struct
{
   UINT Flags;
   UINT AvailBits;
   /* Parameters for software programmable direction */
   UINT DO_Chan;                                  /* Corrosponding DO channel */
   UINT GroupWidth;             /* Port width for ProgDir, i,e, 1, 4, 8, etc. */
   UINT  __rsv[2];                     /* reserved for future use */
} DI_CHDEF;

/* Digital input channel setup */
typedef struct
{
   UINT OutputBits;  /* Used with software programmable direction only */
   DWORD DriverParam;
   UINT  __rsv[2];                     /* reserved for future use */
} DI_CHSET;

/* Counter input channel specifications */
typedef struct
{
   UINT Flags;
   UINT  __rsv[2];                     /* reserved for future use */
} CT_CHDEF;

/* Counter input channel setup */
typedef struct
{
   DWORD DriverParam;
   UINT  __rsv[2];                     /* reserved for future use */
} CT_CHSET;


/* Analog output channel specifications */
typedef struct
{
   double OutputRange_Max;
   double OutputRange_Min;
   DWORD  Resolution;
   UINT   Flags;
   UINT   BaseUnit;       /* Currently unsupported; must be zero */
   char FAR *Unit;
   UINT  __rsv[4];                     /* reserved for future use */
} AO_CHDEF;

/* Analog output channel setup */
typedef struct
{
   UINT GainCode;           /* Currently unsupported; must be zero */
   DWORD DriverParam;
   UINT  __rsv[4];                     /* reserved for future use */
} AO_CHSET;

/* Digital output channel specifications */
typedef struct
{
   UINT Flags;
   UINT AvailBits;
   /* Parameters for software programmable direction */
   UINT DI_Chan;                                  /* Corrosponding DI channel */
   UINT  __rsv[2];                     /* reserved for future use */
} DO_CHDEF;

/* Analog output channel setup */
typedef struct
{
   DWORD DriverParam;
   UINT  __rsv[2];                     /* reserved for future use */
} DO_CHSET;

/* Hardware component section */
typedef struct
{
   double MaxSumFrequency;
   double MaxSingleFrequency;
   UINT FirstChan;
   UINT FirstChanLabel;
   UINT NumChannels;
   UINT Grouping;
   int FAR *GainInfo;
   UINT Flags;                         /* Currently unused; must be zero */
   UINT  __rsv[7];                     /* reserved for future use */
} HW_SECTION;

/* Hardware component */
typedef struct
{
   char ShortName[20];
   char LongName[64];
   HW_SECTION AI;
   HW_SECTION DI;
   HW_SECTION CT;
   HW_SECTION AO;
   HW_SECTION DO;
   UINT Flags;                         /* Currently unused; must be zero */
   UINT  __rsv[7];                     /* reserved for future use */
} HW_COMPONENT;


/* What follows is the main interface structure */
/* Data flow: '>' == to TREIBER.DLL; '<' == from TREIBER.DLL */

typedef struct
{
   /* Part 1: Identification of hardware and driver */
   UINT   Version;                /* >  Driver interface version number                        */
   UINT   SupportLevel;           /* >  Level of supported features                            */
   DWORD  Error;                  /*  < Last error code                                        */
   char   DriverName[60];         /*  < Internal driver name                                   */
   char   DeviceName[20];         /*  < Name of device as displayed in the experiment setup dlg*/
   DWORD  Features;               /*  < Features supported by the driver                       */
   DWORD  ReservedForFutureUse;   /*  < currently unused / don't touch this                    */
   LPSTR  DLL_Version;            /*  < String in format "Version/Date" for the DLL driver     */
   LPSTR  VxD_Version;            /*  < String in format "Version/Date" for the VxD driver     */
   LPSTR  INIFileName;            /*  < Name of INI file for this driver                       */
   LPSTR  HelpFileName;           /*  < Hardware help file name                                */
   UINT   HelpIndex;              /*  < Main entry point in help file                          */

   /* Part 2: General hardware parameters */
   double MinFreq;                /*  < Lowest possible AI sum frequency                       */
   double MaxFreq;                /*  < Highest possible AI sum frequency                      */
   double MaxContFreq;            /*  < Highest possible AI sum frequency for continuous Acq.  */

   UINT   Max_AI_Channel;         /*  < Number of supported analog input channels              */
   UINT   Max_DI_Channel;         /*  < Number of supported digital input channels             */
   UINT   Max_AO_Channel;         /*  < Number of supported counter input channels             */
   UINT   Max_DO_Channel;         /*  < Number of supported analog output channels             */
   UINT   Max_CT_Channel;         /*  < Number of supported digital output channels            */

   UINT   DIO_Width;              /*  < Max number of bits per DI/DO channel; typically 16     */
   int    GainInfo[32];           /*  < Gain factors for up to 32 gain codes                   */

   AI_CHDEF AI_ChInfo[512];       /*  < Parameters of the analog input channels                */
   DI_CHDEF DI_ChInfo[32];        /*  < Parameters of the digital input channels               */
   CT_CHDEF CT_ChInfo[32];        /*  < Parameters of the counter input channels               */
   AO_CHDEF AO_ChInfo[32];        /*  < Parameters of the analog output channels               */
   DO_CHDEF DO_ChInfo[32];        /*  < Parameters of the digital output channels              */

   DWORD ScanListFeatures;        /*  < Scan list features; 0 == no scan list support          */
   UINT ScanListMinLen;           /*  < Scan list minimum length (typically 0 or 1)            */
   UINT ScanListMaxLen;           /*  < Scan list maximum length                               */

   DWORD MaxContinuousSamples;    /*  < Max. samples that can be captured gap-free or 0        */

   UINT NumHardwareComponents;    /*  < Number of installed hardware components                */
   HW_COMPONENT FAR *HW_Comp;     /*  < List of hardware components                            */

   DWORD SupportedAcqModes;       /*  < ORed combination of all supported acquisition modes    */

   /* Part 3: Experiment setup */
   double AI_Frequency;           /* >< Acquisition frequency == AI sum frequency              */
   DWORD  DI_FreqRate;            /* >  DI Rate  ==  AI_Sum_Frequency / DI_Sum_Frequency       */
   DWORD  CT_FreqRate;            /* >  CT Rate  ==  AI_Sum_Frequency / CT_Sum_Frequency       */
   DWORD  AO_FreqRate;            /* >  AO Rate  ==  AI_Sum_Frequency / AO_Sum_Frequency       */
   DWORD  DO_FreqRate;            /* >  DO Rate  ==  AI_Sum_Frequency / DO_Sum_Frequency       */

   WORD   AI_Channel[32];         /* >  AI channels to acquire synchonously                    */
   DWORD  DI_Channel;             /* >  DI channels to acquire synchonously                    */
   DWORD  CT_Channel;             /* >  CT channels to acquire synchonously                    */
   DWORD  AO_Channel;             /* >  AO channels to output synchonously                     */
   DWORD  DO_Channel;             /* >  DO channels to output synchonously                     */

   DWORD  AI_AsyncChannel[32];    /* >  AI channels to acquire asynchonously                   */
   DWORD  DI_AsyncChannel;        /* >  DO channels to acquire asynchonously                   */
   DWORD  CT_AsyncChannel;        /* >  CT channels to acquire asynchonously                   */
   DWORD  AO_AsyncChannel;        /* >  AO channels to output asynchonously                    */
   DWORD  DO_AsyncChannel;        /* >  DO channels to output asynchonously                    */
   
   DWORD  AcquisitionMode;        /*  < Mode of data acquisition                               */

   DWORD  DriverBufferSize;       /* >< WORD count: Total size of the driver buffer            */
   DWORD  ADI_BlockSize;          /* >  WORD count: Size of a transfer block returned by the   */
                                  /*                DRV_GetBuf() function                      */
   DWORD  MaxBlocks;              /* >  Number of ADI_BlockSize blocks to acquire before stop  */
                                  /*    0 = infinite                                           */
   LPSAMPLE AO_BufferAdr;         /* >  Analog output buffer address                           */
   DWORD  AO_BufferSize;          /* >  Analog output buffer size                              */
   DWORD  AO_StartDelay;          /* >  Analog ouput cycles to wait before starting            */
   UINT   AO_Mode;                /* >  Analog output mode: 0 = continuous, 1 = block cycle    */

   LPSAMPLE DO_BufferAdr;         /* >  Digital output buffer address                          */
   DWORD  DO_BufferSize;          /* >  Digital output buffer size                             */
   DWORD  DO_StartDelay;          /* >  Digital ouput cycles to wait before starting           */
   UINT   DO_Mode;                /* >  Digital output mode: 0 = continuous, 1 = block cycle   */

   AI_CHSET AI_ChSetup[512];      /*  < Setups for the analog input channels                   */
   DI_CHSET DI_ChSetup[32];       /*  < Setups for the digital input channels                  */
   CT_CHSET CT_ChSetup[32];       /*  < Setups for the counter input channels                  */
   AO_CHSET AO_ChSetup[32];       /*  < Setups for the analog output channels                  */
   DO_CHSET DO_ChSetup[32];       /*  < Setups for the digital output channels                 */
   DWORD  HWSetup;                /* >  Hardware setup, like CJC measurement enable            */

   UINT ScanListLength;           /* >  Current scan list length                               */
   SCAN_ENTRY FAR *ScanList;      /* >  The scan list; available only if length > 0            */
   UINT ScanListMaxGroupSize;     /* >  Maximum number of items to be done at the same time    */
   
   time_t StartOfExperiment;      /*  < Start date/time of experiment (if specified)           */

   /* Part 4: Communication during experiment */
   long   CJValue;                /*  < Cold Junction temperature in 1/10 DegC                 */
   char   Message[12];            /*  < Driver message to be displayed inside the status bar   */
   DWORD  ADI_PercentFull;        /*  < Info on how full the buffer is                         */
   DWORD  AO_Counter;             /* >< Analog output counter                                  */
   DWORD  DO_Counter;             /* >< Digital output counter                                 */

   /* Part 5: Space for the driver to save parameters with the flow chart */
   char   DriverParam[100];       /* >< Space for the driver to store flow chart specific data */

   /* Part 6: Room for future extensions */
   DWORD  NoFunction[50];         /*    Reserved for future use */
} DRV_INFOSTRUCT;




/************** External callback functions **********/


/* ------------------------------------------------------------------------ */
/* Function     : DRV_AllocADIBuffer                                        */
/* Description  : Change the size of the input buffer                       */
/* Parameters   : nSamples: New size in WORDs                               */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong (out of mem)    */
/* Calling      : This may be called at any time. Please note that there is */
/*              : no DRV_FreeADIBuffer function. So AllocADIBuffer should   */
/*              : free the old buffer first before allocating a new one.    */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_AllocADIBuffer(DWORD nSamples);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_AllocDADIOBuffer                                      */
/* Description  : Allocate an output buffer                                 */
/* Parameters   : nSamples: Size in WORDs                                   */
/*              : lphBuf: Pointer to a space to store a handle. This handle */
/*              : will later be used to free the buffer again               */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong (out of mem)    */
/* Calling      : This may be called at any time. DASYLab may allocate more */
/*              : than one output buffer. In contrast to AllocADIBuffer, we */
/*              : do have a free function here.                             */
/* ------------------------------------------------------------------------ */

LPSAMPLE FAR PASCAL DRV_AllocDADIOBuffer(DWORD nSamples, LPHBUFFER lphBuf);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_ExplainGainCode                                       */
/* Description  : Convert gain code into a range string                     */
/* Parameters   : Chan: Channel number in SCAN_ENTRY coding                 */
/*              : GainCode: The code to convert                             */
/* Return Value : string explaining the input range or                      */
/*              : NULL in case of error                                     */
/* Calling      : This may be called at any time, but only if the flag      */
/*              : SUPPORT_EXPLAIN_GAIN is set. DASYLab will show these      */
/*              : strings inside the 'input range' list of the ADC box.     */
/* ------------------------------------------------------------------------ */

char FAR *FAR PASCAL DRV_ExplainGainCode(SCAN_ENTRY Chan, UINT GainCode);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_GetBuf                                                */
/* Description  : Return a pointer to a buffer of new input data            */
/* Parameters   : None.                                                     */
/* Return Value : Pointer to buffer (always)                                */
/* Calling      : After DRV_GetBufStatus did return TRUE, the DRV_GetBuf    */
/*              : function will be called to retrieve the data. DRV_GetBuf  */
/*              : must always return a valid pointer after DRV_GetBufStatus */
/*              : returned TRUE, so this function can never return NULL.    */
/* ------------------------------------------------------------------------ */

LPSAMPLE FAR PASCAL DRV_GetBuf(void);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_GetBufStatus                                          */
/* Description  : Test if input data are waiting to be processed            */
/* Parameters   : None.                                                     */
/* Return Value : DRV_FUNCTION_FALSE = less than InfoStruct->ADI_BlockSize  */
/*              :                      WORDS are waiting in the buffer      */
/*              : DRV_FUNCTION_OK otherwise                                 */
/* Calling      : DRV_GetBufStatus will be continuously called while the    */
/*              : experiment is running. Every time it returned TRUE, the   */
/*              : DRV_GetBuf function will then be called, the data be      */
/*              : processed, and after that a call to DRV_SetBufFree is     */
/*              : made.                                                     */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_GetBufStatus(void);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_GetMeasInfo                                           */
/* Description  : Get status (running, lost interrupts, etc.) of experiment */
/* Parameters   : None.                                                     */
/* Return Value : ORed combination of flags or Zero if no flag is set       */
/* Calling      : DRV_GetMeasInfo will be continuously called while the     */
/*              : experiment is running.                                    */
/* ------------------------------------------------------------------------ */

DWORD  FAR PASCAL DRV_GetMeasInfo(void);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_InitDevice                                            */
/* Description  : General setup for the hardware driver                     */
/* Parameters   : lpDRV_InfoStruct pointer to a DRV_InfoStruct variable in  */
/*              : the calling program's data space. The calling program     */
/*              : only sets the 'Version' member before the call.           */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong                 */
/* Calling      : DRV_InitDevice is the very first function called.         */
/*              : It checks the version number for correctness and then it  */
/*              : fills up the DRV_InfoStruct structure for the calling     */
/*              : program. If the driver uses ADI buffering, a default size */
/*              : buffer is also allocated here.                            */
/* Hints        : The driver saves the adress of the DRV_InfoStruct in a    */
/*              : local variable for later communication with the calling   */
/*              : program.                                                  */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_InitDevice(DRV_INFOSTRUCT FAR *lpDRV_InfoStruct);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_AllocDADIOBuffer                                      */
/* Description  : Release an output buffer                                  */
/* Parameters   : hBuffer: Buffer handle as returned by DRV_AllocDADIOBuffer*/
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong                 */
/* Calling      : This may be called at any time. DASYLab may allocate more */
/*              : than one output buffer. In contrast to AllocADIBuffer, we */
/*              : do have a free function here.                             */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_KillDADIOBuffer(HBUFFER hBuffer);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_KillDevice                                            */
/* Description  : Prepare for system exit                                   */
/* Parameters   : None.                                                     */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong                 */
/* Calling      : This will be called at the very end, just before DASYLab  */
/*              : exits.                                                    */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_KillDevice(void);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_ReadCT                                                */
/* Description  : Asynchronous Counter/Timer input                          */
/* Parameters   : ChanCode: Code of channel to read                         */
/*              : lpResult: Pointer to a DWORD where to put the result      */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong                 */
/* Calling      : This may be called only if counter channels are present,  */
/*              : but the SUPPORT_NO_SYNC_CT flag is set in the features.   */
/*              : In that case the function will be called asynchronously   */
/*              : from time to time.                                        */
/* Caution      : Instead of passing the channel directly to this function, */
/*              : DASYLab passes ChanCode(channel) as the first parameter.  */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_ReadCT(DWORD ChanCode, LPDWORD lpResult);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_ReadDI                                                */
/* Description  : Asynchronous digital input                                */
/* Parameters   : ChanCode: Code of channel to read                         */
/*              : lpResult: Pointer to a DWORD where to put the result      */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong                 */
/* Calling      : This may be called only if digital channels are present,  */
/*              : but the SUPPORT_NO_SYNC_DI flag is set in the features.   */
/*              : In that case the function will be called asynchronously   */
/*              : from time to time.                                        */
/* Caution      : Instead of passing the channel directly to this function, */
/*              : DASYLab passes ChanCode(channel) as the first parameter.  */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_ReadDI(DWORD ChanCode, LPDWORD lpResult);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_SetBufFree                                            */
/* Description  : Tell Driver that the last data block is no longer needed  */
/* Parameters   : None.                                                     */
/* Return Value : DRV_FUNCTION_OK always                                    */
/* Calling      : DRV_GetBufStatus will be continuously called while the    */
/*              : experiment is running. Every time it returned TRUE, the   */
/*              : DRV_GetBuf function will then be called, the data be      */
/*              : processed, and after that a call to DRV_SetBufFree is     */
/*              : made. At the time the driver DRV:SetBufFree function is   */
/*              : called, the data block processing is complete, so the     */
/*              : space can now be re-used for new data.                    */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_SetBufFree(void);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_ShowDialog                                            */
/* Description  : Show a driver specific dialog box                         */
/* Parameters   : DlgNumber: Number of the dialog; e.g. DRV_DLG_CARD_DEF    */
/*              : lParam: Dialog-specific data (if needed)                  */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong                 */
/* Calling      : This may be called from time to time. Currently DASYLab   */
/*              : will not call this function while the experiment is       */
/*              : running, but we may eventuelly change this in the future  */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_ShowDialog(UINT DlgNumber, DWORD lParam);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_ShowError                                             */
/* Description  : Show an error dialog box                                  */
/* Parameters   : None. The error code in DRV_InfoStruct.Error is used to   */
/*              : show the corrosponding error box.                         */
/* Return Value : always DRV_FUNCTION_OK                                    */
/* Calling      : After a driver function returned DRV_FUNCTION_FALSE the   */
/*              : calling program may call DRV_ShowError to display an      */
/*              : error box on the screen. DRV_ShowError also resets the    */
/*              : DRV_InfoStruct.Error component to zero.                   */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_ShowError(void);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_StartMeas                                             */
/* Description  : Start the experiment                                      */
/* Parameters   : None.                                                     */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong                 */
/* Calling      : DASYLab will always call DRV_TestStruct before calling    */
/*              : DRV_StartMeas.                                            */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_StartMeas(void);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_StopMeas                                              */
/* Description  : Stop the experiment                                       */
/* Parameters   : None.                                                     */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong                 */
/* Calling      : DASYLab will call this function on the stop or pause case */
/*              : The driver should *not* flush it's buffers here, but only */
/*              : stop data acquisition. The remaining dada in the buffer   */
/*              : may still be processed by DASYLab even after calling      */
/*              : DRV_StopMeas.                                             */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_StopMeas(void);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_TestStruct                                            */
/* Description  : Test and correct integrity of InfoStruct                  */
/* Parameters   : None.                                                     */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong or some values  */
/*              :     inside the InfoStruct had to be changed.              */
/* Calling      : DASYLab will call this function at start of experiment    */
/*              : and in other cases, such as after loading a flow chart,   */
/*              : after changes were made in the analog input setup etc.    */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_TestStruct(void);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_WriteAO                                               */
/* Description  : Asynchronous analog output                                */
/* Parameters   : ChanCode: Code of channel to read                         */
/*              : OutVal: Value to output                                   */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong                 */
/* Calling      : This will be called if the user activates ascnchronous    */
/*              : analog output.                                            */
/* Caution      : Instead of passing the channel directly to this function, */
/*              : DASYLab passes ChanCode(channel) as the first parameter.  */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_WriteAO(DWORD ChanCode, DWORD OutVal);

/* ------------------------------------------------------------------------ */
/* Function     : DRV_WriteDO                                               */
/* Description  : Asynchronous digital output                               */
/* Parameters   : ChanCode: Code of channel to read                         */
/*              : OutVal: Value to output                                   */
/* Return Value : DRV_FUNCTION_OK    = everything is fine                   */
/*              : DRV_FUNCTION_FALSE = something went wrong                 */
/* Calling      : This will be called if the user activates ascnchronous    */
/*              : digital output.                                           */
/* Caution      : Instead of passing the channel directly to this function, */
/*              : DASYLab passes ChanCode(channel) as the first parameter.  */
/* ------------------------------------------------------------------------ */

int FAR PASCAL DRV_WriteDO(DWORD ChanCode, DWORD OutVal);

/*********************************/

#ifdef __cplusplus
}                       /* End of extern "C" { */
#endif   /* __cplusplus */

/* Switch back to default packing */
#ifndef RC_INVOKED
#pragma pack()
#endif  /* RC_INVOKED */

#endif /* ! defined(_TREIBER_H) */

/* -eof- */
