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.
380 lines
9.0 KiB
380 lines
9.0 KiB
PROGRAM CO485
|
|
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>46 then
|
|
commandsend1:=0;
|
|
end_if;
|
|
end_if;
|
|
end_if;
|
|
|
|
case commandsend1 of
|
|
1,2:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#01;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
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#02;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
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#03;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
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#04;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
9,10:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#05;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
11,12:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#06;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
13,14:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#07;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
15,16:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#08;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
17,18:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#09;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
19,20:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#10;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
21,22:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#11;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
23,24:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#12;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
25,26:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#13;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
27,28:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#14;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
29,30:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#15;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
31,32:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#16;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
33,34:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#17;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
35,36:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#18;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
37,38:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#19;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
39,40:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#20;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
41,42:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#21;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
43,44:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#22;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
sendf1[4]:=16#00;
|
|
sendf1[5]:=16#01;
|
|
CRC4851(CRC_IN :=sendf1 , CRC_LEN :=6 | sendf1[6]:= CRC16H, sendf1[7]:= CRC16L);
|
|
|
|
45,46:
|
|
F_WS1 :=8;
|
|
sendf1[0]:=16#23;
|
|
sendf1[1]:=16#04;
|
|
sendf1[2]:=16#01;
|
|
sendf1[3]:=16#01;
|
|
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#01 then
|
|
LIES8FA01_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=4 and recvf1[00]=16#02 then
|
|
LIES8FA02_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=6 and recvf1[00]=16#03 then
|
|
LIES8FA03_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=8 and recvf1[00]=16#04 then
|
|
LIES8FA04_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=10 and recvf1[00]=16#05 then
|
|
LIES8FA05_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=12 and recvf1[00]=16#06 then
|
|
LIES8FA06_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=14 and recvf1[00]=16#07 then
|
|
LIES8FA07_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=16 and recvf1[00]=16#08 then
|
|
LIES8FA08_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=18 and recvf1[00]=16#09 then
|
|
LIES8FA09_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=20 and recvf1[00]=16#10 then
|
|
LIES8FA10_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=22 and recvf1[00]=16#11 then
|
|
LIES8FA11_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=24 and recvf1[00]=16#12 then
|
|
LIES8FA12_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=26 and recvf1[00]=16#13 then
|
|
LIES8FA13_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=28 and recvf1[00]=16#14 then
|
|
LIES8FA14_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=30 and recvf1[00]=16#15 then
|
|
LIES8FA15_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=32 and recvf1[00]=16#16 then
|
|
LIES8FA16_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=34 and recvf1[00]=16#17 then
|
|
LIES8FA17_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=36 and recvf1[00]=16#18 then
|
|
LIES8FA18_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=38 and recvf1[00]=16#19 then
|
|
LIES8FA19_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=40 and recvf1[00]=16#20 then
|
|
LIES8FA20_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=42 and recvf1[00]=16#21 then
|
|
LIES8FA21_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=44 and recvf1[00]=16#22 then
|
|
LIES8FA22_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
if commandsend1=46 and recvf1[00]=16#23 then
|
|
LIES8FA23_CO2S :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04]));
|
|
end_if;
|
|
END_PROGRAM
|