⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 par4ch.h

📁 基于PC104的24位数据采集器的完整源码
💻 H
字号:
/* FILE: par4ch.h               Copyright (c), Symmetric Research, 2001

SR PAR4CH C user library include file.

Study this file to see the functions that can be called from user
level programs and applications to control the PAR4CH.

*/





/* FUNCTION TYPE DEFINES:

Most of the SR software links in a static copy of the PAR4CH library.
For static linking, function and global variable declarations are
easy and standard across operating systems.  The following defines
default to static linking if not otherwise specified.

Supporting Windows dynamic DLL libraries introduces complications.
The following ifdef defines allow for one PAR4CH library source to
service either statically linked or DLL applications.

Linux shared object libraries are also supported but do not require any
compile time specificatons beyond static.

*/

#if defined( _WIN_DLLEXPORT )
#define FUNCTYPE( type )        __declspec( dllexport ) type __stdcall
#define VARTYPE( type )         __declspec( dllexport ) type

#elif defined( _WIN_DLLIMPORT )
#define FUNCTYPE( type )        __declspec( dllimport ) type __stdcall
#define VARTYPE( type )         __declspec( dllimport ) type

#else           // default to simple declarations for static linking
#define FUNCTYPE( type )        type
#define VARTYPE( type )         type

#endif



/* DEVICE HANDLE AND MISCELLANEOUS OS DEPENDENT DEFINES:

The various OS's use different data types to keep track of the
current device driver.  These defines helps hide this difference
from the rest of the code.  The allowed SROS_xxxxx options are:

SROS_WINNT  Windows NT 4.0 or Windows 2000
SROS_WIN95  Windows 95 or 98 or ME
SROS_MSDOS  Dos
SROS_LINUX  Linux kernel 2.2.12 = RedHat 6.1 (6.0,6.2 also ok)

*/

#if defined( SROS_WINNT ) || defined( SROS_WIN95 )
#define DEVHANDLE void *

#elif defined( SROS_MSDOS )
#define DEVHANDLE unsigned int

#elif defined( SROS_LINUX )
#define DEVHANDLE int
#define O_BINARY 0x00

#else
#pragma message( "COMPILE ERROR: SROS_xxxxx MUST BE DEFINED !! " )

#endif  // SROS_WINNT  SROS_WIN95  SROS_MSDOS  SROS_LINUX

#define BAD_DEVHANDLE ((DEVHANDLE)(-1))








/* RELEASE REV:

This function allows the user to determine the library rev at
runtime.  The rev is an integer.  A number like 123 would be referred
to as rev "1.23".

*/

FUNCTYPE( void ) Par4chGetRev( int *Rev );








/* SIMPLE PAR4CH CONTROL/EXECUTION DEFINES AND FUNCTIONS:

The following "easy to use" defines and functions provide a basic
level of control over the PAR4CH.  Many applications will not need
anything else.  The basic pattern of usage is:

1) Open and initialize the PAR4CH, setting the sampling rate
2) Start conversion
3) Check Ready to see if data is ready
4) Call GetData to copy data from the PAR4CH buffer to the PC
5) Loop to continue getting more data

For more detailed control of the PAR4CH see the ADVANCED defines and
functions below.

Note that the function Par4chOpen returns a 1 or 0 for general
success or failure.  It also fills in an integer error code, which on
return has more information about what may have gone right or wrong.
The PAR4CH_ERROR ... defines provide a mapping from these error codes
to strings.

*/


// Par4ch number of channels ... this is fixed at 4 !

#define PAR4CH_CHANNELS                         4


// Parallel port name and mode defines ...

#define PAR4CH_0x378                            "Par4ch378"
#define PAR4CH_0x278                            "Par4ch278"

#define PAR4CH_PORT_NAME_1                      PAR4CH_0x378
#define PAR4CH_PORT_NAME_2                      PAR4CH_0x278

#define PAR4CH_PORT_MODE_BPP                    0
#define PAR4CH_PORT_MODE_EPP                    1


// Minimum and maximum Sps values ...

#define PAR4CH_SPS_MIN                          0.00001   // Hz
#define PAR4CH_SPS_MAX                          15625.0   // Hz
#define PAR4CH_SPS_DEFAULT                        100.0   // Hz


// Error code return values ...

#define PAR4CH_ERROR_NONE                           0
#define PAR4CH_ERROR_PORT_ADDRESS                   1
#define PAR4CH_ERROR_PORT_MODE                      2
#define PAR4CH_ERROR_DATA_FORMAT                    3
#define PAR4CH_ERROR_CAL_MODE                       4
#define PAR4CH_ERROR_GAIN                           5
#define PAR4CH_ERROR_TURBO                          6
#define PAR4CH_ERROR_GAIN_TURBO_PRODUCT             7
#define PAR4CH_ERROR_DECIMATION                     8
#define PAR4CH_ERROR_DRIVER_NOT_OPEN                9
#define PAR4CH_ERROR_DRIVER_REQUEST_FAILED          10
#define PAR4CH_ERROR_VOLTAGE_BAD_ON                 11
#define PAR4CH_ERROR_VOLTAGE_BAD_OFF                12
#define PAR4CH_ERROR_ADS1210_CR_READBACK            13
#define PAR4CH_ERROR_FIFO_SANITY                    14
#define PAR4CH_ERROR_OVERFLOW                       15
#define PAR4CH_ERROR_KEYPRESS                       16
#define PAR4CH_ERROR_MAX                            17


