Blog

Siemens S7-1200 Serial Communication

Siemens S7-1200 Serial Communication

Today, I found myself setting up some simple point-to-point serial communication on a Siemens S7-1200. For the current application, I was writing a simple function block to broadcast data to a Red Lion serial slave display, but there are a variety of situations in which you may need to do to this, such as communicating with a VFD. While there are many people in this office who do this regularly with other Siemens PLCs, it was the first time for any of us on an S7-1200, so I thought I'd share my experience.

First of all, if this is your first experience doing this, you're in luck. Siemens (and Step 7) makes setting up basic point-to-point communication incredibly simple. The serial slave I was working with was incredibly flexible and accepts both RS-485 and RS-232. I happened to have a CM 1241 RS485 module on hand, so that's what I used.

Hardware Configuration:

The first step is to add the module itself to your device configuration. In Step 7, this is simple as opening up the device configuration device view and dragging the module to your PLC. Once you've added the module, a port identifier for the module will automatically be created. You can view the port number by selecting the module in your device view - you're looking for the hardware identifier. Alternatively, there is a system constant tag created as well - you can find this under your Default Tag Table on the System Constants tab.

Port Configuration:

The next step is to configure your port - set the baud rate, parity, stop bits, etc. Again, you can do all of this directly from the Device Configuration view by scrolling through the properties for the module. If you'd like to configure your port settings dynamically, no problem! There's a simple function block provided (on the instructions palette, located under Communication) called PORT_CFG. This will allow you to fully define your port configuration as needed. I would suggest calling this block using the "FirstScan" bit (%M1.0) to make sure your settings are applied correctly every time the PLC starts.

Sending Data:

Sending data is equally simple - just grab the SEND_PTP function block from the instruction set. In my case, I was broadcasting ASCII text to my slave display, so I wrote a quick function to convert a real to a string, concatenate it with my message header and terminator, and return the resulting string. To make things simple, I used the string length function block included in the extended instructions list to calculate the length of my string.

That's everything you need - send the data!

Receiving Data:

Receiving Data is just as simple. Use the RCV_PTP function block.

That's it! Serial communication is that simple. In fact, Siemens provides instructions for much more complicated communication protocols including blocks for configuring your port as Modbus master or slave, but that's a little beyond my simple example here.

Hope this is helpful! Contact us for more information on our Siemens PLC Programming services.

Learn more about DMC's Siemens S7 PLC expertise.

Comments

Morid
# Morid
Hi Mr.Jason

Can i controll the Maxon EPOS2 70/10 driver ??
how can i do this ???
Vlad
# Vlad
I'm triying to use a s71200 for working as a DMC manager for some CNC machines, so the question is this. Is it possible to send a plain text file over the PLC I mean aim to a directory on the sd card that have te file and send it

Actualy I´m using a PC for that but I wonder if I can get rid of the PC.
Krishna k
# Krishna k
I want to display the weight, measured using weighing machine, in His via s7-1200 could 1214c. Can I use the same configuration. My weighing machine have rs232 port
star123
# star123
Thanks Jason, this was simple to understand. do yo have a project to share, there were few things I didnt understood, like the conversion of real to string and reading the length of the string. I didnt see those blocks in your explanation.

One more thing I was interested was while receiving the message using RCV_PTP how can I filter out a specific message, for example if I receive test1 then i want my DO to do something and if I receive test2 then i want to do something else with my DO. How can I filter out the messages I need in the RCV_PTP.
Mayur Patel
# Mayur Patel
We also tried modbus RS485 ASCII communication for one of our load cell interface device with same Siemens S7-1200 CPU1214C DC\DC|DC and CM 1241 RS485 module in TIA portal V13.We tried too much but it was not happening.So is it possible for you to attach your working program?

Thanks in advance.
Ramnath Mishra
# Ramnath Mishra
Thanks Mr. Jason it is really helpful.
made my work very easy.
Anonymous User
# Anonymous User
PID with a Siemens S7-1200 PLC

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above: