Hi all. I'm trying to create a comunication script for a Schneider M340 plc.
I've to talk to a Serial converter ( 485 -> 232 ) that talk with a server.
After a lot of test i've discovered the INPUT_BYTE function that works better then the INPUT_CHAR in my case, but I've got some problems writing something from the plc to the server. Not all the send are received.
I've got some problem with intrelocking the 2 communications. In attachment my code, hope someone can help me.
regards
I've to talk to a Serial converter ( 485 -> 232 ) that talk with a server.
After a lot of test i've discovered the INPUT_BYTE function that works better then the INPUT_CHAR in my case, but I've got some problems writing something from the plc to the server. Not all the send are received.
I've got some problem with intrelocking the 2 communications. In attachment my code, hope someone can help me.
regards
Code:
parser_timeout:=INT_TO_BOOL(management_table_R[0] and 2#0000000011111111);
START_DELAY:=FE(parser_timeout);
IF NOT START_DELAY AND NOT Read_In_Progress AND NOT management_table_R[0].0 AND NOT Cmd_Print and not Print_In_Progress THEN
management_table_R[0]:=0;
management_table_R[1]:=0;
management_table_R[2]:=10;
INPUT_BYTE(ADDM('0.0.0'), clear_read, input_length, management_table_R, returned_byte_arr);
SET (Read_In_Progress);
END_IF;
IF Read_In_Progress AND NOT management_table_R[0].0 THEN
if management_table_R[1]=0 then
RESET (Read_In_Progress);
ELSE
(*errore read*)
INC (COM_results[1]);
RESET (Read_In_Progress);
END_IF;
debug_READ[0]:=management_table_R[0] and 2#0000000011111111; (* activity bit *)
debug_READ[1]:=SHR (management_table_R[0], 8); (* exchange number *)
debug_READ[2]:=management_table_R[1] and 2#0000000011111111; (* communication report *)
debug_READ[3]:=SHR (management_table_R[1], 8); (* operation report *)
END_IF;
if START_DELAY then
SET(clear_buffer_READ);
RESET (Read_In_Progress);
for i:=0 to 40 BY 1 do
continue_parsing:=(continue_parsing OR returned_byte_arr[i]>0);
end_for;
if continue_parsing then
CMD_string:=MATCH_CMDS_STRING[BYTE_TO_INT(returned_byte_arr[6])];
set(Cmd_Print);
(*app_returned_byte_arr[test_cmds_index]:=returned_byte_arr[6];
inc(test_cmds_index);*)
reset(continue_parsing);
end_if;
for i:=0 to 40 BY 1 do
returned_byte_arr[i]:=0;
end_for;
reset(START_DELAY);
end_if;
(* scrittura *)
IF Cmd_Print AND NOT management_table_W[0].0 AND NOT Print_In_Progress AND NOT Read_In_Progress THEN
set(Print_In_Progress);
input_string_WRITE:=MATCH_CMDS_STRING[BYTE_TO_INT(returned_byte_arr[6])]; (*int_to_string(COMANDO);*)
(*management_table_W[0]:=0;*)
management_table_W[1]:=0;
management_table_W[2]:=200;
management_table_W[3]:=len_int(input_string_WRITE);
PRINT_CHAR(ADDM('0.0.0'),input_string_WRITE,management_table_W);
input_string_WRITE:='';
END_IF;
IF Print_In_Progress AND NOT management_table_W[0].0 THEN
if management_table_R[1]=0 then
reset(Cmd_print);
SET(clear_buffer_WRITE);
(*print OK*)
INC (COM_results[3]);
RESET (Print_In_Progress);
ELSE
(*errore print*)
INC (COM_results[4]);
END_IF;
debug_WRITE[0]:=management_table_W[0] and 2#0000000011111111; (* activity bit *)
debug_WRITE[1]:=SHR (management_table_W[0], 8); (* exchange number *)
debug_WRITE[2]:=management_table_W[1] and 2#0000000011111111; (* communication report *)
debug_WRITE[3]:=SHR (management_table_W[1], 8); (* operation report *)
END_IF;
if re(clear_buffer_WRITE) then
management_table_W[0]:=0;
SET(management_table_W[0].1);
management_table_W[1]:=0;
management_table_W[2]:=0;
management_table_W[3]:=0;
PRINT_CHAR(ADDM('0.0.0'),'',management_table_W);
reset(clear_buffer_WRITE);
end_if;
if re(clear_buffer_READ) then
management_table_R[0]:=0;
SET(management_table_R[0].1);
management_table_R[1]:=0;
management_table_R[2]:=100;
management_table_R[3]:=0;
INPUT_CHAR(ADDM('0.0.0'),1,input_length,management_table_R,returned_string_READ);
reset(clear_buffer_READ);
end_if;