Modbus RTU on M241

tobias_84

Member
Join Date
May 2017
Location
Gothenburg
Posts
3
Hi!

I have been testing to control a servo over modbus RTU from an Schneider TM241C24T but haven't had any success.

I get a output from the PLC but it's not the data I expected.
The goal on this try I attached is to send data to device 01 and use the function 08. Sending test data '12' '12' and it should reply with '12' '12' but there is no respond at all. I can't read that the data output from the PLC is correct so there seems to be a problem with the code I'm running.

Any pointers to get the function working?


I uploaded PDF-files to an other server due to the size.
Schneider Modbus tutorial. Using exemple from page 32.
https://revenhole.tk/s/UAwIZEstzDgzebZ

SMC LEC servo documentation.
Testing the echo function on page 24.
https://revenhole.tk/s/vN5cO9pY0HIIaK1

Output from logic analyzer:
https://revenhole.tk/s/XH1mfaSYC1iNmNS

Screenshots from SoMachine while running is attached.



Code:
PROGRAM POU

VAR
ADDM_MODBUS_LEC			: ADDM;
v_Adress_Modbus_LEC		: ADDRESS ;	
v_xAddress_Done			: BOOL := FALSE ;
v_xAddress_Error		: BOOL := FALSE ;
v_xAddress_Is_OK		: BOOL := FALSE ;
x_Start_ADDM			: BOOL;

Blink_Test_Data			: BLINK;

xRead_test_Data			:BOOL;

Read_Var_Data			: WRITE_READ_VAR;
v_wRegister_Read_Testdata	: WORD := 0 ;

Read_data_1			: UINT ;
Read_data_2			: UINT ;
Read_data_3			: UINT ;
Read_data_4			: UINT ;
Read_data_5			: UINT ;
Read_data_6			: UINT ;
Read_data_7			: UINT ;
Read_data_8			: UINT ;

Write_data_1			: UINT ;
Write_data_2			: UINT ;
Write_data_3			: UINT ;
Write_data_4			: UINT ;
Write_data_5			: UINT ;
Write_data_6			: UINT ;
Write_data_7			: UINT ;
Write_data_8			: UINT ;

Read_Data_Value			: ARRAY [0..7] OF WORD := [8(0)];
Write_Data_Value		: ARRAY [0..7] OF WORD := [8(0)];

END_VAR




// Adressing the device
ADDM_MODBUS_LEC(
	AddrTable	:=	v_Adress_Modbus_LEC,
	Execute		:= x_Start_ADDM,
	Addr		:= '2.1',
	Done		=> v_xAddress_Done,
	Error		=> v_xAddress_Error,
	);

// send test data every 500ms
	Blink_Test_Data.ENABLE	:=	TRUE;
	Blink_Test_Data.TIMELOW	:= T#500MS;
	Blink_Test_Data.TIMEHIGH := T#500MS;
	Blink_Test_Data();
	xRead_test_Data := Blink_Test_Data.OUT ;
	
// Sending (and reading) data over modbus.
Read_Var_Data(
	Execute			:= xRead_test_Data,
	Abort			:= FALSE,
	Addr			:= v_Adress_Modbus_LEC,
	Timeout			:= 5,
	ObjType			:= ObjectType.MW,
	
	FirstWriteObj		:= 08,
	WriteQuantity		:= 2,
	WriteBuffer		:= ADR(Write_Data_Value),

	FirstReadObj		:= 08,
	ReadQuantity		:= 2,
	ReadBuffer		:= ADR(Read_Data_Value),

	
);

 Read_data_1 := WORD_TO_UINT(Read_Data_Value[0]);
 Read_data_2 := WORD_TO_UINT(Read_Data_Value[1]);
 Read_data_3 := WORD_TO_UINT(Read_Data_Value[2]);
 Read_data_4 := WORD_TO_UINT(Read_Data_Value[3]);
 Read_data_5 := WORD_TO_UINT(Read_Data_Value[4]);
 Read_data_6 := WORD_TO_UINT(Read_Data_Value[5]);
 Read_data_7 := WORD_TO_UINT(Read_Data_Value[6]);
 Read_data_8 := WORD_TO_UINT(Read_Data_Value[7]);

 Write_data_1 := WORD_TO_UINT(Write_Data_Value[0]);
 Write_data_2 := WORD_TO_UINT(Write_Data_Value[1]);
 Write_data_3 := WORD_TO_UINT(Write_Data_Value[2]);
 Write_data_4 := WORD_TO_UINT(Write_Data_Value[3]);
 Write_data_5 := WORD_TO_UINT(Write_Data_Value[4]);
 Write_data_6 := WORD_TO_UINT(Write_Data_Value[5]);
 Write_data_7 := WORD_TO_UINT(Write_Data_Value[6]);
 Write_data_8 := WORD_TO_UINT(Write_Data_Value[7]);


Regards
Tobias

Modbus_running.jpg
 
Have you check the communication specifications: Unit number, Baud Rate, Data Bits, Stop Bits and parity?
Check to make sure the communication parameters are the same on each side.
Are you using RS485?
You may want to try a modbus master program running on a computer to test the slave device and vise versa with the master device.

Regards,
 
Have you check the communication specifications: Unit number, Baud Rate, Data Bits, Stop Bits and parity?
Check to make sure the communication parameters are the same on each side.
The settings should be correct. Have checked them multiple times.

Are you using RS485?
Yes

You may want to try a modbus master program running on a computer to test the slave device and vise versa with the master device.

Have tested the slave device with PC with modbus adapter and it works.
Tested with supplied software from manufacturer.
I have not used the logic analyzer on it thou.

I have not try to communicate from the PC to the PLC by modbus.
My knowledge is not that good to make something useful to test that.

I'm hoping to learn more about modbus with this trials and errors!

Regards
Tobias
 
What is Modbus function8?

It is maybe easier if you code with function blocks, ST is hard to read at first
 
The Modbus 08 function code is diagnostics. I'm lazy and don't want to figure out what it's supposed to, so I'll give you an alternative.

My advice: Start by reading a known non-zero value from a holding register using the Modbus 03 Read holding register Function Code.

The 03h function is listed on page 13 and an example at the top of page 22.

The D04xx registers are essentially Modbus Holding registers (4xxxx in Modbus terms), as shown on page 31.

In Modbus a register is 16 bits or 2 bytes.
The example on page 22 to read 4 registers starting at D0400 would give integer values for
Movement Mode in D0400
Speed in D0401
and long 32 bit integer (4 bytes) for Position at F0402

When working with RS-485, be aware that the labels for the driver lines (A/B or +/-) are inconsistent from manufacturer to manufacturer. It should be (+) to (+) or A to A, but sometimes it turns out to be (+) to (-) or A to B. If it doesn't connect, try swapping the driver lines at one end.
 

Similar Topics

Hi , My devices are m241 and atv320 , i did paramaters settings , ı wanna read or write Fr , Current , Voltaga etc. However ı couldn't connection...
Replies
4
Views
2,776
Dear All, i am trying to connect Danfoss inverter with s7 200 cpu 226.but microwin shows following error at DATA Ptr.i assigned different VB...
Replies
1
Views
46
I'm trying to control a device via MODBUS RTU and the ModbusRtuMasterV2_PcCOM in Twincat 3. I've configured a device with the right com port and...
Replies
7
Views
221
Hi all, Currently having trouble getting a speed reference to write over modbus to an Omron M1... I can successfully write a run command and...
Replies
6
Views
252
Hi, I'm having an issue with a mircologix not transmitting out. The current setup is a mircologix 1400 connected to a Guardian 100 Radio...
Replies
1
Views
109
Back
Top Bottom