Modbus RTU Ladder Logic Example for Siemens TIA Portal
The following is an example TIA Portal Ladder Logic project for a 2 wire RS485
Modbus RTU Project.
All the functions defined The Tag Table (system bytes enabled in CPU)
Main [OB1]
King Wick, Alduras Inc Page 1 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Pull or Plug of Modules [OB83]. Same code in Rack or Station Failure [OB86].
King Wick, Alduras Inc Page 2 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
GetAllModbus FC. Note the PORT name (found in the CM Ptp module’s Properties-
>System Contants tab) requires double quotes to work here: better than just hardwiring
the HWID in my opinion.
The GetAllModbus FC just calls the primary FB that does all the work
ModbusWordsToReal
Converts two Modbus floating point words read from a Modbus device to a Siemens real.
King Wick, Alduras Inc Page 3 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
MB485_Definitions DB – MUST have ‘optimized block access’ disabled
Modbus_MasterRead FB variables defined
Includes a number of error and status variables to watch communications for debug
King Wick, Alduras Inc Page 4 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Networks within MB485_MasterRead FB
King Wick, Alduras Inc Page 5 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Network 1 & 2
King Wick, Alduras Inc Page 6 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Network 2, 3, 4
King Wick, Alduras Inc Page 7 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Network 5 Modbus_Comm_Load
Regardless of settings you may have configured for the hardware, you need to force it
into 2 wire RS485 here. The hardware settings get ignored for some strange reason.
King Wick, Alduras Inc Page 8 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Network 6, 7
King Wick, Alduras Inc Page 9 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Network 8, 9
King Wick, Alduras Inc Page 10 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Network 10, 11
King Wick, Alduras Inc Page 11 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Network 12
Network 13
King Wick, Alduras Inc Page 12 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Network 14
King Wick, Alduras Inc Page 13 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Network 15
Note this code is device specific: we are reading the device Modbus registers that tell us
the device is ready to give good readings (fully powered up and running). Not all
Modbus devices have such registers.
King Wick, Alduras Inc Page 14 of 15 March 25, 2017
Modbus RTU Ladder Logic Example for Siemens TIA Portal
Network 16 Convert two Modbus 16 bit words to Siemens 32 bit real
King Wick, Alduras Inc Page 15 of 15 March 25, 2017