#define PAR4CH_ERROR_MSG_NONE                       "NONE"
#define PAR4CH_ERROR_MSG_PORT_ADDRESS               "PORT ADDRESS"
#define PAR4CH_ERROR_MSG_PORT_MODE                  "PORT MODE"
#define PAR4CH_ERROR_MSG_DATA_FORMAT                "DATA FORMAT"
#define PAR4CH_ERROR_MSG_CAL_MODE                   "CALIBRATION"
#define PAR4CH_ERROR_MSG_GAIN                       "GAIN"
#define PAR4CH_ERROR_MSG_TURBO                      "TURBO"
#define PAR4CH_ERROR_MSG_GAIN_TURBO_PRODUCT         "GAIN*TURBO"
#define PAR4CH_ERROR_MSG_DECIMATION                 "DECIMATION"
#define PAR4CH_ERROR_MSG_DRIVER_NOT_OPEN            "DEVICE DRIVER"
#define PAR4CH_ERROR_MSG_DRIVER_REQUEST_FAILED      "DRIVER REQUEST"
#define PAR4CH_ERROR_MSG_VOLTAGE_BAD_ON             "VOLTAGE STILL ON"
#define PAR4CH_ERROR_MSG_VOLTAGE_BAD_OFF            "VOLTAGE BAD/OFF"
#define PAR4CH_ERROR_MSG_ADS1210_CR_READBACK        "A/D READBACK"
#define PAR4CH_ERROR_MSG_FIFO_SANITY                "FIFO SANITY"
#define PAR4CH_ERROR_MSG_OVERFLOW                   "OVERFLOW"
#define PAR4CH_ERROR_MSG_KEYPRESS                   "KEYPRESS"
#define PAR4CH_ERROR_MSG_MAX                         NULL

extern VARTYPE( char ) *PAR4CH_ERROR_MSG[];

        // This array maps error codes to message strings.  See par4ch.c
        // for the actual allocation of PAR4CH_ERROR_MSG[].
        //
        // All of the library functions return error codes.  You may wish
        // to map them to message strings for use with printf.
        //
        // = {
        //        0  PAR4CH_ERROR_MSG_NONE,
        //        1  PAR4CH_ERROR_MSG_PORT_ADDRESS,
        //        2  PAR4CH_ERROR_MSG_PORT_MODE,
        //        3  PAR4CH_ERROR_MSG_DATA_FORMAT,
        //        4  PAR4CH_ERROR_MSG_CAL_MODE,
        //        5  PAR4CH_ERROR_MSG_GAIN,
        //        6  PAR4CH_ERROR_MSG_TURBO,
        //        7  PAR4CH_ERROR_MSG_GAIN_TURBO_PRODUCT,
        //        8  PAR4CH_ERROR_MSG_DECIMATION,
        //        9  PAR4CH_ERROR_MSG_DRIVER_NOT_OPEN,
        //       10  PAR4CH_ERROR_MSG_DRIVER_REQUEST_FAILED,
        //       11  PAR4CH_ERROR_MSG_VOLTAGE_BAD_ON,
        //       12  PAR4CH_ERROR_MSG_VOLTAGE_BAD_OFF,
        //       13  PAR4CH_ERROR_MSG_ADS1210_CR_READBACK,
        //       14  PAR4CH_ERROR_MSG_FIFO_SANITY,
        //       15  PAR4CH_ERROR_MSG_OVERFLOW
        //       16  PAR4CH_ERROR_MSG_KEYPRESS
        //       17  PAR4CH_ERROR_MSG_MAX
        //
        //   };




// Simple Par4ch functions ...

FUNCTYPE( DEVHANDLE ) Par4chOpen(

                                char *PortName,
                                int PortMode,
                                double Sps,

                                double *ActualSps,
                                int *Error

                                );

FUNCTYPE( int ) Par4chClose( DEVHANDLE Par4chHandle );

FUNCTYPE( void ) Par4chStart( DEVHANDLE Par4chHandle );
FUNCTYPE( void ) Par4chStop( DEVHANDLE Par4chHandle );

FUNCTYPE( int ) Par4chReady( DEVHANDLE Par4chHandle );
FUNCTYPE( int ) Par4chOverflow( DEVHANDLE Par4chHandle );

FUNCTYPE( unsigned int ) Par4chReadData(

                                DEVHANDLE Par4chHandle,
                                long *Values,
                                unsigned int Nvalues,
                                int *Error

                                );









