Modbus RTU Master Not Working on RS485 (X20CP0484) and Modbus Card (X20CS1030)

I created a Modbus RTU Slave program on a B&R X20CP0484 using Automation Studio 6.5, with a Modbus device X20CS1030. I am sharing screenshots 1 to 8 showing my code and configuration, Local Variable. Datamod, but communication is not working. Can anyone help me identify what is wrong?

Hi,

your MBMopen instance has status 20241, which could mean “data module not found”.
Please check if your data module is deployed (assigned to the PLC), and which name the deployed module has (check the SW configuration for thw deployed modules).

I’m not completely sure, but from screenshot 4 it looks like the name of the module is “DataObject”, not “datmod” (“datmod” is the name of the code file, but the parent object in logical view seems to be different, and this parent object name is normally the one of the compiled object in the PLC).

Best regards!

Example of Modbus Master in Structured Text its Example Code,

use data

file name.

Hello,

You can use the DataObject name instead of fileName.dat
Please try code below;
MBMOpen_xx.pConfig := ADR(DataObject);

The image below is part of the ST code I use MODBUS RTU.

Best Regards,

Hi,

from your screenshot, the data object has the name “DataObject”:

This leads to a deployed data object with the name “DataObject”, see my example screenshot here:

But from your screenshot, you’re addressing a module with name “datamod” in your code:

So you’ve either to change the name from “DataObject” to “datamod”, or change the name in the code to “DataObject”.
For example, change the name in the Logical View to “datamod”:

I changed the Data Object name and updated the new object name in the code accordingly. However, I am still not receiving any data. Could you please check if I have missed any configuration or made any mistakes?

Now, your MBMopen instance is in a different error state 20242.
As long as MBMopen returns a status unequal 0, no data exchange can be executed anyway.

Error 20242 means that some event variable definition in your data module is wrong, for example a variable is used which is not declared or installed in the PLC.

Please note that variables are only installed in the PLC, if the’re used somewhere in the task code → if the’re just declared but nowhere referenced in any executing code file, the variables do not exist in the PLC → a data module is not a executing code file. So to ensure that every declared variable is installed inside the PLC, you can a.) check the compiler warnings for “unused variables”, and b.) just call the variables once in INIT UP.

Some more information about the data module and devent variables can be found in this thread:

i will Share Full Details Check it and please how to Solve it.

------------------datamod.dat Code---------------

;--------------------
; Modbus command file
;--------------------
"EventPV1 ", 01, 3, “modbus_m:DataPV1”, 0000, 0005
"EventPV2 ", 01, 3, “modbus_m:DataPV2”, 0000, 0003

------------------datamod.dat Code---------------

---------------------Main Code-------------------

PROGRAM _INIT

S1:=0;
S2:=1;
EventPV1:=1;
EventPV2:=1;
DataPV1[0] := 0;
DataPV1[1] := 0;
DataPV1[2] := 0;
DataPV1[3] := 0;
DataPV1[4] := 0;
DataPV2[0] := 0;
DataPV2[1] := 0;
DataPV2[2] := 0;
MBMOpen_xx.enable:=1;
MBMOpen_xx.pDevice := ADR('IF6.ST2.IF1');
MBMOpen_xx.pMode := ADR('/PHY=RS485 /PA=N /DB=8 /SB=1 /BD=9600');
MBMOpen_xx.pConfig:=ADR('datamod');
MBMOpen_xx.timeout:=2000;
MBMOpen_xx.ascii:=0;
MBMOpen_xx();

END_PROGRAM

PROGRAM _CYCLIC

EventPV1:=1;
EventPV2:=1;
IF(S1=0)THEN
	MBMaster_xx.enable:=1;
	MBMaster_xx.ident:=MBMOpen_xx.ident;
	MBMaster_xx();
ELSE
	MBMCmd_xx.enable:=1;
	MBMCmd_xx.ident:=MBMOpen_xx.ident;
	MBMCmd_xx.mfc:=3;
	MBMCmd_xx.node:=1;
	MBMCmd_xx.data:=ADR(DataPV1);
	MBMCmd_xx.offset:=0;
	MBMCmd_xx.len:=2;
	MBMCmd_xx();
END_IF
IF(S2=0)THEN
	MBMClose_xx.enable:=1;
	MBMClose_xx.ident:=MBMOpen_xx.ident;
	MBMClose_xx();
END_IF

END_PROGRAM

PROGRAM _EXIT
(* Insert code here *)

END_PROGRAM

---------------------Main Code-------------------

Hi,

I’m away from keyboard now, so I can’t dig deeper into.

But it looks like that your event pv’s are local variables too, like the data pvs.
So you have to address them in the datamodule in the same way like the data pvs with “< taskname>:< variablename>”

Example for the 1st line:
"modbus_m:EventPV1 ", 01, 3, “modbus_m:DataPV1”, 0000, 0005

I will Change datamod code, Now Show Error Code is 20210