Issues on M340 rs485 communication

g3nti

Member
Join Date
Nov 2015
Location
Turin
Posts
2
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

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;
 
Hi gclshortt and thanks for the answer.

The problem is thant the device I need to talk to wors just in rs232. Thanks for the useful links
 

Similar Topics

Hi friends, I have programmed an M340 PLC (BMXP341000 Processor) using Unitypro XL and ran out of the trial period. Yesterday I installed a...
Replies
2
Views
2,126
Greetings, I'm using Unity Pro v8 (131118) with Modicon M340. I cut my teeth on PLCs with Modicon back in the early 90s but this is my first...
Replies
2
Views
2,661
Hello, I am currently in the final week of my internship and I have encountered issues with communication between a PowerFlex 700 variable...
Replies
0
Views
49
Hello everyone, I've had this issue for the last 2 days where I try to assign the profisafe address to an IO block (6ES7 146-6FF00-0AB0) but when...
Replies
5
Views
143
I'm at a loss here and hoping someone else has seen this: Background: We've got two identical machines on our floor (we'll call them machine A &...
Replies
0
Views
69
Back
Top Bottom