S7 1200 Modbus RTU Programming Websites
S7 1200 Modbus RTU Programming Websites
Certainly! Here is an example of ladder logic program for Siemens S7-1200 PLC to
communicate with a Modbus slave device over RS485 using Modbus RTU protocol:
MB_CLIENT_INIT initializes the Modbus client on port 1 of the S7-1200 PLC. The client is
configured to communicate over RS485 using the Modbus RTU protocol with a baud rate
of 9600, 8 data bits, no parity, and 1 stop bit. The slave address is not specified here, as it
will be included in the request message later.
MB_CLIENT_SEND sends a request to the Modbus slave to read 2 holding registers starting
at address 40001, using function code 3. The slave address is 1, as specified in the
function call.
MB_CLIENT_WAIT_FOR_RESPONSE waits for a response from the Modbus slave. This
instruction should be used after sending a request, as the response may not be available
immediately.
MB_CLIENT_REQUEST_SUCCESSFUL checks if the Modbus client has successfully received a
response from the slave device. If the client has received a response, this instruction will
be true.
MB_CLIENT_RESPONSE_WORD reads a 16-bit word from the response buffer of the Modbus
client. The response buffer is indexed starting at 0. In this example, the word is read from
index 0 of the response buffer and stored in MW100.
Note that this is a simple example and the specific instructions and addresses used will
depend on the specific requirements of your application and the slave device being used.
Also, make sure to configure the RS485 interface of the S7-1200 PLC correctly for your
particular hardware setup.