0% found this document useful (0 votes)
12 views1 page

S7 1200 Modbus RTU Programming Websites

This document provides a sample ladder logic program for Siemens S7-1200 PLC to communicate with a Modbus RTU slave device over RS485. It includes initialization of communication settings, sending requests to read holding registers, and handling responses. The program demonstrates how to check for successful requests and read data from the response buffer.

Uploaded by

KS Lai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

S7 1200 Modbus RTU Programming Websites

This document provides a sample ladder logic program for Siemens S7-1200 PLC to communicate with a Modbus RTU slave device over RS485. It includes initialization of communication settings, sending requests to read holding registers, and handling responses. The program demonstrates how to check for successful requests and read data from the response buffer.

Uploaded by

KS Lai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

an generate siemens 1200 PLC modbus RTU sample ladder programming

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:

scss Copy code

// Initialize communication settings MB_CLIENT_INIT(1, 9600, 8, 'N', 1, 1); //


Read Holding Registers from Modbus slave LD MB_CLIENT_REQUEST_BUSY(1); LD
MB_CLIENT_REQUEST_SUCCESSFUL(1); LD MW100 = MB_CLIENT_RESPONSE_WORD(1, 0); //
Send a request to read Holding Registers MB_CLIENT_SEND(1, 1, 40001, 2); // Wait
for the response MB_CLIENT_WAIT_FOR_RESPONSE(1); // Check if the request was
successful IF MB_CLIENT_REQUEST_SUCCESSFUL(1) THEN // Request successful, read
the data from the response buffer LD MW100 = MB_CLIENT_RESPONSE_WORD(1, 0); ELSE
// Request failed, handle the error here ENDIF

Here's an explanation of the program:

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.

You might also like