You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
2.8 KiB
141 lines
2.8 KiB
3 months ago
|
PROGRAM TH4851
|
||
|
VAR_EXTERNAL
|
||
|
|
||
|
END_VAR
|
||
|
|
||
|
VAR_GLOBAL
|
||
|
|
||
|
END_VAR
|
||
|
|
||
|
VAR
|
||
|
|
||
|
sendf1 : array[0..200] of byte;(*����16����*)
|
||
|
recvf1 : array[0..200] of byte;(*������*)
|
||
|
calcf1 : array[0..200] of byte;(*������*)
|
||
|
recvb4851 :NW_serrecv;
|
||
|
sendb4851 :NW_sersend;
|
||
|
send_act1 :BOOL;
|
||
|
recv_act1 :BOOL;
|
||
|
CRC4851 :BS_GETCRC16;
|
||
|
t1 :TON;
|
||
|
t1_in :BOOL;
|
||
|
t1_q :BOOL;
|
||
|
t2 :TON;
|
||
|
t2_in :BOOL;
|
||
|
t2_q :BOOL;
|
||
|
t3 :TON;
|
||
|
t3_in :BOOL;
|
||
|
t3_q :BOOL;
|
||
|
timer1 :TON;
|
||
|
timer1_run :BOOL;
|
||
|
timer2 :TON;
|
||
|
timer2_run :BOOL;
|
||
|
commandsend1 :int;
|
||
|
F_WS1 :int;
|
||
|
recv_len :int;
|
||
|
recv_len1 :int;
|
||
|
recv_len2 :int;
|
||
|
recv_len3 :int;
|
||
|
recv_len4 :int;
|
||
|
recv_CRCH :byte;
|
||
|
recv_CRCL :byte;
|
||
|
sendp1 :pointer;
|
||
|
recvp1 :pointer;
|
||
|
i :int;
|
||
|
j :int;
|
||
|
|
||
|
test_mode1 :bool;
|
||
|
|
||
|
END_VAR
|
||
|
t1_in:=not t1.q;
|
||
|
t1(IN :=t1_in , PT :=t#600ms );
|
||
|
t2(IN :=t1_in , PT :=t#350ms );
|
||
|
|
||
|
if t2.q=1 and t2_q=0 then
|
||
|
recv_act1:=1;
|
||
|
else
|
||
|
recv_act1:=0;
|
||
|
end_if;
|
||
|
|
||
|
if t1.q=0 and t1_q=1 then
|
||
|
send_act1:=1;
|
||
|
else
|
||
|
send_act1:=0;
|
||
|
end_if;
|
||
|
|
||
|
if t1.q and t1_q=0 then
|
||
|
if test_mode1=0 then
|
||
|
commandsend1:=commandsend1 + 1;
|
||
|
if commandsend1>12 then
|
||
|
commandsend1:=0;
|
||
|
end_if;
|
||
|
end_if;
|
||
|
end_if;
|
||
|
|
||
|
case commandsend1 of
|
||
|
1,2:
|
||
|
F_WS1 :=8;
|
||
|
sendf1[0]:=16#07;
|
||
|
sendf1[1]:=16#04;
|
||
|
sendf1[2]:=16#00;
|
||
|
sendf1[3]:=16#00;
|
||
|
sendf1[4]:=16#00;
|
||
|
sendf1[5]:=16#01;
|
||
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
||
|
3,4:
|
||
|
F_WS1 :=8;
|
||
|
sendf1[0]:=16#09;
|
||
|
sendf1[1]:=16#04;
|
||
|
sendf1[2]:=16#00;
|
||
|
sendf1[3]:=16#00;
|
||
|
sendf1[4]:=16#00;
|
||
|
sendf1[5]:=16#01;
|
||
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
||
|
|
||
|
5,6:
|
||
|
F_WS1 :=8;
|
||
|
sendf1[0]:=16#17;
|
||
|
sendf1[1]:=16#04;
|
||
|
sendf1[2]:=16#00;
|
||
|
sendf1[3]:=16#00;
|
||
|
sendf1[4]:=16#00;
|
||
|
sendf1[5]:=16#01;
|
||
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
||
|
7,8:
|
||
|
F_WS1 :=8;
|
||
|
sendf1[0]:=16#1D;
|
||
|
sendf1[1]:=16#04;
|
||
|
sendf1[2]:=16#00;
|
||
|
sendf1[3]:=16#00;
|
||
|
sendf1[4]:=16#00;
|
||
|
sendf1[5]:=16#01;
|
||
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
||
|
|
||
|
|
||
|
end_case;
|
||
|
|
||
|
sendb4851(EN :=send_act1 , COM :=1 , DATA :=sendp1 , LENGTH :=F_WS1 );
|
||
|
recvb4851(EN :=recv_act1 , COM :=1 , DATA :=recvp1 );
|
||
|
|
||
|
sendp1:=&sendf1;
|
||
|
recvp1:=&recvf1;
|
||
|
|
||
|
t1_q:=t1.q;
|
||
|
t2_q:=t2.q;
|
||
|
|
||
|
|
||
|
if commandsend1=2 and recvf1[00]=16#07 then
|
||
|
LIESB1F01_CO :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
||
|
end_if;
|
||
|
if commandsend1=4 and recvf1[00]=16#09 then
|
||
|
LIESB1F02_CO :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
||
|
end_if;
|
||
|
if commandsend1=6 and recvf1[00]=16#17 then
|
||
|
LIESB1F03_CO :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
||
|
end_if;
|
||
|
if commandsend1=8 and recvf1[00]=16#1D then
|
||
|
LIESB1F04_CO :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
||
|
end_if;
|
||
|
|
||
|
|
||
|
END_PROGRAM
|