MBSOpen returning Error 20215

Hello Community,
I’m currently working on a project on AS6.1.1 and I’m using MBSOpen() FB. However, it is returning me Error 20215 - ModBus simulation variable invalid or missing (MBSOpen() and MBSlave() FBK).

Below is how I initialized the FB:

mbSlaveOpen.pDevice 	:= ADR('IF6.ST2.IF1');//This is the Device Name of the Serial Port

mbSlaveOpen.pCoilStat 	:= ADR(gMbRtuServerData.Coils); //pointer to the data source of Coils
mbSlaveOpen.pInputStat	:= ADR(gMbRtuServerData.DiscreteInputs); //pointer to the data source of Discrete Input
mbSlaveOpen.pInputReg	:= ADR(gMbRtuServerData.InputRegisters); //pointer to the data source of Input Registers
mbSlaveOpen.pHoldingReg := ADR(gMbRtuServerData.HoldingRegisters); //pointer to the data source of Holding Registers

mbSlaveOpen.own_ID 		:= 1;//Modbus Unit ID

serialModeStr 			:= '';

brsstrcat(ADR(serialModeStr),ADR('/BD=57600'));//Baud Rate (300|600|1200|2400|4800|9600|19200|38400|57600|115200)
brsstrcat(ADR(serialModeStr),ADR(' '));//Delimeter

brsstrcat(ADR(serialModeStr),ADR('/PA=E'));//Parity (N|E|O|H|L)
brsstrcat(ADR(serialModeStr),ADR(' '));//Delimeter

brsstrcat(ADR(serialModeStr),ADR('/DB=8'));//Data bits (7|8)
brsstrcat(ADR(serialModeStr),ADR(' '));//Delimeter

brsstrcat(ADR(serialModeStr),ADR('/SB=1'));//Stop bits (1|2)
brsstrcat(ADR(serialModeStr),ADR(' '));//Delimeter

brsstrcat(ADR(serialModeStr),ADR('/PHY=RS422'));//Physical Properties (RS232|RS422|RS485|TTY|RS422BUS|LIN)
brsstrcat(ADR(serialModeStr),ADR(' '));//Delimeter

brsstrcat(ADR(serialModeStr),ADR('/RIT=4'));//Receive idle time Number of characters (1-65535)
brsstrcat(ADR(serialModeStr),ADR(' '));//Delimeter

brsstrcat(ADR(serialModeStr),ADR('/TIT=5'));//Transmit idle time Number of characters (1-65535)

mbSlaveOpen.pMode		:= ADR(serialModeStr);
mbSlaveOpen.timeout		:= 60000;//1 minute

serialIdent := 0;
step := 0;


These are just array of BOOL and UINT.

Does anyone have idea of why the FB is returning Error 20215? Thanks in advance.

Regards,
Alvin

Hi,

according to the help here: B&R Online Help
In the section with the heading “pCoilStat, pInputStat, pInputReg, pHoldingReg”
it says this:

So your example should be

mbSlaveOpen.pCoilStat 	:= ADR('gMbRtuServerData.Coils'); //pointer to the data source of Coils
mbSlaveOpen.pInputStat	:= ADR('gMbRtuServerData.DiscreteInputs'); //pointer to the data source of Discrete Input
mbSlaveOpen.pInputReg	:= ADR('gMbRtuServerData.InputRegisters'); //pointer to the data source of Input Registers
mbSlaveOpen.pHoldingReg := ADR('gMbRtuServerData.HoldingRegisters'); //pointer to the data source of Holding Registers

Note how I surrounded your variables with apostrophes.

Also make sure to use one of the variables in code as well, otherwise the variable will be thrown away by the compiler, so maybe simply add
gMbRtuServerData.Coilds[0] = FALSE;
to the init section of your program

Best regards


P.S.: Your mode string can be all in one line (imo improving the readability over the various string concatenations), if you want to document what each of the names is, add a comment above:

(* BD = Baudrate, PA = Parity (E=Equal), DB = Databits, SB = Stopbits,
   PHY = Physical properties (RS232 or rs485), RIT = Receive Idle Time,
   TIT = Transfer Idle Time *)
brsstrcat(ADR(serialModeStr), ADR('/BD=57600 /PA=E /DB=8 /SB=1 /PHY=RS422 /RIT=4 /TIT=5'));

And then as a next step you can get rid of a separate variable altogether and use that string in the pMode assignment directly :slight_smile:

2 Likes

Hi Michael,

Thanks for the reply. The issue was resolved by using the variables in the code.

Regards,
Alvin

Hi there,

thanks for the feedback and glad it works for you now.

Question: Does it work using your original assignments like
mbSlaveOpen.pCoilStat := ADR(gMbRtuServerData.Coils);
or did you also have to change them to the ones I said, passing them as
mbSlaveOpen.pCoilStat := ADR('gMbRtuServerData.Coils' ); ?

Just asking so I know that part for sure for the next time as well :slight_smile: