我觉得调用没问题,可是提示访问dll内存越界了,好奇怪,c的原型如下:
typedef uInt32             bool32;typedef void*              TaskHandle;
int32 __CFUNC     DAQmxReadAnalogF64             (TaskHandle taskHandle, int32 numSampsPerChan, float64 timeout, bool32 fillMode, float64 readArray[], uInt32 arraySizeInSamps, int32 *sampsPerChanRead, bool32 *reserved);delphi的定义
type
   TaskHandle=Pointer ;
   bool32=Cardinal ;
   PBool32=^bool32 ;
function DAQmxReadAnalogF64(taskHandle :TaskHandle; numSampsPerChan:Integer; TimeOut:Double; fillMode:bool32;ReadArray:double;arraySizeInSamps:Cardinal ;
          sampsPerChanRead:PInteger;Reserved:Pbool32):Integer;stdcall;external 'nicaiu.dll'我引用的时候这样写
Data:Array [0..999] of Double;
DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByChannel,Data[0],1000,channelRead,nil)不知道哪里错了,请各位大哥指点,那个cpu寄存器窗口不会看,呵呵错误提示信息 Access violation at address 6d9a3e47 of in module 'nicaiu.dll'
一共引用了这个DLL里面的3个函数前面两个都没报错,只是第三个,。读通道里面的模拟量数据的函数,报错了。
 function DAQmxCreateTask(taskName:string;taskHandle:PTaskHandle):Integer;stdcall;external 'nicaiu.dll'  
function DAQmxCreateAIVoltageChan(AtaskHandle:TaskHandle;const physicalChannel:string ;
          const nameToAssignToChannel:string;terminalConfig:Integer ;minVal:Double;maxVal:Double;units:Integer;const customScaleName:string):Integer; stdcall;external 'nicaiu.dll'
上面两个函数引用没报错

解决方案 »

  1.   

    ReadArray:double
    =====>
    var ReadArray:double
    type
      TaskHandle=Pointer ;
      bool32=Cardinal ;
      PBool32=^bool32 ;
    function DAQmxReadAnalogF64(taskHandle :TaskHandle; numSampsPerChan:Integer; TimeOut:Double; fillMode:bool32;var ReadArray:double;arraySizeInSamps:Cardinal ;
      sampsPerChanRead:PInteger;Reserved:Pbool32):Integer;stdcall;external 'nicaiu.dll'
      

  2.   

    还想问下一个问题
    var
      pdata:Pdouble;
    begin
      pdata^:=3.6;
      showmessage(floattostr(Pdata^));
    end;
    报地址越界错误,我该怎么样才能把这个双精度指针里面的数值转换为字符串呢
      

  3.   

    我现在想用另外一个函数调用,读取模拟量数值,可是也老报地址越界错误。但是不是在DLL里面,是在工程里面。
    c函数原型
    DAQmxReadAnalogScalarF64       (TaskHandle taskHandle, float64 timeout, float64 *value, bool32 *reserved);
    dlephi声明
    function DAQmxReadAnalogScalarF64(AtaskHandle :TaskHandle; timeout:Double; var value:Pdouble; reserved:PBool32):Integer;stdcall;external 'nicaiu.dll'
    try
       new(pdata);
       DAQmxErrChk(DAQmxCreateTask('',@taskHandle));
       TaskisRunning:=True;
       DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle,edt_PhysicalChannel.Text,'', DAQmx_Val_Cfg_Default,
                  StrToFloat(edt_MinValue.Text),StrToFloat(edt_MaxValue.Text),DAQmx_Val_VoltageUnits1_Volts,''));
       DAQmxErrChk(DAQmxReadAnalogScalarF64(taskHandle,10.0,pdata,nil));
       //DAQmxErrchk(DAQmxReadAnalogF64(taskHandle,-1,10.0,DAQmx_Val_GroupByChannel,Data[0],1000,channelRead,nil));
       edt_Acq.Text :=FloatToStr(pdata^) ; //当调用这句老是报错,不知道为什么
       //cwgraph1.PlotY(data);
       DAQmxErrChk(DAQmxStopTask(taskhandle));
       DAQmxErrChk(DAQmxClearTask(taskhandle));
       TaskisRunning:=False;
       Dispose(pdata);
      

  4.   

    var value:Pdouble
    改为
    value:Pdouble
      

  5.   

    C里面double* arg 和double arg[]是等价的。
    Delphi要么 var arg:double 要么 arg:Pdouble
      

  6.   

    恩,大哥你真厉害啊,呵呵每次都被你说对了啊,呵呵,谢谢你啊,真相拜你为师,嘿嘿,这个采集卡只支持C和VB平台,不支持DELPHI,幸亏是标准的STDCALL,不然真不知道怎么做呢
      

  7.   

    是不是这个VAR,相当于把它声明为一个地址指针,double arg[],这个arg[]是一个数组吗?
      

  8.   

    支持C就表示Delphi可以调用了写法习惯的问题 注意着两句话
    C里面double* arg 和double arg[]是等价的。
    Delphi里 var arg:double 和 arg:Pdouble 等价
      

  9.   

    现在采集数据没问题了,可是引用它的一个相关控件的时候,老是提示“There is no overloaded version of 'Ploty' that can be called with argument”,参数不能重载什么意思?
    CWgraph1.ploty这个方法的参数是oleVariant类型,所以我把刚才采集到的数据进行了转换var
      VariantData:oleVariant;
    for i:=1 to 1000 do
    begin
     VariantData[i-1]:=Data[i-1];
    end;
    CWgraph1.ploty(VariantData);//老提示上面的错误下面是VB的上对上面这个方法的解释,
    PlotY Method
    Syntax
    CWGraph.PlotY yData [, xFirst = 0] [, xInc = 1] [, bPlotPerRow = True]PurposePlots Y data evenly spaced on the x axis relative to the index in the array. Alternatively, you can use the xFirst and xInc parameters to specify the X value at the first data point and the incremental X value between data points.ResPass in a 2D array to plot several rows of data at once.The PlotY method uses plots from the CWGraph.Plots collection that are ed as multiplots. If there are not enough plots available, it uses temporary multiplots.Parameters
    yData As VariantThe data to plot. yData can be a one-dimensional array that updates the first plot on the graph or a two-dimensional array that updates the first n plots on the graph.xFirst As Variant[Optional] The X value for the first point in each plot.This parameter has a default value of 0.xInc As Variant[Optional] The amount to increment X for points in each plot. The value can be positive or negative.This parameter has a default value of 1.bPlotPerRow As Variant[Optional] If True, each row of the yData array is equivalent to one plot. If False, each column of the yData array is equivalent to one plot.This parameter has a default value of True.See Also
    CWPlot.PlotY//Delphi上的方法声明,是一个重载函数
     procedure PlotY(YData: OleVariant); overload;
    procedure TCWGraph.PlotY(YData: OleVariant);
    begin
      DefaultInterface.PlotY(YData, EmptyParam, EmptyParam, EmptyParam);
    end;
    //
    property  DefaultInterface: _DCWGraph read GetControlInterface;调试了好久,找不出错误,头晕了
      

  10.   

    这个问题已经换成如何使用OleVariant了,找本书看看吧.