关于数据采集卡采集和绘制实时动态曲线问题 (100分)

  • 主题发起人 主题发起人 smartcn
  • 开始时间 开始时间
S

smartcn

Unregistered / Unconfirmed
GUEST, unregistred user!
我正在做课程设计,做的是一个金属切削计算机仿真软件;
其中有一部分是要通过数据采集生成一个实时的动态曲线 y轴为切削力Fz,x轴为时间T
有点像股票K线图的样子。
现有问题如下:
1)采用的是PCI-8333多功能模入模出接口卡,PCI8KA系列PCI数据采集卡,
是AMCC公司的5920 PCI总线接口控制芯片,驱动中提供了动态链接库Pci8kp.dll
说明书提供的例子是用VB写的,如下:
Public Type ZT_PCIBOARD
lIndex As Long
hHandle As Long
nCh As Integer
lData As Long
pldata As Long
lCode As Long
End Type

Public Type ZT_SIRQCALLBACK
lIndex As Long
End Type

Public Declare Function OpenDevicePlx Lib "pci8kp.dll" (nZT_PCIBOARD As ZT_PCIBOARD) As Long
Public Declare Function CloseDevicePlx Lib "pci8kp.dll" (nZT_PCIBOARD As ZT_PCIBOARD) As Long

Public Declare Function OpenIRQ Lib "pci8kp.dll" (hDeviceList As Long, ByVal hDeviceNum As Long, ByVal IrqCallBack As Long) As Long
Public Declare Function CloseIRQ Lib "pci8kp.dll" () As Long

Public Declare Function ZT8319DI Lib "pci8kp.dll" (nZT_PCIBOARD As ZT_PCIBOARD) As Long
Public Declare Function ZT8319DO Lib "pci8kp.dll" (nZT_PCIBOARD As ZT_PCIBOARD) As Long
Public Declare Function ZT8319AI Lib "pci8kp.dll" (nZT_PCIBOARD As ZT_PCIBOARD) As Long
Public Declare Function ZT8319Init Lib "pci8kp.dll" (nZT_PCIBOARD As ZT_PCIBOARD) As Long
.... ....
如何改为用delphi 使用这个Dll文件中的函数呢?

2),需要用采集卡采集三个数值,分别为主切削力Fz,进给量f,速度v 存入数据库;
并用采集到的数据Fz生成一个实时的动态曲线 ,y轴为切削力Fz,x轴为时间T;
用什么控件可以实现呢?编程的过程该注意些什么呢?

我刚学delphi,希望各位能给我一些指导:)
能否给我一个相关的例程?
谢谢~
我的邮箱是
smartcn@vip.sina.com
 
who can help me?
 
有人能解答吗?
 
type
ZT_PCIBOARD = record
lIndex : LongInt;
hHandle : LongInt;
nCh : Integer;
lData : LongInt;
pldata : LongInt;
lCode : LongInt
end;

ZT_SIRQCALLBACK = record
lIndex : LongInt
End;

Function OpenDevicePlx(nZT_PCIBOARD : ZT_PCIBOARD) : LongInt; external 'pci8kp.dll';
Function CloseDevicePlx(nZT_PCIBOARD : ZT_PCIBOARD) : LongInt; external 'pci8kp.dll';

Function OpenIRQ(hDeviceList : LongInt; var hDeviceNum, IrqCallBack : LongInt) : LongInt; external 'pci8kp.dll';
Function CloseIRQ : LongInt; external 'pci8kp.dll';

Function ZT8319DI(nZT_PCIBOARD : ZT_PCIBOARD) : LongInt; external 'pci8kp.dll';
Function ZT8319DO(nZT_PCIBOARD : ZT_PCIBOARD) : LongInt; external 'pci8kp.dll';
Function ZT8319AI (nZT_PCIBOARD : ZT_PCIBOARD) : LongInt; external 'pci8kp.dll';
Function ZT8319Init(nZT_PCIBOARD : ZT_PCIBOARD) : LongInt; external 'pci8kp.dll';
 
这个好象是WIN98下的程序
 
先申明dll里边的函数,在程序里边调用它就可以采集了。我做的项目和你的差不多,不过闪的太厉害,要请教高人了,帮你UP
 
用 timer 控件和 paintbox 控件配合使用就可以画出动态的图形了
当然,你也必须设定动态数组
 
谢谢LeeChange,会给你分的:)

joymaker ,你说的用 timer 控件和 paintbox 控件配合使用就可以画出动态的图形
你能说具体点吗,我是初学delphi
是否有相关的例程?

分不够可以加的
 
LeeChange,我按你说的写好了,可是运行的过程中出现以下错误信息:
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address
10001279 in module'pic8kp.dll'.Read of address 00000000'.Process stopped.Use Step or Run to
continue.

