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

📄 daq53.cpp

📁 matlab daq sampling source code
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*
 * This file was automatically generated for MATLAB by H2MEX on
 * Sun Mar 19 02:29:24 2000
 * from daq2.h.
 * 
 * H2MEX v 1.0, by Alaa Makdissi (c) 1999
 * Alaa.Makdissi@obspm.fr
 * http://opdaf1.obspm.fr/~makdissi
 *
 * The original code is due to the matwrap (v.52) script by Gary R. Holt
 * <holt@monet.klab.caltech.edu>
 */ 

#define MEM_ALLOC(type, n, size) ((type)mxCalloc(n, size))
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "wdaq_c.h"

#if (__BCPLUSPLUS__ < 0x0301)
		  typedef unsigned int    UINT;
#endif

#if defined (WIN32)
	#define	MoveTo(a,b,c)		MoveToEx(a,b,c,NULL)
	#define	huge
#endif

extern "C" {

#include <mex.h>
}

//
// Return the maximum of the arguments:
//
#if !defined(max)
#define	max(A, B)	((A) > (B) ? (A) : (B))
#endif

#if !defined(min)
#define	min(A, B)	((A) < (B) ? (A) : (B))
#endif



/*
 * Return the number of dimensions of an array.
 * This is not well-defined in matlab; we just return the highest dimension
 * which is not 1.
 */
static int
_n_dims(const mxArray *mat)
{
  int n_dim = mxGetNumberOfDimensions(mat); /* Get what matlab thinks. */
  if (n_dim == 2 && mxGetN(mat) == 1) /* 2D array with # of columns = 1? */
  {
    n_dim = 1;			/* It's really a 1D array. */
    if (mxGetM(mat) == 1)	/* Also only one row? */
      n_dim = 0;		/* It's really a scalar. */
  }

  return n_dim;
}

/*
 * Function to get the total number of elements in an array.
 * Arguments:
 * 1) The matlab object.
 *
 * If the object is a scalar, the array length is 1.
 */
static int
_arraylen(const mxArray *mat) {
  int len = 1;
  const int *dims = mxGetDimensions(mat); // Get the number of dimensions.
  int idx;
  for (idx = 0; idx < mxGetNumberOfDimensions(mat); ++idx)
    len *= dims[idx];		// Multiply all the dimensions.

  return len;
}

//
// Get the n'th dimension of a Matlab object.
// Arguments:
// 1) The matlab matrix.
// 2) Which dimension.  0 for the most quickly varying one, etc.
//
static inline int
_dim(const mxArray *mat, int idxno) {
  if (idxno >= mxGetNumberOfDimensions(mat))	// Illegal # of dims?
    return 1;
  else
    return mxGetDimensions(mat)[idxno];	// Return the dimension.
}

//
// Load up an array (which may consist only of a single element) with
// the values from a matlab object.  Arguments:
// 1) The matlab object.
// 2) Where to put the values.  The array should be allocated sufficiently
//    large so that all of the values in the matlab object can be converted.
//
// These functions return 0 on error, or 1 if the operation succeded.
//
template <class FLOAT>
static int
_get_numeric(const mxArray *mat, FLOAT *arr) // float or double.
{
  int idx;
  int n_elements = _arraylen(mat); // Get the length.

  if (mxIsDouble(mat))		// Ordinary double precision matrix?
  {
    double *pr = mxGetPr(mat);	// Point to vector of double precision values.

    for (idx = 0; idx < n_elements; ++idx) // Loop through all elements.
      *arr++ = (FLOAT)*pr++;	// Convert and copy this element.
  }
  else				// Don't know what this is.
    return 0;			// Type conversion error.

  return 1;			// No error.
}



/*
 * Check to see if the vectorizing dimensions on an input argument are
 * ok.  Arguments:
 * 1) The input argument.
 * 2) The number of vectorizing dimensions we have so far.  This is updated
 *    if we add more vectorizing dimensions.
 * 3) An array containing the existing vectorizing dimensions.
 * 4) The number of explicitly declared dimensions, i.e., 0 if this was
 *    declared as a scalar, 1 if a vector.  We vectorize only the dimensions
 *    higher than the explicitly declared ones.
 * 5) A value which is set to 0 if this argument is not vectorized.  This
 *    value is left unaltered if the argument is vectorized.
 *
 * Returns 0 if there was a problem, 1 if the dimensions were ok.
 */
