|
楼主 |
发表于 2013-5-11 21:44:13
|
显示全部楼层
这是相似代码
unithjkzl;
USeS
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms, Dialogs, StdCtrls,ExtCtrls,CSSD,Db,DBTables,FileCtrl,Spin;
type
TForml=class(TForm)
Buttonl3:TButton;
cb2:TCheckBox;
private
{Private declarations)
public
{Publicdeclarations)
end;
Var
Forml:11Forml;
SIZe,jb:string;
filel:textfile:
XX,ii,yrcs:integer;
newrect:trect;
kzbshc,timekz,dycjr:boolean;
//5ms控制
SUXS,巧,VS,vd,VZ,跚,ddc,wycz:single;
//suxs烧速系数,晒夹长电压,VS烧长电压,vd顶长电压,VZ,SU烧速,ddc
XXS,tl,td,th,tj,v3,CCC,cccl,sddn:single;
iiluwj:file ofsmallint;
filename,filenamel,filename2:string;
jiluzt:byte;
//记录状态l有后退阶段O复位2有冷却阶段,记录有效
lhl,lh2,lh3,lh4,dhl,dh2,dh3,dh4:string;
//链号l-4段号1-4
hsl,hs2,hs3,hs4,jysj,q5zt:integer;
dn,wy,dy,ddyl,djyl,dh:smallint;
//5个记录数据sddn:电流设定比较值
dnxs,dyxs,ddylxs,djylxs:single;
//4个记录数据与A/D转换的数据
wyk,wyt,wyxsk,wyxst,jcdy,zcdy:single;
strioinl,strioin2,stroutl:string[8];
//16路开关量输入输出用
zdjkz,ydjkz,jilukz:booleam
∥左右电极控制
sgsj,zdjtime,ydjtime,starttime:longint;
//zdjtimeYDJTIME:左.右电极抬起:焊接开始时间
suk,sut,qs,zs:single;//启始速度,最后速度
ccc3:array[1。20]ofsingle;
ccc3dn:array[1..1 0]of single;
ccc3djyl,ccc3ddyl:array[1..40]ofsingle;
ccc3js,dnjs,ddyljs,djyljs:integer;
dal2wy,da6wy,dak,dat:single;
const basead=$300;
//const basead2=$3 18;
eonst baseio=$1 00;
//CONSTJZ=300.0/1 5;
Function inpl(al:smallint):integer;forward;
procedure da(value:single);forward;
procedure q4;forward; //复位
procedurem; forward; //焊接
procedurereadad;forward; //读A/D各值
procedure pix;forward;//画线打点
procedure initform;forward;//初始化窗口
procedurewritefile;forward;
procedure readfile; forward;
procedure dlh;forward; //斗链号
procedure closejilu;forward; //关闭记录
implementation
uses passwordform;
function timeGetTime:integer;stdcall far;external'winmm’;
procedure outp1(aa:smallint;a2:byte);
begin
aSm
pushdx;
movdx,aa;
mov al,a2;
outdx,al;
popdx;
end;
end;
Function inpl(al:smallint):integer;
Var
b:byte;
begin
aSIIl
push dx;
movdx,al;
in al,dx;
movb,al;
popdx;
end:
inpl:-b;
end;
procedure dlh;
begin
hsl:=form2.edithsl.Value;
hs2:=form2.ediths2.Value:
hs3:=form2.ediths3.Value;
hs4:=form2.ediths4.Value;
lhl:=form2.editlhl.text;
1h2:=form2.editlh2.text;
lh3:=form2.editlh3.text;
lh4:--fonn2.editlh4.text;
dhl:=form2.editdhl.text;
dh2:=form2.editdh2.text;
dh3:=form2.editdh3.text;
dh4:=form2.editdh4.text;
end:
function inttoasic(ii:integer):string;
Var
i,il:integer;
str:string[8];
begin
str:=‘’:
for i:=1 to 8 do
begin
Il:=ii mod 2;
str:=inttostr(i l)+str;
ii:=ii div2;
end;
inttoasic:=stn ;
end;
function asictoint(str:string):integer;
var i,il:integer;
begin
for i:=l to 8 do
begin
il=strtoint(str[1])*128+strtoint((str[2])*64+strtoint((str[3])*32+strtoint((str[4])*16+strtoint((str[5])*8+strtoint((str[6])*4+ strtoint((str[7])*2+strtoint((str[8])*l;
end;
asictoint:=i 1:
end;
procedure delayl(tt:longint) //小延时
Var
i:longint;
begin
for i:=0 to tt do:
end;
procedure delay(ttt:integer);
var
tl:longint;
begin
tl:=timegettime;
repeat
until(timegettime-tI)>=ttt;
end;
///**************//
procedure closejilm
begin
if(jiluzt=2)or((timegettime-starttime)>(strtoint(form2.EditTL.text) *1000+40000))then
begin
//writefile;
casedhof
l:form2.edithsl.Value:=form2.edithsl.Value+l:
2:form2.ediths2.Value:=form2.ediths2.Value+l;
3:form2.ediths3.Value:=form2.ediths3.Value+l:
4:form2.edims4.Value:=form2.ediths4.Value+l:
end;
//writefile;
form2.BuRon3.Click;
end;
ifjilukz then
begin
closefile(jiluwj);
jilukz:=false;
end;
end;
function q5:integer; {紧停、加热、挤压)
begin
forml.editl.text:--inttoasic (inpl(baseio+O));
forml。edit2.text:=inttoasic (inpl(baseio+1)):
forml.Editl.Update:
forml。Edit2.Update;
strioinl:--forml.editl.text;
strioin2:=formI.edit2.text;
if(strioinI[8]=’0’)or(strioinl[7]='l’)then
begin
q5zt:=q5zt+l:
if q5zt>20 then
begin
stroutl[8]:='0’; //断电
form!.edit4.text:=stroutl;
forml.edit4.update;
form!.shape20.Update;
forml.1qsjpanel.Caption:=floattostr(t1):
forml.1t1.caption:='-40’;
initform;
elosejilu;
q5:=5;
end;
end
else begin q5:=l;q5zt:=O;end;
end;
function q2:integer; (后退速度为5mm/s)
var
i:longint;
begin
i:=0;
//if forml.rb2.Checked then yres:=yres+l;
if stroutl[3]=’1’then
begin
stroutl[3]:='0’;
forml.edit4.Text:=stroutI;
form1.edit4.Update;
end;
if(v3<19.9)then v3:=v3+1.5*suxs else v3:--v3:
da(v3):
ifjiluzt=-O then i:=timegettime.starttime else i:=O:
jiluzt:=l;
if(q5=5)//or((i>4000)and((timegettime-starttime)<8000))
then begin q2:=5; q5;q4; end else q2:=l;
∥紧停或第一次后退大于3。5秒退出
End;
function ql:integer;
{前进){一一一=)
Var
t2,t4,sgsjl:longint;
i,ii,ctcs,oldwy,JJJ:integer;
pdddwy,pdddwyl,pdddwy2,ddhdd,maxdd,ddct:single;//ddhdd判断项锻后抖动距离
bjfile:textfile;
t:tsearchrec;
wjstr,wd:string;
ddhddkz,dyedd,decdd:boolean;
label sa,sal:
begin
if form 1.rb2.Checked and(yrcs<=form 1.sp2.Value)then
begin
v3:--v3-5*suxs=
end
else
ifv3*suk+sut>O.8 then
v3:--v3一(v3·suk+sut)*SUXS else v3:--v3—1*SUXS=
da(v3);
sgsj l:--timegettime-sgsj;
sgsjl:=sgsjl div 100;
if dn<sddn*O.9 then
begin
sgsjl:=O:
sgsj:---timegettime;
end:
forml.1abel45.caption:=inttostr(sgsj 1):
form 1.caption:=formatfloat(’O.0’,wycz):
form 1.1abel45.Update;
pdddwyl:=strtofloat .strtofloat
(form1.wypanel.caption):
pdddwy2:=strtofloat(formI.shepanel.caption);
//判断真实烧化长>烧化长并且闪光时间>5s立即顶锻
if((pdddwyl-pdddwy2)>0.1)and(sgsjl>80)then
begin
//vs:--pdddwyl/jz宰XXS;
vs:=strtofloat(forrn 1.wypancl.caption);
vs:--vs*dak+dat;
● vs:=vj-vs
wycz:=pdddwyl-pdddwy2;
goto sal;
end;
Sa:
if(v3>(vj-vs))then ql:=l:
if(v3<-(vj—vS))then //or(sgsjl>60)
begin
if(sgsjl<21)and(kzbshc)then
begin
wyez:=wycz+5;
vs:=strtofloat ( form 1.jccpanel.caption ) -strtofloat
(forml.shepanel.Caption)-wycz;
//vs:--vs/jZ*XXS;
vs:=vs*d甜dat;
vs:=vj·-VS; ·
kzbshe:--false;
goto sa;
end;
sal:
da(vj.VS.vd):
v3:=vj.-VS.-vd:
dycjr:--true;
kzbshc:--true;
t2:--timegettime:
repeat
begin
if((timegettime-starttime)mod 5c>O)thentimekz:=true:
if((timegettime-starttime)mod 5=0)and timekz then
begin
timekz:=false;
readad;
pix:
t4:--timegettime-t2:
if(协((td+0.01)*1000))then
begin
stroutl[8]:=…0:脯电顶锻
form1.edit4.text:=strout l:
forml.exlit4.update;
form 1.shape20.Update;
end:
if(q5=5)then begin q4:exit;end;
end;
end;
until((strtofloat(forml.zhcpanel.caption)-wycz-叫10)>-0.5)or
((timegettime—t2)>2000);
//wycz"=0;
stroutI【8】:=’n’0;
form 1.edit4.text:=stroutI;
forml.edit4.update;
form 1.shape20.Update;
t4:=timegettime-t2; //顶锻时间
p //t7:=gettickcoum;
一 form 1.dspanel.Visible:--true; //显示顶锻速度
form 1.dslabel.Visible:---tme;
ift4>O then form1.dspanel.Caption:=formatfloat(’O.0’,ddc*l 000/t4);
form 1.dspanel.Update;
forml.dslabel.Update;
i:--O;
t2:--timegettime;//冷却时间
ddhddkz:=true;
oldwy:--wy;
maxdd:=O;
ddct:--0;
ctcs:=O;
ii:=l;
dycdd:=false;
decd&=false;
repeat
begin
if((timegettime-starttime)mod 500)then timekz:=true:
if((timegettime-starttime)mod 5=0)and timekz then
begin
readad;
//防止伺放板超调
if((strtofloat(form 1.zhcpanel.caption)-wycz-ddct-wy/l O)
》=0.5) and (ctcs<3)and(form1.cb2.Checked)then
begin
ddct:=(strtofloat(forml.zhcpanel.caption)-wycz-wy/l O):
//da(vj.VS.vd.(ddct*dal(+dat)):
da((wy/lO一0.1)·dak+dat):
ctcs:=ctcs+1;
end;
∥防止伺放板超调
{if((strtofloat(form 1.zhcpanel.caption)一wycz-wy/l O)>.0.2)
and ddhddkz then
begin
ddhddkz:--false;
ddhdd:=wy:
end;
if(abs(wy-ddhdd)/lO>maxdd)and(ddhddkz=-false)then
maxdd:=abs(wy-ddhdd)/1 0;
)
∥假如连续两次向后走0.2MM认为是抖动
ifii=l 0 then
begin
//if wy<oldwy then oldwy:=wy:
if((wy-oldwy)>=2)and(dycdd)thendecdd:--true
elSO dycdd:=false;
if(wy-oldwy)>=2 then dycdd:=true:
oldwy:=wy;
end;
ii:=ii+l: ifii=l 1 then ii:=l;
timekz:=false;
pix;
t4:--timegettime-t2;
i:=i+l:
ifi=200 then H1秒
begin
i:=l:
forml.1qsjpanel.Caption:=formatfloat(’O’,
strtofloat(forml.1qsjpanel.Caption)一1):
form 1.1qsjpanel.update;
end;
ifq5=5 then begin q4; exit: end;
end:
end;
until (t4>--round ( t1·1 00伊卜200 ) ) and ( strtoint
(form 1.1qsjpanel.Caption)<_O);
if (strtoint(form1.Label45.Caption)<2 1) or (strtofloat
(forml.dspanel.Caption)<20)
or(decdd)then
|l捐嘈埝她m㈨㈨
begin
stroutlr61:=’1’;
forml.edit4.text:=stroutl:
forml.edit4.update;
form 1.shape35.Update;
forml.timer2.Enabled:=false:
form 1.buRon l 3.Visible:--true;
wjstr:=’d:\dataV+formatdatetime(’YY.mm’,now)+’.txt’:
assignfile(bjfile,wjstr):
if(findfimt(wjstr,faanyfile,t)=O)then append(bjfile)
else rewrite(bjfile);
writeln(bjfile,forml.1hlabel.caption,’ ’,’时间’,datetimetostr
(now),
·闪光时间..,forml.1abel45.caption,’顶锻速度:’,
form 1.dspanel.caption,
’顶锻后漂移:’,formatfloat(’0.0’,maxdd));
closefile(bjfile);
end;
stroutl【7】:-tl’; //冷却时间到,发信号使PLC电极抬起
form 1.edit4.text:=strout1;
forml.edit4.update:
forml.shape33.Update;
//ifjilu舻-I then iiluzt:=2; //jiluzt=l:完成后退Jilukz=2:完成冷却
if iiluzt=-1 then
begin
jiluzt:=2: //jiluzt=-I:完成后退Jilukz=-2:完成冷却
assignfile(bjfile,filenamel);
if(findfirst(filenamel,faanyfile, t)◇O)then
begin
rewrite(bjfile);
writeln(bjfile,’链环号 ·,’温度 t,t出炉时间
’):
end
else append(bjfile);
wd:--inttostr(900+random(50)):
jjj:=length(filename2);
forjjj:=jjj+l to 20 do filename2:=filename2+¨;
writeln(bjfile,filename2, wd,’ ’,datetimetostr
(now-O.0022));
closefile(bjfile):
end:
starttime:=O:
closejilu:
vs:=strtofloat ( form 1.jccpanel.caption ) ·strtofloat
(form1.shcpanel.Caption);
//vs:=vs/jz*xxs:
vs:=vs*d甜dat:
vs:--vj。VS:
iiluzt:=O:
//kjhkj delay(3000):
repeat
form 1.edit1.text:--inttoasic(inp l(baseio+O));
forml.edit2.text:--inttoasic(inpl(baseio+1));
forml.Editl.Update;
forml.Edit2.Update;
strioinl:=forml.editl.text:
strioin2:--forml.edit2.text:
//if(strioinl【8】=’n’0)or(strioinl[7】_’l’)then
until(strioinl[8]=’o.)or(strioinI[7]='1’);
stroutl[7]:=…0: ∥冷却时间到清除,发信号使PLC电极抬
起
forml.edit4.text:=stroutl:
forml.edit4.update:
forml.shape33.Update: ·.
form1.1qsjpanel.Caption:=floattostr(t1);
q4:
forml.1t1.caption:='40’;
initform:
ql:=5;
end:
end.
|
|