Skip to main content

Guides

Reading data from a Siemens S7 PLC: PUT/GET, rack/slot and DB addressing

Every step from two settings in the PLC to seeing the DB variables with quality Good on the Tag States screen.

2Win Scada talks to Siemens S7 PLCs over Ethernet with ISO-on-TCP (TCP 102) and reads PLC variables by absolute address. In this guide we read six variables from a data block (DB) of an S7-1200: two bits, an integer, a floating-point value, a counter and a text string. First we make the two settings needed on the PLC side, then we define the channel, device and tags in 2Win Scada and check the values on screen. On the S7-300 and S7-400 the PLC-side settings are not needed; the remaining steps are the same.

Before you start

You need:

  • The PLC's network details. The IPv4 address of the CPU or its Ethernet module. The 2Win Scada server must reach this address on TCP port 102; if there is a firewall in between, that port must be open.
  • The CPU family and hardware configuration. Which family the CPU belongs to (S7-1200, S7-1500, S7-300, S7-400 …) and the CPU's rack and slot numbers. You find these in the hardware configuration of the PLC project.
  • The list of variables to read. For each variable, the DB number, the start address inside the DB (offset) and the data type in the PLC. In TIA Portal these are in the Offset and Data type columns of the DB editor.
  • The right to change and download the PLC project. On the S7-1200 and S7-1500, the two settings in step 1 are made in the PLC project and downloaded to the PLC.
  • A running 2Win Scada installation. Siemens S7 is included in every package. Each device and tag you add counts toward the license capacity; the package capacities are on the Licensing page.
  • The right to make definitions. Managing channel, device and tag definitions with your own team is included in the Professional package; in Starter and Standard it can be added to your quote, otherwise your integrator makes these definitions.

Example data block

For this guide we assume a communication DB numbered DB10 in the PLC, used only to hand data to SCADA. The variable names and values are examples.

VariableData typeOffsetMeaning
CalisiyorBool0.0Line running
ArizaBool0.1Fault present
Hat_HiziInt2.0Line speed (pieces/min)
SicaklikReal4.0Oven temperature (°C)
Toplam_AdetDInt8.0Production counter
Recete_AdiString[20]12.0Name of the running recipe

The Offset column appears once optimized block access is switched off in step 1 and the block is compiled. The addresses in 2Win Scada are written from this column.

1. Prepare the PLC side (S7-1200 and S7-1500)

2Win Scada reads the PLC's DBs with the PUT/GET read and write services of classic S7 communication, by absolute address. On the S7-1200 (firmware 4.0 and later) and the S7-1500 this access is off by default, and two settings are needed. The S7-300 and S7-400 have no such settings; go straight to step 2.

Permit PUT/GET access. In TIA Portal, open the CPU properties and, under Protection & Security (Protection in older TIA Portal versions) > Connection mechanisms, select Permit access with PUT/GET communication from remote partner. Without this permission the connection cannot be established or the PLC rejects the read requests. The CPU's protection level (access level) settings may also affect this access; if the connection cannot be established, check this setting as well.

Switch off optimized block access in the DBs used. Right-click each DB to be read, clear Optimized block access under Properties > Attributes and compile the block. Variables in an optimized DB have no fixed address; absolute addresses such as DB10.DBW2, which 2Win Scada uses, only make sense while this option is off.

Download the changes to the PLC. Note three points:

  • The PUT/GET permission is part of the hardware configuration; TIA Portal may ask to put the CPU into STOP for this download. Do it during a planned stop.
  • Because the access type of the DB changes, TIA Portal reinitializes the DB during the download; the DB's current values return to their start values. That is why, instead of changing the setting of an existing production DB, it is often safer to create a separate communication DB, as in the example, and copy the values into it in the PLC program.
  • PUT/GET access requires no authentication: any client on the same network can read and write the permitted areas. Keep the PLC on a separate network together with the SCADA server.

2. Create the channel

  1. Open Settings > Tag Management from the left menu.
  2. Click the + button in the header of the Channels tree.
  3. On the General tab, type Hat1 in the Name field.
  4. Select SiemensTcp in the Connection Type list and click Save.

A Siemens channel has no connection settings; the IP address, rack and slot are entered on each device. You can add more than one PLC under the same channel.

3. Define the device (the PLC)

  1. In the tree, right-click the Hat1 channel and select New Device.
  2. On the General tab, type PLC1 in the Name field and select the Active check box. If this box is not selected, the device is saved but no connection to the PLC is made.
  3. Fill in the Parameters tab:
    • Cpu Type: the PLC family. In our example S71200. The list contains S7200, Logo0BA8, S7200Smart, S7300, S7400, S71200 and S71500.
    • Ip: the PLC's IPv4 address (for example 192.168.0.10). The default 255.255.255.255 is only a placeholder.
    • Port: stays 102.
    • Rack and Slot: the CPU's position in the hardware configuration; see the table below.
    • Timeout [ms]: the wait time for a read or write response; the default 3000 suits most networks.
  4. Click Save.

Device Definition window, Parameters tab: Cpu Type S71200, Ip 192.168.0.10, Port 102, Rack 0, Slot 1, timeout 3000 ms; the tabs General, Parameters and Advanced Parameters at the top

Screenshot: 2Win Scada 2.11.5, the Parameters tab of a Siemens S7 device; the IP address is an example value.

Typical Rack and Slot values:

PLCRackSlot
S7-1200 / S7-150001 (0 in some configurations)
S7-30002
S7-4000The CPU slot in the hardware configuration

A wrong rack or slot value, especially on the S7-300 and S7-400, prevents the connection even when the IP address is correct. On the S7-400 the CPU is often in the slot after the power supply; read the number from the hardware configuration.

4. Define the tags