int
_check_input_vectorize(const mxArray *arg,
                       int *n_vec_dim,
		       int _d[4],
		       int explicit_dims,
		       int *vec_stride)
{
  int v_idx;

  int n_dims = _n_dims(arg);

  if (n_dims > explicit_dims)	/* Any additional dimensions? */
  {
    if (*n_vec_dim == 0)	/* No vectorizing dimensions seen yet? */
    {				/* This defines the vectorizing dimensions. */
      *n_vec_dim = n_dims - explicit_dims; /* Remember the # of dims. */
      for (v_idx = 0; v_idx < 4-explicit_dims; ++v_idx)
        _d[v_idx] = _dim(arg, v_idx+explicit_dims); /* Remember this dim. */
    } 
    else			/* Already had some vectorizing dimensions. */
    {				/* These must match exactly. */
      for (v_idx = 0; v_idx < 4-explicit_dims; ++v_idx)
        if (_d[v_idx] != _dim(arg, v_idx+explicit_dims)) /* Wrong size? */
          return 0;		/* Error! */
    }
  }  
/*  else if (n_dims < explicit_dims) */ /* Too few dimensions? */
/*    return 0; */ /* We don't do this check because there's no way to
		    * distinguish between a vector and a 3x1 matrix. */
  else
    *vec_stride = 0;		/* Vectorization not required. */

  return 1;
}

/*
 * Same thing except for modify variables.  Arguments:
 * 1) The input argument.
 * 2) The number of vectorizing dimensions we have so far.
 * 3) An array containing the existing vectorizing dimensions.
 * 4) The number of explicitly declared dimensions, i.e., 0 if this was
 *    declared as a scalar, 1 if a vector.  We vectorize only the dimensions
 *    higher than the explicitly declared ones.
 * 5) A flag indicating whether this is the first modify variable.  This
 *    flag is passed by reference and updated by this subroutine.
 *
 * The vectorizing dimensions of modify arguments must exactly match those
 * specified for input variables.  The difference between this subroutine
 * and _check_input_vectorize is that only the first modify variable may
 * specify additional vectorizing dimensions.
 *
 * Returns 0 if there was a problem, 1 if the dimensions were ok.
 */
int
_check_modify_vectorize(const mxArray *arg,
		        int *n_vec_dim,
		        int _d[4],
		        int explicit_dims,
			int *first_modify_flag)
{
  int v_idx;

  int n_dims = _n_dims(arg);

  if (n_dims > explicit_dims)	/* Any additional dimensions? */
  {
    if (*n_vec_dim == 0 && *first_modify_flag)	/* No vectorizing dimensions seen yet? */
    {				/* This defines the vectorizing dimensions. */
      *n_vec_dim = n_dims - explicit_dims; /* Remember the # of dims. */
      for (v_idx = 0; v_idx < 4-explicit_dims; ++v_idx)
        _d[v_idx] = _dim(arg, v_idx+explicit_dims); /* Remember this dim. */
    } 
    else			/* Already had some vectorizing dimensions. */
    {				/* These must match exactly. */
      for (v_idx = 0; v_idx < 4-explicit_dims; ++v_idx)
        if (_d[v_idx] != _dim(arg, v_idx+explicit_dims)) /* Wrong size? */
          return 0;		/* Error! */
    }
  }  
/*  else if (n_dims < explicit_dims) */ /* Too few dimensions? */
/*    return 0; */ /* We don't do this check because there's no way to
		    * distinguish between a vector and a 3x1 matrix. */

  *first_modify_flag = 0;	/* Next modify variable will not be first. */
  return 1;
}

void _wrap_A2000_Calibrate(int nlhs, mxArray **plhs, int nrhs, const mxArray **prhs)
{
  if (nlhs > 1 ||
      nrhs != 5+1)
    mexErrMsgTxt("Wrong number of arguments to function A2000_Calibrate");
  short _arg_slot;
  short _arg_saveNewValues;
  short _arg_calMethod;
  short _arg_channel;
  double _arg_extRefVoltage;
  short _arg_retval;
  if (_n_dims(prhs[1]) > 0)
    mexErrMsgTxt("Error in dimension of argument slot");
  if (!_get_numeric(prhs[1], &_arg_slot))
    mexErrMsgTxt("Expecting numeric scalar for argument slot");

  if (_n_dims(prhs[2]) > 0)
    mexErrMsgTxt("Error in dimension of argument saveNewValues");
  if (!_get_numeric(prhs[2], &_arg_saveNewValues))
    mexErrMsgTxt("Expecting numeric scalar for argument saveNewValues");

  if (_n_dims(prhs[3]) > 0)
    mexErrMsgTxt("Error in dimension of argument calMethod");
  if (!_get_numeric(prhs[3], &_arg_calMethod))
    mexErrMsgTxt("Expecting numeric scalar for argument calMethod");

  if (_n_dims(prhs[4]) > 0)
    mexErrMsgTxt("Error in dimension of argument channel");
  if (!_get_numeric(prhs[4], &_arg_channel))
    mexErrMsgTxt("Expecting numeric scalar for argument channel");

  if (_n_dims(prhs[5]) > 0)
    mexErrMsgTxt("Error in dimension of argument extRefVoltage");
  if (!_get_numeric(prhs[5], &_arg_extRefVoltage))
    mexErrMsgTxt("Expecting numeric scalar for argument extRefVoltage");

  plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
    _arg_retval = (short)
      A2000_Calibrate(_arg_slot, _arg_saveNewValues, _arg_calMethod, _arg_channel, _arg_extRefVoltage);
  *mxGetPr(plhs[0]) = (double)_arg_retval;
}

