Mod Bus Rtu Example
Mod Bus Rtu Example
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]
Pull or Plug of Modules [OB83]. Same code in Rack or Station Failure [OB86].
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.
Includes a number of error and status variables to watch communications for debug
Network 1 & 2
Network 2, 3, 4
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.
Network 6, 7
Network 8, 9
Network 10, 11
Network 12
Network 13
Network 14
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.