8

I'm trying to access the Siemens S7-1200 database to set and read tags through a C# executable that I will run on Windows. The intention is to have a desktop app that can establish a connection with a PLC over Wi-Fi / Ethernet. The app will then allow the user to read data off the device (and save in SQL database or .csv, etc.) and send commands to the device (via setting certain tags and then the PLC executes an instruction).

Siemens S7-1200 and S7-1500 devices host a webserver which allows users to create websites and set / read data via that. I've already got that working successfully. I intend to bypass the website and pull data directly from the device. Instead of constantly pulling data from a website.

I've looked at the following already:

Along with a lot of the Siemens tutorials and manuals.

Any ideas on how to set up this connection in C# will be greatly appreciated.

4

1 回答 1

6

I have finally got it to work. Please first read the PDF in this Siemens link. Unfortunately, I can't attach PDF's on Stack Overflow. Then implement the C# code on this Microsoft link. According to the PDF (not explicitly said), the PLC establishes a connection and therefore acts as the client. The PC opens a port and therefore acts as the server.

When setting up the PLC, refer to the attached images. This will help you configure the necessary DB for TX and RX respectively. Use the TSEND and TRCV blocks for TCP connections (as in the PDF). Ensure that the chosen TCP port exists between 2000 and 5000. Siemens does not support higher than that. I used port 4005.

Configure the transmitter such that when you press a button it is coupled to the REQ bit, or set it on a clock high. Please press F1 on the actual block and read about why these bits are set that way. The DB set up is as follows: enter image description here

The RX DB setup is as follows: enter image description here

Do not connect to the PLC through a router! You will need to set up the router to do "port forwarding". Refer to link one and link two for more info on that.

Tip #1: Ensure that the end-of-file delimiter (EOF) in the C# application matches that in the PLC code. Or account for variations of the EOF using string handling in C#. The current EOF is evident in the C# code and the TX_DB.

Tip #2: Remember to always clear the Siemens registers for TX and RX. The image below shows how to do it for TX. Basically you use "String Move".

enter image description here

This is not a perfect or complete solution. But it does work without the need for OPC servers and extracting data from webpages through FTP servers, JSON structures, etc.

于 2016-05-30T08:34:04.360 回答