这个错误信息是表示什么意思呢?改怎么修改?
大哥们帮帮忙吧:)
(编译的过程没有错误)
 
第一个问题已经解决了
第二个关于实时绘制动态曲线,有什么好的方法呢?
 
第二个关于实时绘制动态曲线,有什么好的方法呢?
我有一个这方面的例子,我两个了image.canvas,作双缓冲。
给个mail我给你发一个?
 
to cryingboy
我的邮件是
smartcn@vip.sina.com

谢谢你:)
 
这个只是我自己编的, 我也是新手上路:
procedure TForm3.Timer1Timer(Sender: TObject);
var
buf,inputstring:string;
dotpos:integer;
x:integer;
begin
try
x:=1;
i:=i+1;
inputstring:='#'+'02'+chr(13);
Mscomm1.Output:=inputstring;
sleep(150);
buf:=trim(Mscomm1.Input);
buf:='+0.3200+0.4400+0.5600+0.6700+0.7800';
if buf='' then
begin
timer1.Enabled:=false;
showmessage('取值失败!');
exit;
end;
if pos('.',buf)<1 then
begin
timer1.enabled:=false;
showmessage('返回的数据错误!请重新采集.');

exit;

end
else
begin
dotpos:=pos('.',buf);
a:=strtofloat(copy(buf,dotpos-1,6));
buf:=copy(buf,dotpos+4,length(buf)-7);
dotpos:=pos('.',buf);
b:=strtofloat(copy(buf,dotpos-1,6));
buf:=copy(buf,dotpos+4,length(buf)-7);
dotpos:=pos('.',buf);
c:=strtofloat(copy(buf,dotpos-1,6));
buf:=copy(buf,dotpos+4,length(buf)-7);
dotpos:=pos('.',buf);
d:=strtofloat(copy(buf,dotpos-1,6));
buf:=copy(buf,dotpos+4,length(buf)-7);
dotpos:=pos('.',buf);
e:=strtofloat(copy(buf,dotpos-1,6));
with paintbox1.Canvas do
begin
pen.Width:=2;
if flag1=1 then
begin
edit1.Text:=floattostr(a);
pen.Color:=clred;
moveto((i-1),400-trunc(400*a[i-1]));
lineto(i,400-trunc(400*a));
end;
if flag2=1 then
begin
edit2.Text:=floattostr(b);
pen.Color:=clmaroon;
moveto((i-1),400-trunc(400*b[i-1]));
lineto(i,400-trunc(400*b));
end;
if flag3=1 then
begin
edit3.Text:=floattostr(c);
pen.Color:=clpurple;
moveto((i-1),400-trunc(400*c[i-1]));
lineto(i,400-trunc(400*c));
end;
if flag4=1 then
begin
edit4.Text:=floattostr(d);
pen.Color:=cllime;
moveto((i-1),400-trunc(400*d[i-1]));
lineto(i,400-trunc(400*d));
end;
if flag5=1 then
begin
edit5.Text:=floattostr(e);
pen.Color:=clblue;
moveto((i-1),400-trunc(400*e[i-1]));
lineto(i,400-trunc(400*e));
end;
end;


end;
except
showmessage('rong');
timer1.enabled:=false;
end;
end;
这是我的设计的一部分,有五路信号。不知对你是否有用

 
谢谢 joymaker
我试试看
 
使用我们公司的控件
TPolyLine可以方便的绘出曲线,并可以存入数据库。

----------------------------------------
水晶控件
http://www.codeidea.com
 
以下代码中的count_temp过程运算出现"Invalid floating point operation"错误提示,
是怎么回事呢?

