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.