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#0B; 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#0C; 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#11; 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#1C; 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#0B then LIESB1C01_CO :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04])); end_if; if commandsend1=4 and recvf1[00]=16#0C then LIESB1C02_CO :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04])); end_if; if commandsend1=6 and recvf1[00]=16#11 then LIESB1C03_CO :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04])); end_if; if commandsend1=8 and recvf1[00]=16#1C then LIESB1C04_CO :=(BYTE_TO_REAL(recvf1[03])*256.0+BYTE_TO_REAL(recvf1[04])); end_if; END_PROGRAM