Siemens#Let’s Try Using DPWR_DAT/DPRD_DAT with the S71200-G2 and S71500!

In this article, we will build communication between S71200-G2 and S71516F-3 via Profinet. The S71516F side acts as the IO controller, and the S71200G2 acts as the IO device. In addition, in this article we will use DPWR_DAT and DPRD_DAT to update IO data.

Now, let’s enjoy FA!

Reference Link

http://soup01.com/ja/category/siemens-jp/s7%e2%80%901200-g2/

Data Consistency

A data area whose contents are not modified during processing even when multiple processes are running simultaneously is called a *consistent data area.

On the other hand, if the size of the data block exceeds the consistent data area, the integrity of the entire data block may not be maintained during transmission.

Therefore, even for a data block that you originally want to handle as a single unit, if its size is larger than the consistent data area, a state may occur where part of it contains new data and another part contains old data.

Data inconsistency can occur, for example, when execution of communication processing is interrupted by a higher-priority hardware interrupt OB. At this time, if the data that the communication instruction was already partially processing is modified by the user program within the interrupt OB, the transferred data may contain a mixture of information from the following two points in time:

  • Data before the hardware interrupt was processed
  • Data after the hardware interrupt was processed

In other words, because the transferred data no longer represents content from the same point in time, this data enters an inconsistent (inconsistent / not coherent) state.

Methods to Ensure Consistency

If communication processing might be interrupted by an interrupt OB, you need to ensure that data is transferred in a consistent state. To achieve this, instead of directly modifying the transfer target data from the interrupt OB, modify the copy (image) side of the data. Then, before performing the next data transfer, copy that data image to the transfer area of the communication instruction.

When communication instructions within the user program access a shared data area, access to that data area can be coordinated using parameters such as DONE. This enables user programs to ensure data consistency for communication areas transferred from the local side via communication instructions.

In the Case of PUT/GET

On the other hand, when using S7 communication instructions PUT/GET, you need to consider the size of the consistent data area at the program creation and configuration stages.

This is because there is no communication block in the user program of the target communication device (server) to synchronize communication data with user program processing.

In the Case of S7-300 / C7-300

In S7-300 and C7-300, except for CPU 318-2 DP, communication data is copied to user memory in a consistent state in 32-byte units at OS cycle control points.

On the other hand, for data areas exceeding 32 bytes, data consistency is not guaranteed.

Therefore, if you need to explicitly ensure data consistency, communication data handled in the user program must be kept within a range not exceeding 32 bytes.

Note that depending on the version, the maximum supported size may be 8 bytes.

Please note that, depending on the version, the maximum size supported may be 8 bytes.

In the Case of S7-400 / S7-1500

On the other hand, in S7-400 and S7-1500, communication data is handled in 462-byte units. Unlike S7-300, these communication data items are not processed at cycle control points, but are processed within fixed time windows (time slices) provided during the program cycle.

Tag consistency is guaranteed by the system. Therefore, these communication areas can be accessed in a consistent state even when using “PUT”/”GET” instructions, or when reading/writing tags from OP or OS, etc.

Impact on Interrupt Response Time

Performing data copy processing slightly increases the CPU’s interrupt response time.

In addition, as the amount of data that needs to be transferred in a fully consistent state increases, the system’s interrupt response time becomes longer.

In short, because there is a tradeoff between the data volume guaranteed for consistency and the interrupt response time, care must be taken regarding the volume of data handled.

DPWR_DAT

Using the DPWR_DAT instruction allows you to transfer data specified by the RECORD parameter in a consistent state to a central configuration module, or a specified module of a DP standard slave/PROFINET IO device.

If necessary, data is also transferred to the process image. This applies when the address range of the target DP standard slave is configured as a consistency range within the process image.

“DPWR_DAT” is required because standard transfer instructions accessing I/O or process image outputs can only write up to 4 contiguous bytes at a time.

If supported by the CPU, consistent data can also be written via process image outputs. Check the relevant documentation to see if the CPU you are using supports this feature.

However, when writing consistent data, avoid using both methods simultaneously.

Use either “DPWR_DAT” or write via the process image output table, but not both.

Note

When using “DPWR_DAT”, avoid accessing I/O areas belonging to process image partitions assigned to OB6x (isochronous mode interrupt).

LADDR Parameter

The LADDR parameter specifies the target DP standard slave / PROFINET IO device. If an error occurs when accessing the specified module, error code 8090 is output.

RECORD Parameter

The RECORD parameter specifies the source area of the data to be written. The source area must be equal to or longer than the output data length of the selected module. Only the portion corresponding to the output data is actually transferred, and any remaining bytes are ignored.

If the source area specified in RECORD is larger than the configured module output size, only data up to the maximum output size will be transferred.

On the other hand, if the source area is smaller than the module output size, error code 80B1 is output.

Supported Data Types

The supported data types are as follows. These data types can also be used within ARRAY or STRUCT data structures. On the other hand, STRING and WSTRING types are not supported.

PLC data types (UDT) and system data types are also supported. Data transfer is executed synchronously. Therefore, write processing is complete when execution of the instruction finishes.

  • BOOL
  • BYTE
  • CHAR
  • WCHAR
  • WORD
  • LWORD
  • DWORD
  • INT
  • UINT
  • USINT
  • SINT
  • LINT
  • ULINT
  • DINT
  • UDINT
  • REAL
  • LREAL

Parameters

Parameter

Declaration

Data Type

Description

LADDR

Input

HW_IO

Specifies the hardware ID of the target module to write data to. Hardware identifiers can be checked in system constants.