Click the PLC1 device in the tree; the device's tag table opens on the right. The + button on the toolbar opens a new editable row. Enter the rows below and save each with the floppy disk button at the end of the row.

NameAddressData TypeLengthUpdate Interval[s]Unit
CalisiyorDB10.DBX0.0Bool11
ArizaDB10.DBX0.1Bool11
Hat_HiziDB10.DBW2Int11adet/dk
SicaklikDB10.DBD4Real11°C
Toplam_AdetDB10.DBD8DInt11adet
Recete_AdiDB10.DBB12String201

The example uses Turkish names and units (adet/dk = pieces per minute, adet = pieces); the Unit field is free text.

The address is made of the DB number and the start byte from the Offset column:

  • Bool variables need a bit address: DBX + byte + dot + bit. Ariza, at offset 0.1, becomes DB10.DBX0.1. A bit address is used only for Bool tags.
  • For the other types the letter only marks the start byte: write DBW for 2-byte types (Int, Word), DBD for 4-byte types (DInt, DWord, Real) and DBB for text and single bytes. The Data Type decides how many bytes are read, so the data type must match the type in the PLC.
  • For a String tag the address is the start byte of the STRING variable, and the Length field holds the maximum number of characters defined in the PLC (20 for STRING[20]). For other types Length stays 1.
  • Addresses are written in upper case without spaces. A comma as in DB10,DBW2 and lower case as in db10.dbw2 are not accepted.
  • LInt, ULInt and LWord are not supported; copy such a variable to a DInt, DWord or LReal variable in the PLC program and read that one. SINT is not supported either; copy a SINT variable to an INT variable in the PLC program and read it as Int. WSTRING and arrays are not supported; define a separate tag for each array element.

The same applies to the areas outside DBs: inputs are written as I0.0 or IW64, outputs as Q0.1 or QB1, and the memory area as M10.3 or MD40.

New tags open with Read Only selected; 2Win Scada does not write to these tags. If writing is needed, clear the box only after checking the PLC program and process safety.

Tag Management page: on the left the Channels tree with channel Hat1 and device PLC1, on the right the PLC1 tag table; Ariza DB10.DBX0.1 Bool, Calisiyor DB10.DBX0.0 Bool, Hat_Hizi DB10.DBW2 Int adet/dk, Recete_Adi DB10.DBB12 String length 20, Sicaklik DB10.DBD4 Real °C, Toplam_Adet DB10.DBD8 DInt adet; update interval 1 s, Read Only selected

Screenshot: 2Win Scada 2.11.5, the six tags of the example DB. The table is sorted by name. The search box of the channel tree shows its placeholder in Turkish (Ara) in this version.

When the tag list changes, the device needs a restart. Click the Reinitialize Device button shown next to the device in the tree.

Fewer read requests

2Win Scada combines tags with the same Update Interval[s] that lie close together in the same memory area (the same DB, I, Q or M) into one read request: the gap between them can be at most 30 bytes and one request at most 200 bytes. The six example tags are read from the first 34 bytes of DB10 in a single request. This is another benefit of keeping the variables for SCADA next to each other in a communication DB.

5. Check the values

  1. Open Monitoring > Tag States.
  2. Select Hat1 in the Channels field and PLC1 in the Devices field, then click Update.

The table shows the Value, Unit and Quality columns of each tag. If Quality is Good, the value is read correctly from the PLC. Bool values appear as 1 and 0. Compare the values with the watch table in TIA Portal.

Tag States page: Hat1 in the Channels filter, PLC1 in the Devices filter; the table shows Calisiyor 1, Ariza 0, Hat_Hizi 120 adet/dk, Sicaklik 68.5 °C, Toplam_Adet 15284 adet, Recete_Adi URUN-A; all six with quality Good

Screenshot: 2Win Scada 2.11.5, Tag States; the values are read from an S7 simulator that serves the fixed values of the example DB.

You can also see the device's connection state on the Monitoring > Device States page. If the connection cannot be established, 2Win Scada retries no more than once every 30 seconds; after correcting a setting, wait about half a minute to see the result.

Troubleshooting

SymptomChecks
The device does not connect, all tags are BadCheck the Active box, the Ip value, network access and TCP 102 in the firewall. Confirm that Cpu Type, Rack and Slot match the hardware configuration.
Cannot connect to an S7-1200 / S7-1500, or reads are rejectedCheck that the PUT/GET permission is selected, that the change was downloaded to the PLC and that the CPU protection level allows the access.
Connected, but the tags of one DB are BadCheck that the DB exists in the PLC, that the address stays within the DB size and, on the S7-1200 / S7-1500, that Optimized block access is off. A failed read on an open connection makes only the tags of that request Bad.
Quality Good but the value makes no senseCheck that the Data Type matches the type in the PLC and that the address points to the start byte of the variable. If variables were added to or removed from the DB, the offsets may have moved; compile the DB and read the Offset column again.
The tag is not savedUse a bit address for a Bool tag (DB10.DBX0.0) and a byte, word or double word address for the other types (DB10.DBW2); write the address in upper case. The error message shows the reason.
Text is missing or garbledCheck that the Length matches the STRING[n] definition in the PLC and that the address is the start byte of the STRING variable.

What next

  • Communication alarm: The Quality tags button in the tag table adds the _ConnError and _TagQualityBad tags that watch the device connection; you can define alarms on them.
  • Consumption from a counter: How to get daily and monthly figures from an ever-increasing counter such as Toplam_Adet is covered in Daily and monthly consumption reports from a kWh counter; the same approach works for piece counters.
  • Supported PLC families and other protocols: the Protocols page.

Related pages in the manual:

If you would like to see these steps with your own PLC, we can show them in a demo meeting.

All guides