📄 omron_plc_fins.~pas
字号:
begin
result:=true;
sbinstring:=trim(self.OcttoBin(strtoint('$'+s)));
ilen:=length(trim(sbinstring));
swarnmessage:='';
for i:=0 to ilen-1 do
begin
swarnmessage:=warnprocess(copy(sbinstring,ilen-i,1),i,pos);
frmglass.memlog.Lines.Add(datetimetostr(now)+' '+swarnmessage);
end;
end;
function Tomron_Fins.warnprocess(s:string;i:integer;pos:integer):string;
var swarnmessage:string;
begin
swarnmessage:='';
if pos=1 then
begin
case i of
0: if s='1' then
swarnmessage:='加热温度超过最大设定温度!';
1: if s='1' then
swarnmessage:='玻璃长度超过最大设定长度!';
2: if s='1' then
swarnmessage:='低温时间和高温时间有冲突';
3: if s='1' then
swarnmessage:='高温时间和强化时间有冲突';
4: if s='1' then
swarnmessage:='低温加热时间超过设定时间';
5: if s='1' then
swarnmessage:='高温加热时间超过设定时间';
6: if s='1' then
swarnmessage:='玻璃出片时,出片光电被挡';
7: if s='1' then
swarnmessage:='前炉门不能打开';
8: if s='1' then
swarnmessage:='后炉门不能打开';
9: if s='1' then
swarnmessage:='低温或高温编码器故障';
10: if s='1' then
swarnmessage:='高温和强化编码器故障';
11: if s='1' then
swarnmessage:='';
12: if s='1' then
swarnmessage:='';
13: if s='1' then
swarnmessage:='';
14: if s='1' then
swarnmessage:='';
15: if s='1' then
swarnmessage:='';
end;
end;
if pos=2 then
begin
case i of
0: if s='1' then
swarnmessage:='进片电机或变频异常';
1: if s='1' then
swarnmessage:='低温电机或变频异常!';
2: if s='1' then
swarnmessage:='高温电机或变频异常';
3: if s='1' then
swarnmessage:='强化电机或变频异常';
4: if s='1' then
swarnmessage:='出片电机异常';
5: if s='1' then
swarnmessage:='前风栅电机或变频异常';
6: if s='1' then
swarnmessage:='后风栅电机或变频异常挡';
7: if s='1' then
swarnmessage:='炉体电机异常';
8: if s='1' then
swarnmessage:='风机01电机或变频异常';
9: if s='1' then
swarnmessage:='风机02电机或变频异常';
10: if s='1' then
swarnmessage:='';
11: if s='1' then
swarnmessage:='';
12: if s='1' then
swarnmessage:='';
13: if s='1' then
swarnmessage:='';
14: if s='1' then
swarnmessage:='';
15: if s='1' then
swarnmessage:='';
end;
end;
result:=swarnmessage;
end;
function Tomron_Fins.OcttoBin(i: integer): string; //十进制转换为二进制字符串
var
j: integer;
s: string;
begin
j := i;
s := ' ';
while j >= 2 do
begin
if (j mod 2) = 1 then
begin
s := '1' + s;
j := j div 2;
end
else
begin
s := '0' + s;
j := j div 2;
end;
end;
s := chr(ord('0') + j) + s;
result := s;
end;
function Tomron_Fins.maketime(s:string):string;
var stime,shex:string;
begin
stime:=copy(s,47,8);
shex:=chr(strtoint('$'+copy(stime,1,2)))+
chr(strtoint('$'+copy(stime,3,2)))+
chr(strtoint('$'+copy(stime,5,2)))+
chr(strtoint('$'+copy(stime,7,2)));
result:=shex;
end;
function Tomron_Fins.isresponse(buf:Tsbuf):boolean;
begin
result:=false;
if (buf[4]=$46)and(buf[5]=$41) and (buf[8]=$34) and (buf[9]=$30) then
//headcode(4,5位)=FA ICF(8,9字节)=40
result:=true;
end;
function Tomron_Fins.make_response_fcs(buf:Tsbuf;ilength:integer):string;
begin
result:=inttohex(buf[ilength-3],1)+inttohex(buf[ilength-2],1);
end;
function Tomron_Fins.dealCompact(s:string):string;
var
s_tmp,s_sou,s_des:string;
begin
{ if (length(s)<>54) and (length(s)<>62) and (length(s)<>100) then//帧的字节数不够
begin
result:='帧的字节数不够';
exit;
end;}
{ s_sou:=copy(s,3,2); //如果源地址不是31的话,说明不是plc发过来的信息
if s_sou<>'31' then
begin
result:='';
exit;
end;
s_des:=copy(s,5,2);
if s_des<>'30' then
begin
result:='';
exit;
end;
if copy(s,1,2)<>'02' then//没有帧头
begin
result:='';
exit;
end;
if copy(s,19,2)<>'03' then //没有帧尾
begin
result:='';
exit;
end;}
if (length(s)=100) then
s_tmp:=copy(s,85,8)
else
s_tmp:='';
result:=s_tmp;
end;
function Tomron_Fins.calc_response_fcs(buf:Tsbuf;buflength:integer):string;
var i:integer;
sxor:integer;
begin
sxor:=0;
for i:=1 to buflength do
begin
sxor:=sxor xor buf[i];
end;
result:=inttohex(sxor,2);
end;
function Tomron_Fins.calc_response_fcs1(scommand:string):string;
var i,ilength:integer;
sxor:integer;
sbuftmp:string;
begin
sxor:=0;
ilength:=length(scommand);
for i:=1 to ilength do
begin
sxor:=sxor xor ord(scommand[i]);
end;
result:=inttohex(sxor,2);
end;
function Tomron_Fins.MakeSbufSignal(signal: integer): Tsbuf;
var
sbuf:Tsbuf;
FCS1,FCS2:integer;
scontent:string;
begin
if (signal=1) or (signal>=21) then
begin
ssendcommand:='@00FA000000000010182';
self.readorwrite:='read';
end
else
begin
ssendcommand:='@00FA000000000010282';
self.readorwrite:='write';
end;
if (signal=1) then
begin
sSendcommand:=sSendcommand+'044C000014'; //read-memory address d1100~D1119开始20个字(监控)
scontent:=self.calc_response_fcs1(sSendcommand);
sSendcommand:=sSendcommand+scontent+'*'+chr(13);
end;
if (signal=21) then
begin
sSendcommand:=sSendcommand+'03E8000006'; //read-memory address d1000开始6个字(设定值)
scontent:=self.calc_response_fcs1(sSendcommand);
sSendcommand:=sSendcommand+scontent+'*'+chr(13);
end;
if (signal=22) then
begin
sSendcommand:=sSendcommand+'03E800000A'; //read-memory address d1000开始10个字 (设定值)
scontent:=self.calc_response_fcs1(sSendcommand);
sSendcommand:=sSendcommand+scontent+'*'+chr(13);
end;
if (signal=23) then
begin
sSendcommand:=sSendcommand+'04B000001C'; //read-memory address d1200开始28个字 (设定值)
scontent:=self.calc_response_fcs1(sSendcommand);
sSendcommand:=sSendcommand+scontent+'*'+chr(13);
end;
if (signal=24) then
begin
sSendcommand:=sSendcommand+'051400000E'; //read-memory D1300开始14个字(设定值);
scontent:=self.calc_response_fcs1(sSendcommand);
sSendcommand:=sSendcommand+scontent+'*'+chr(13);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -