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!
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”:
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
Hi @MDParvezSarkar ,
step by step…
function 1 only support PV type BOOL/SINT/USINT, but in your case:

so there is an issue on data type.
I think there is a second issue on MBMCmd:
a) Now node = 1, but on dataobj node = 3
b) you write the same PV (DataPV1, type INT[0..4]) for mfc = 1 and mfc = 3 but you can’t
Ciao
Valerio
I will try to read holding registers at addresses 40001 and 40002 (data length: 2) via Modbus, using slave ID 1, with the following serial settings: baud rate 9600, parity None, 8 data bits, and 1 stop bit. When I check using Modpoll with this same configuration, the connection is established successfully and I can see the values correctly — address 1 = 27 and address 2 = 45. However, although the connection on the B&R PLC side also appears to establish okay, the PLC is not receiving the data.
Hello,
could you please show the content of your data object here? Please also check the wiring to the slave.
regards
Hello,
You’ve written:
The first line reads 5 holding registers from station number 1 starting from offset 0 (HoldingRegister 0) using Modbus Function 3 (Read holding registers) when modbus_m:EventPV1 is set to true.
The second line reads 3 holding registers from station number 1 starting from offset 0 (HoldingRegister 0) using Modbus Function 3 (Read holding registers) when modbus_m:EventPV2 is set to true.
For an explanation, see help.
Is this what you want?
Hi @MDParvezSarkar ,
in your case I see MBMOpen.timeout = 2000, so timeout is configured in correct way, I hope the other settings too (parity, baud rate, stop bit…), maybe now it’s time to connect a serial sniffer and see all raw data when you send and receive a message.
In the past, a customer gave me wrong baud rate (9600) for a sensor and as you see below I had the same error than yours 20220 in the function block and no message back when I sent my command:
after, with correct settings (baud rate 115200), I got the message:
Ciao
Valerio









































