我觉得调用没问题,可是提示访问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'
上面两个函数引用没报错
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'
上面两个函数引用没报错
解决方案 »
- delphi 向excel表格第一列里动态写入数据 需要判断是否重复
- 哪位有DevExpress的帮助文档,最好是中文的,主要是想要cxgrid的帮助文档.
- 如何通过读取注册表来获取所有文件类型的ICO图标,并存到ImageList里面!!!
- 关于IdTcpServer与IdTcpClient编程
- 毕设求助各位大侠 :)
- 关于delphi的消息处理机制,有一点不太明白
- 怎样解决SPComm在win2k下的多串口通信限制
- delphi数据库操作时,如何直接捕获到SQL Server错误消息代码
- 请教一个关于SYBASE下的SQL语句
- 应用程序如何处理数据库的密码?是保存在程序里还是存在程序外?
- 关于进销存架构问题,高手们进来发表高见啦~~~
- delphi怎样查询函数的使用方法呢?
=====>
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'
var
pdata:Pdouble;
begin
pdata^:=3.6;
showmessage(floattostr(Pdata^));
end;
报地址越界错误,我该怎么样才能把这个双精度指针里面的数值转换为字符串呢
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);
改为
value:Pdouble
Delphi要么 var arg:double 要么 arg:Pdouble
C里面double* arg 和double arg[]是等价的。
Delphi里 var arg:double 和 arg:Pdouble 等价
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;调试了好久,找不出错误,头晕了