Procedure Tmainfrm.count_temp;
const
{Wd-外径,Nd-内径,Hw-与水的对流换热系数,Ha-与空气的对流换热系数
v-外表面线速度,L-铸轧区长度,k-导热系数,c-比热,p-密度
Tw-冷却水温度,Ta-空气温度
Tb-锟套初始化温度,limit-限制循环次数,E-最小值}
Wd = 0.996; Nd = 0.903; Hw = 15000; Ha = 100; L = 0.073;
k = 30; c = 460; p = 7900; Tw = 25; Ta = 25;
Tb = 25; limit = 1000; E = 0.001;
i = 135; j = 8;
var
{i-圆周网格,j-径向网格,bi-圆周步长,bj-径向步长
w-角速度,a-导温系数,counts-循环次数,U-每次循环未收敛的网格数
cycle-周期,Ti-,bt-时间步长,points-铸轧区内的节点数,num-计算周期数}
M,N,counts,U,points,num,aa:integer;
Y,T,X:array[1..i,1..j] of Double;
v,bi,bj,ri,w,a,q,cycle,Ti,bt:Double;
begin
v:=0.0192;
bj:=(Wd-Nd)/(2*j);
bi:=2*3.1415926/i; //0.0465
a:=k/(p*c);
w:=v/(3.1415926*Wd);
q:=52256;
counts:=0;
points:=round(L*i/(3.1415926*Wd));
cycle:=round((3.1415926*Wd)/v); //周期 163″
bt:=0.9; //时间步长
Ti:=0; //选择每个周期的第0秒的时刻点作为参考点 Ti=0? 该时刻为铸轧区的入口处
num:=1;
aa:=0;
//----------------------------------------------------
for M:=1 to i do {温度初始化}
begin
for N:=1 to j do
T[M,N]:=Tb;
end;
//----------------------------------------------------
repeat {采用高斯迭代法计算}
U:=0;
ri:=Nd/2;
for N:=1 to j do
begin
for M:=1 to i do
begin
if countCBox.checked=false then Exit;
if (N=1) then {计算内表面温度}
X[M,N]:=2*bt/(p*c*bi*bj*(ri+bj/4))
*((p*c*bi*bj*(ri+bj/4)/(2*bt)-k*bj/(ri*bi)-k*(ri+bj/2)*bi/bj-Hw*ri*bi)*T[M][N]
+(k*bj/(2*ri*bi))*T[M][N+1]
+(k*(ri+bj/2)*bi/bj)*T[M+1][N]
+(k*bj/(2*ri*bi))*T[M][N-1]
+Hw*ri*bi*Tw)
else
begin
if (N<>j) then {计算套内部温度}
X[M][N]:=a*bt
*((1/(a*bt)-2/(bj*bj)-2/(ri*ri*bi*bi))*T[M][N]
+(1/(bj*bj)+1/(2*ri*bj))*T[M+1][N]
+(1/(bj*bj)-1/(2*ri*bj))*T[M-1][N]
+(1/(ri*ri*bi*bi))*T[M][N+1]
+(1/(ri*ri*bi*bi))*T[M][N-1])
else
begin {以下是计算外表面温度}
if ((num-1)*cycle<=Ti) and (Ti<=points*bt+(num-1)*cycle) and (aa<=points) then {计算铸轧区温度}
begin
X[M][N]:=(2*bt)/(p*c*bi*bj*(ri-bj/4))
*((p*c*bi*bj*(ri-bj/4)/(2*bt)-k*bj/(ri*bi)-k*(ri-bj/2)*bi/bj)*T[M][N]
+(k*bj/(2*ri*bi))*T[M][N+1]
+(k*(ri-bj/2)*bi/bj)*T[M-1][N]
+(k*bj/(2*ri*bi))*T[M][N-1]
+ri*bi*q);
//X[M][N]:=421;
aa:=aa+1 ;
label2.caption:=inttostr(aa);
end
else {计算外表面温度}
X[M,N]:=(2*bt)/(p*c*bi*bj*(ri-bj/4))
*((p*c*bi*bj*(ri-bj/4)/(2*bt)-k*bj/(ri*bi)-k*(ri-bj/2)*bi/bj
-Ha*ri*bi)*T[M][N]
+(k*bj/(2*ri*bi))*T[M][N+1]
+(k*(ri-bj/2)*bi/bj)*T[M-1][N]
+(k*bj/(2*ri*bi))*T[M][N-1]
+Ha*ri*bi*Ta);
// X[M][N]:=421;
end;
end;

if (Ti=(num-1)*cycle) then
begin
Y[M,N]:=X[M,N]-T[M,N];
if (abs(Y[M,N])>E) then U:=U+1;
end;

T[M,N]:=X[M,N];
end;
ri:=ri+bj;
end;
counts:=counts+1;
//>>>>>动态显示counts&amp;U的值
countsLbl.Caption :=IntToStr(counts);
ULbl.Caption :=IntToStr(U);

if (Ti=(num-1)*cycle) and (U=0) then Break;
Ti:=Ti+bt; //计算完所有点后增加一个时间步长
if (Ti=num*cycle) then
begin
num:=num+1;
aa:=0;
end;

until counts>limit;
//----------------------------------------------------
for N:=1 to j do {输出网格温度值}
begin
for M:=1 to i do
begin
Label1.Caption :=FloatToStr(T[M,N]); //>>>>>>加入数据库
with ListView.Items.Add do
begin
Caption:=floattostr(round(T[M,N]));
subitems.add(floattostr(v));
subitems.add(inttostr(M));
subitems.add(inttostr(N));
end;
end;
end;
messagedlg('完成计算,请进行仿真分析!',mtinformation,[mbOK],0);
CountCBox.Checked:=false;
end;

procedure Tmainfrm.CountCBoxClick(Sender: TObject);
begin
if CountCBox.Checked=true then
Count_temp;
end;
 
发到邮箱里 coolcwm@163.com
 
多人接受答案了。
 
后退
顶部