RECORD

Input

VARIANT

Specifies the source area for user data to be written.

RET_VAL

Return

INT

If an error occurs during execution of the instruction, an error code is stored in this return value.

Error Codes

The execution result of DPWR_DAT is returned in RET_VAL. 0000 is stored upon normal completion, and the corresponding error code is stored if an error occurs.

Error Code

Description

0000

No error occurred.

8090

No module is configured corresponding to the specified hardware ID, restrictions regarding consistent data length are not met, or no hardware ID is specified in LADDR.

8092

An unsupported data type is specified in the RECORD parameter.

8093

There is no DP module / PROFINET IO device that can write consistent data at the hardware ID specified in LADDR. This error also occurs if the specified DP standard slave / PROFINET IO device has no outputs.

80A1

An access error was detected while accessing the I/O device.

80B1

The source area specified in RECORD is shorter than the configured output size of the DP standard slave / PROFINET IO device.

80C1

Data from the previous write job has not yet been processed by the DP standard slave / PROFINET IO device.

DPRD_DAT

Using the DPRD_DAT instruction allows you to read consistent data from an I/O module.

This instruction can be used not only for modules in central configurations, but also for DP standard slaves and PROFINET IO devices.

DPRD_DAT is required because standard load instructions accessing I/O or process image input tables can only read up to 4 contiguous bytes at a time.

If supported by the CPU, consistent data can also be read via process image inputs if necessary.

LADDR Parameter

The LADDR parameter specifies the target DP standard slave / PROFINET IO device. If an error occurs when accessing the specified module, error code 8090 is output.

RECORD Parameter

The RECORD parameter specifies the source area of the data to be written. The source area must be equal to or longer than the output data length of the selected module. Only the portion corresponding to the output data is actually transferred, and any remaining bytes are ignored.

If the source area specified in RECORD is larger than the configured module output size, only data up to the maximum output size will be transferred.

On the other hand, if the source area is smaller than the module output size, error code 80B1 is output.

Supported Data Types

The supported data types are as follows. These data types can also be used within ARRAY or STRUCT data structures. On the other hand, STRING and WSTRING types are not supported.

PLC data types (UDT) and system data types are also supported. Data transfer is executed synchronously. Therefore, write processing is complete when execution of the instruction finishes.

  • BOOL
  • BYTE
  • CHAR
  • WCHAR
  • WORD
  • LWORD
  • DWORD
  • INT
  • UINT
  • USINT
  • SINT
  • LINT
  • ULINT
  • DINT
  • UDINT
  • REAL
  • LREAL

Parameters

Parameter

Declaration

Data Type

Description

LADDR

Input

HW_IO

Specifies the hardware ID of the target module to read data from. Hardware identifiers can be checked in system constants.

RET_VAL

Return

INT

If an error occurs during execution of the instruction, an error code is stored in this return value.

RECORD

Output

VARIANT

Specifies the destination area to store the read user data.

Error Codes

Error Code

Description

0000

No error occurred.

8090

No module is configured corresponding to the specified hardware ID, restrictions regarding consistent data length are not met, or no hardware ID is specified in LADDR.

8092

An unsupported data type is specified in the RECORD parameter.

8093

There is no DP module / PROFINET IO device that can read consistent data at the hardware ID specified in LADDR. This also occurs if the specified module has no inputs.

80A0

An access error was detected while accessing I/O.

80B1

The destination area length specified in RECORD is shorter than the configured user data length.

80C0

Data reading has not completed yet.

Implementation

This time, configuration is required on both S71516F-3 and S71200-G2.

Create 2 New Devices

First, create a TIA project and add two CPUs into it. In this example, they are S71516F-3 and S71214FC.

Configure IP address

Next, switch to Network View and configure the IP address for each CPU.

Click the button shown in the figure below.

Match the device IP addresses to your application.

S71200 Side

Configure the S71200-G2 side.

Enable the IO device functionality.

In this article, we connect S71516F-3 with S71200-G2, so let’s configure the PROFINET interface of S71500.

Done!

Transfer area

Next, click Operation Mode > I-device communication, and set up the communication transfer area between S71516F-3 and S71200-G2.

Program

Next, create the program.

udt_test

Here, we create a 100-Byte structure.

db

Define variables in the data block using the structure created earlier.

fbTest

Now, create a program for testing.

Network 1

Here, write the head and tail of the data to be transmitted from S71200 → S71500 into Connection 1 and Connection 2.

Network 3

Use the DPWR_DAT function to write data from S71200 → S71500 via Profinet.

Network 5

Use the DPRD_DAT function to receive data from S71500 → S71200 via Profinet.

OB1

Finally, call the FB created earlier.

Download

Finally, download the project to the PLC.

S71500 Side

Configure the S71516F-3 side.

Profinet Connection Settings

Program

Next, create the program.

udt_test

Here, we create a 100-Byte structure.

Tags

This is the declaration of Tags. On the S71500 side, create a program that directly accesses IO.

db

Define variables in the data block using the structure created earlier.

fbTest

Now, create a program for testing.

Network 2

Transfer input data to DB variables via Profinet.

Network 4

Reply to S71200 with the received data plus and minus 1.

Network 6

Transfer DB variables to output and transmit to S71200 via Profinet.

OB1

Finally, call the FB created earlier.

Download

Finally, download the project to the PLC.

Results

We were able to confirm PNIO Packets from Wireshark.

There are also no errors in the DPRD_DAT function.

On the S71500 side, data sent from S71200 was also confirmed.

シェアする

  • このエントリーをはてなブックマークに追加

フォローする