void _wrap_A2000_Config(int nlhs, mxArray **plhs, int nrhs, const mxArray **prhs)
{
  if (nlhs > 1 ||
      nrhs != 4+1)
    mexErrMsgTxt("Wrong number of arguments to function A2000_Config");
  short _arg_slot;
  short _arg_sampClkSrc;
  short _arg_sampClkDrv;
  short _arg_dither;
  short _arg_retval;
  if (_n_dims(prhs[1]) > 0)
    mexErrMsgTxt("Error in dimension of argument slot");
  if (!_get_numeric(prhs[1], &_arg_slot))
    mexErrMsgTxt("Expecting numeric scalar for argument slot");

  if (_n_dims(prhs[2]) > 0)
    mexErrMsgTxt("Error in dimension of argument sampClkSrc");
  if (!_get_numeric(prhs[2], &_arg_sampClkSrc))
    mexErrMsgTxt("Expecting numeric scalar for argument sampClkSrc");

  if (_n_dims(prhs[3]) > 0)
    mexErrMsgTxt("Error in dimension of argument sampClkDrv");
  if (!_get_numeric(prhs[3], &_arg_sampClkDrv))
    mexErrMsgTxt("Expecting numeric scalar for argument sampClkDrv");

  if (_n_dims(prhs[4]) > 0)
    mexErrMsgTxt("Error in dimension of argument dither");
  if (!_get_numeric(prhs[4], &_arg_dither))
    mexErrMsgTxt("Expecting numeric scalar for argument dither");

  plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
    _arg_retval = (short)
      A2000_Config(_arg_slot, _arg_sampClkSrc, _arg_sampClkDrv, _arg_dither);
  *mxGetPr(plhs[0]) = (double)_arg_retval;
}

void _wrap_A2150_Calibrate(int nlhs, mxArray **plhs, int nrhs, const mxArray **prhs)
{
  if (nlhs > 1 ||
      nrhs != 3+1)
    mexErrMsgTxt("Wrong number of arguments to function A2150_Calibrate");
  short _arg_slot;
  short _arg_ref0;
  short _arg_ref1;
  short _arg_retval;
  if (_n_dims(prhs[1]) > 0)
    mexErrMsgTxt("Error in dimension of argument slot");
  if (!_get_numeric(prhs[1], &_arg_slot))
    mexErrMsgTxt("Expecting numeric scalar for argument slot");

  if (_n_dims(prhs[2]) > 0)
    mexErrMsgTxt("Error in dimension of argument ref0");
  if (!_get_numeric(prhs[2], &_arg_ref0))
    mexErrMsgTxt("Expecting numeric scalar for argument ref0");

  if (_n_dims(prhs[3]) > 0)
    mexErrMsgTxt("Error in dimension of argument ref1");
  if (!_get_numeric(prhs[3], &_arg_ref1))
    mexErrMsgTxt("Expecting numeric scalar for argument ref1");

  plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
    _arg_retval = (short)
      A2150_Calibrate(_arg_slot, _arg_ref0, _arg_ref1);
  *mxGetPr(plhs[0]) = (double)_arg_retval;
}

void _wrap_AI_Check(int nlhs, mxArray **plhs, int nrhs, const mxArray **prhs)
{
  if (nlhs != 3 ||
      nrhs != 1+1)
    mexErrMsgTxt("Wrong number of arguments to function AI_Check");
  short _arg_slot;
  short _arg_status;
  short _arg_value;
  short _arg_retval;
  if (_n_dims(prhs[1]) > 0)
    mexErrMsgTxt("Error in dimension of argument slot");
  if (!_get_numeric(prhs[1], &_arg_slot))
    mexErrMsgTxt("Expecting numeric scalar for argument slot");

  plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
  plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
  plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL);
    _arg_retval = (short)
      AI_Check(_arg_slot, &_arg_status, &_arg_value);
  *mxGetPr(plhs[0]) = (double)_arg_retval;
  *mxGetPr(plhs[1]) = (double)_arg_status;
  *mxGetPr(plhs[2]) = (double)_arg_value;
}

void _wrap_AI_Clear(int nlhs, mxArray **plhs, int nrhs, const mxArray **prhs)
{

⌨️ 快捷键说明

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