/* ADVANCED PAR4CH CONTROL/EXECUTION DEFINES AND FUNCTIONS:

These defines and functions allow a more detailed level of control
over PAR4CH execution.  They are intended for users who are familiar
with the ADS1210 command register bit fields and wish to program them
directly.


Use these defines with Par4chFullOpen to initialize the PAR4CH.

Several of these constants map directly into ADS1210 command register
bit setings.  Don't change their values !!

Some of the abbreviations are:

       EPP              enhanced parallel port
       BPP              bidirectional parallel port

       DF               ADS1210 data format
       CAL_MODE         ADS1210 calibration mode
       GAIN             ADS1210 preamp gain
       TURBO            ADS1210 modulator turbo setting
       DECIMATION       ADS1210 modulator decimation ratio


These functions control the operation of the PAR4CH.

Use the defines above and helper functions for setting Par4chFullOpen
parameters.

Note that PAR4CH user digital IO will not work until the board has
been initialized with Par4chOpen.

*/


// PAR4CH ADS1210 command register defines ...

#define PAR4CH_DF_SIGNED                        0
#define PAR4CH_DF_OFFSET                        1

#define PAR4CH_CAL_NORMAL                       0
#define PAR4CH_CAL_SELF                         1
#define PAR4CH_CAL_SYSTEM_OFFSET                2
#define PAR4CH_CAL_SYSTEM_FS                    3
#define PAR4CH_CAL_PSEUDO                       4
#define PAR4CH_CAL_BACKGROUND                   5

#define PAR4CH_CAL_MIN                          0
#define PAR4CH_CAL_MAX                          5

#define PAR4CH_GAIN_1                           0
#define PAR4CH_GAIN_2                           1
#define PAR4CH_GAIN_4                           2
#define PAR4CH_GAIN_8                           3
#define PAR4CH_GAIN_16                          4

#define PAR4CH_GAIN_MIN                         0
#define PAR4CH_GAIN_MAX                         4

#define PAR4CH_TURBO_1                          0
#define PAR4CH_TURBO_2                          1
#define PAR4CH_TURBO_4                          2
#define PAR4CH_TURBO_8                          3
#define PAR4CH_TURBO_16                         4

#define PAR4CH_TURBO_MIN                        0
#define PAR4CH_TURBO_MAX                        4

#define PAR4CH_GAINTURBO_MIN                    0
#define PAR4CH_GAINTURBO_MAX                    4

#define PAR4CH_DECIMATION_MIN                   19
#define PAR4CH_DECIMATION_100Hz_T1              194
#define PAR4CH_DECIMATION_100Hz_T16             3124
#define PAR4CH_DECIMATION_50Hz_T1               390
#define PAR4CH_DECIMATION_50Hz_T16              6249
#define PAR4CH_DECIMATION_MAX                   8000

#define PAR4CH_EXTRADECIMATION_MIN              1

#define PAR4CH_UNUSED                           -1


// Advanced Par4ch functions ...

FUNCTYPE( DEVHANDLE ) Par4chFullOpen(

                                char *PortName,
                                int PortMode,

                                int Df,
                                int GainLog,
                                int TurboLog,
                                int Decimation,
                                int ExtraDecimation,
                                int Unused,

                                long *ADS1210_CrValue,
                                int *Error

                                );


FUNCTYPE( int ) Par4chSpsGainToTde(

                                double Sps,
                                int GainLog,

                                int *TurboLog,
                                int *Decimation,
                                int *ExtraDecimation

                                );


FUNCTYPE( int ) Par4chTdeToSpsGain(

                                int TurboLog,
                                int Decimation,
                                int ExtraDecimation,

                                double *Sps,
                                int *GainLog

                                );











/* PAR4CH USER DIGITAL IO FUNCTIONS:

These functions allow programs to communicate with the DB15 digital
IO connector on the right hand side of the PAR4CH front panel.

*/

FUNCTYPE( void ) Par4chUserIoRd( DEVHANDLE Par4chHandle, int *Value );
FUNCTYPE( void ) Par4chUserIoWr( DEVHANDLE Par4chHandle, int Value );

FUNCTYPE( void ) Par4chUserLed( DEVHANDLE Par4chHandle, int State );




/* PAR4CH PC INTERRUPT FUNCTIONS:

These functions allow programs to enable and disable the PC interrupt.

*/

FUNCTYPE( void ) Par4chInterruptEnable( DEVHANDLE Par4chHandle );
FUNCTYPE( void ) Par4chInterruptDisable( DEVHANDLE Par4chHandle );





/* PAR4CH VOLTAGE CHECK FUNCTION:

This function checks the PAR4CH board voltage level.  If the voltage is
good, this function returns 1.  Otherwise, 0.

*/

FUNCTYPE( int ) Par4chVoltageGood( DEVHANDLE Par4chHandle );






/* GENERIC HELPER FUNCTIONS:

These functions perform a few generic keyboard and file IO tasks and
are used in various SR application programs to help smooth over OS
differences.

*/

FUNCTYPE( int  ) SrKeyboardNonBlock( void );
FUNCTYPE( int  ) SrGetKeyCheck( void );
FUNCTYPE( int  ) SrGetKeyWait(  void );
FUNCTYPE( void ) SrFlushPrint( void );
FUNCTYPE( int  ) SrSleep( int ms );
FUNCTYPE( int  ) SrFileLength( int fh );
FUNCTYPE( int  ) SrFileExist( char *filename );
FUNCTYPE( int  ) SrCommit( int fh );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -