Cookies are important for this site to function properly, to guarantee your safety, and to provide you with the best experience. By clicking OK, you accept all cookies. For more information, please access our Privacy Policy.
Table of Contents
Tutorials / 
How to Read and Write RFID Tags in Siemens TIA Portal
Intermediate

How to Read and Write RFID Tags in Siemens TIA Portal

Siemens
TIA Portal
EtherNet/IP
Simulation

Introduction

Working with RFID in an industrial setting can feel intimidating the first time you open TIA Portal and stare at an empty project. This tutorial walks you through the entire process, from configuring the RF188C communication module and the PROFINET network to integrating the LIDENT library and wiring up Auto and Manual function blocks. You'll learn how automatic and user-controlled command execution differ, how to parameterize readers and transponders, and how to read and write tag data with confidence. By the end, you'll have a working, tested application and a much clearer picture of how PROFINET-based identification systems operate.

Application Example Overview

A dedicated library named 'LIDENT' supplies function blocks that let you control compatible industrial identification modules over cyclic PROFINET I/O communication. There are two operating modes available within the cyclic PROFINET I/O protocol. First is the automatic command execution. This operating mode runs the control automatically, so there's no need to start it manually from the user program. The second operating mode is user-controlled command execution. Here, you can use the user program to key the desired command to trigger it manually.

Figure 1.1: RFID Read/Write in Siemens TIA Portal - Application Overview
Figure 1.1: RFID Read/Write in Siemens TIA Portal - Application Overview

General Hardware Configuration

Once TIA Portal is open, create a new project and select the 1516-3 PN/DP as your CPU.

Figure 2.1: RFID Read/Write in Siemens TIA Portal - CPU selection
Figure 2.1: RFID Read/Write in Siemens TIA Portal - CPU selection

Double-click Devices & Networks afterward to bring up its window, then switch to Network View. Cyclic PROFINET communication runs through the 'RF188C cycle version 2.2' object, which you can insert into the hardware configuration by double-clicking it. Draw a network connection between your PLC and the communication module to establish the link between the CPU 1516-3 PN/DP and RF188C. Configure the communication module's IP address and PROFINET name to allow proper communication between the devices.

Figure 2.2: RFID Read/Write in Siemens TIA Portal - Connecting PLC to RF188C
Figure 2.2: RFID Read/Write in Siemens TIA Portal - Connecting PLC to RF188C

Double-click the RF188C object to open the Device View for the communication module. From the Hardware Catalog, pick the reader object you plan to configure and assign it to the communication module's corresponding port. Two options exist here, depending on the data length required for cyclic I/O communication. First is the '128 Bytes Cycle' reader, suited for applications handling larger data volumes for each cycle. Second is the '32 Bytes Cycle' reader, useful for applications needing less data or aiming to lighten bus load. In this application example, configure the 128-byte reader variant across slots X21 and X22.

Figure 2.3: RFID Read/Write in Siemens TIA Portal - Assigning readers to slots X21 & X22
Figure 2.3: RFID Read/Write in Siemens TIA Portal - Assigning readers to slots X21 & X22

Function Blocks Integration

Go to the right-hand Libraries tab in TIA Portal. Then, under the Global Libraries section, open the LIDENT library you grabbed from this link.

Figure 3.1: RFID Read/Write in Siemens TIA Portal - Opening the LIDENT global library
Figure 3.1: RFID Read/Write in Siemens TIA Portal - Opening the LIDENT global library

From the library opened in the lower pane, drag its Types folder over and drop it onto the Project Library's Types folder. Using the LIDENT_PNCycCmdAuto block, the command's result comes back on every cycle, but issuing the command in the first place is only possible via hardware configuration. The LIDENT_PNCycCmdManual block lets you manually set a command right in the user program. Even though the block's input parameters handle this command, you'll still need to adjust the reader's hardware configuration.

Figure 3.2: RFID Read/Write in Siemens TIA Portal - Copying LIDENT types to project library
Figure 3.2: RFID Read/Write in Siemens TIA Portal - Copying LIDENT types to project library

Special Hardware Configuration

Choose the configured reader to set up its transponder settings first. From there, decide which transponder type your reader should talk to. In this example, 'Reader_1_128B' is used and paired with the LIDENT_PNCycCmdAuto function block. Since you'll be reading a tag's UID going forward, the settings were parameterized accordingly, as shown.

Figure 4.1: RFID Read/Write in Siemens TIA Portal - Setting the transponder configuration
Figure 4.1: RFID Read/Write in Siemens TIA Portal - Setting the transponder configuration

If LIDENT_PNCycCmdManual block is what you're after, make sure automatic command execution is disabled. Here, 'Reader_2_128B' serves this exact purpose.

Figure 4.2: RFID Read/Write in Siemens TIA Portal - Selecting the manual reader variant
Figure 4.2: RFID Read/Write in Siemens TIA Portal - Selecting the manual reader variant

Function Block Calling

From the Project Library, pick the block that matches the reader you just configured in the hardware configuration, then drag it into the Program Blocks folder. Open the Organizational Block meant to process the program by double-clicking it; here, it's OB1.

Figure 5.1: RFID Read/Write in Siemens TIA Portal - Dragging the library block to program blocks
Figure 5.1: RFID Read/Write in Siemens TIA Portal - Dragging the library block to program blocks

Drag the function blocks from the Program Blocks folder into networks in OB1 to create their instances.

Figure 5.2: RFID Read/Write in Siemens TIA Portal - Instantiating function blocks in OB1
Figure 5.2: RFID Read/Write in Siemens TIA Portal - Instantiating function blocks in OB1

Data Blocks Creation

The device parameters go into the data module, IdentControlling, while send/receive buffers go into IdentData. You need to build two data blocks individually. For the first data block, double-click Add New Block under the Program Blocks folder. When the dialog opens, select the Data Block tab on the left and type in the first module's name.

Figure 6.1: RFID Read/Write in Siemens TIA Portal - Creating the IdentControlling data block
Figure 6.1: RFID Read/Write in Siemens TIA Portal - Creating the IdentControlling data block

Do the same for creating the second data block.

Figure 6.2: RFID Read/Write in Siemens TIA Portal - Creating the IdentData data block
Figure 6.2: RFID Read/Write in Siemens TIA Portal - Creating the IdentData data block

Add two Struct variables to the IdentControlling block, labeling them IdentCycCmdAuto and IdentCycCmdManual. Next, set up all the input and output variables with the right data types.

Figure 6.3: RFID Read/Write in Siemens TIA Portal - Adding struct variables to IdentControlling
Figure 6.3: RFID Read/Write in Siemens TIA Portal - Adding struct variables to IdentControlling

The data module IdentData serves as the buffer, either input or output. It starts with creating two Struct variables.

Figure 6.4: RFID Read/Write in Siemens TIA Portal - Creating struct variables in IdentData
Figure 6.4: RFID Read/Write in Siemens TIA Portal - Creating struct variables in IdentData

Data Blocks Interconnection with Function Blocks

Double-click on the communication module within Devices & Networks to switch to Device View. Select 'Reader_1_128B' since it'll interconnect with the Auto function block. Switch to System Constants within the Settings tab and record the hardware identifier there.

Figure 7.1: RFID Read/Write in Siemens TIA Portal - Recording the reader 1 hardware ID
Figure 7.1: RFID Read/Write in Siemens TIA Portal - Recording the reader 1 hardware ID

Head to OB1 and, at the Auto FB's 'hwId' input in Network 1, enter the hardware ID you determined in the previous step.

Figure 7.2: RFID Read/Write in Siemens TIA Portal - Entering the hardware ID at the auto FB
Figure 7.2: RFID Read/Write in Siemens TIA Portal - Entering the hardware ID at the auto FB

Next, redo these steps for 'Reader_2_128B', getting its hardware ID from the communication module so it can be linked to the Manual FB's 'hwId' input within Network 2 of OB1.

Figure 7.3: RFID Read/Write in Siemens TIA Portal - Recording the reader 2 hardware ID
Figure 7.3: RFID Read/Write in Siemens TIA Portal - Recording the reader 2 hardware ID
Figure 7.4: RFID Read/Write in Siemens TIA Portal - Entering the hardware ID in the manual FB 
Figure 7.4: RFID Read/Write in Siemens TIA Portal - Entering the hardware ID in the manual FB 

For the remaining variables, you could connect them to the appropriate inputs or outputs through direct text entry for both networks.

Figure 7.5: RFID Read/Write in Siemens TIA Portal - Assigning I/O variables to auto FB
Figure 7.5: RFID Read/Write in Siemens TIA Portal - Assigning I/O variables to auto FB
Figure 7.6: RFID Read/Write in Siemens TIA Portal - Assigning I/O variables to manual FB
Figure 7.6: RFID Read/Write in Siemens TIA Portal - Assigning I/O variables to manual FB

Auto Function Block Operation

Compile the program, download it to the PLC, then open the online view in OB1. Using the Auto FB, the transponder's UID gets read automatically as soon as the reader detects it. The parameters listed below then appear after a successful run.

Figure 8.1: RFID Read/Write in Siemens TIA Portal - Verifying automatic UID reading
Figure 8.1: RFID Read/Write in Siemens TIA Portal - Verifying automatic UID reading

Evaluating the received UID from the telegram happens through 'IdentData's online view, since its array is linked to the 'dataRx' input.

Figure 8.2: RFID Read/Write in Siemens TIA Portal - Evaluating the received UID in IdenData
Figure 8.2: RFID Read/Write in Siemens TIA Portal - Evaluating the received UID in IdenData

Manual Function Block Operation – Read UID Command

Reading the UID through the Manual FB means changing the parameters in 'IdentCycCmdManual', located inside the 'IdentControlling' data block, to match the displayed values.

Figure 9.1: RFID Read/Write in Siemens TIA Portal - Manual FB parameter assignment for tag reading
Figure 9.1: RFID Read/Write in Siemens TIA Portal - Manual FB parameter assignment for tag reading

Compile the program and send it to your controller. In TIA Portal, switch to online view to check the parameterized block's current values. If online transfer of the values didn't happen, choose the 'Load starting values as current values' option and verify the note that pops up with OK.

Figure 9.2: RFID Read/Write in Siemens TIA Portal - Loading starting values
Figure 9.2: RFID Read/Write in Siemens TIA Portal - Loading starting values

Toggling 'Execute' from FALSE to TRUE is what triggers and runs the command.

Figure 9.3: RFID Read/Write in Siemens TIA Portal - Activating the manual command trigger
Figure 9.3: RFID Read/Write in Siemens TIA Portal - Activating the manual command trigger

The device's outputs let you check the function block's execution. How? Once a tag is detected, outputs should show the following values.

Figure 9.4: RFID Read/Write in Siemens TIA Portal - Verifying output status after tag detection
Figure 9.4: RFID Read/Write in Siemens TIA Portal - Verifying output status after tag detection

Now check the variable tied to 'dataRx'; its current value shows the UID stored from the transponder that was read.

Figure 9.5: RFID Read/Write in Siemens TIA Portal - Checking the stored transponder UID via dataRx
Figure 9.5: RFID Read/Write in Siemens TIA Portal - Checking the stored transponder UID via dataRx

Manual Function Block Operation – General Read Command

Configuring the parameters of 'IdentCycCmdManual' found in the table below is necessary to read transponder data.

Figure 10.1: RFID Read/Write in Siemens TIA Portal - Required parameter fields for manual RFID reading
Figure 10.1: RFID Read/Write in Siemens TIA Portal - Required parameter fields for manual RFID reading

Compile the program, then transfer it to your controller. Use TIA Portal's online view to check what current values the parameterized function block is showing. Flip the 'Execute' input from FALSE to TRUE to run the command. Checking whether the function block executed correctly means watching the device's outputs.

Figure 10.2: RFID Read/Write in Siemens TIA Portal - Verifying manual FB execution via I/O status
Figure 10.2: RFID Read/Write in Siemens TIA Portal - Verifying manual FB execution via I/O status

Next, check the variable you've linked to the 'dataTx' input. Displayed here are the stored values from the transponder's user memory, spanning address 0 to 31.

Figure 10.3: RFID Read/Write in Siemens TIA Portal - Verifying user memory values in dataTx
Figure 10.3: RFID Read/Write in Siemens TIA Portal - Verifying user memory values in dataTx

Manual Function Block Operation – Write Command

Setting up a Write command means parameterizing the function block's inputs using the configuration shown.

Figure 11.1: RFID Read/Write in Siemens TIA Portal - Configuring FB inputs for an RFID write command
Figure 11.1: RFID Read/Write in Siemens TIA Portal - Configuring FB inputs for an RFID write command

Open the 'dataSend' variable, part of the 'IdentCycCmdManual' struct in the 'IdentData' data module, and set it up individually based on the data you want written.

Figure 11.2: RFID Read/Write in Siemens TIA Portal - Preparing the write data payload
Figure 11.2: RFID Read/Write in Siemens TIA Portal - Preparing the write data payload

After loading the compiled program onto your controller, go to the online view of 'IdentControlling' to view the function block's current values.

Figure 11.3: RFID Read/Write in Siemens TIA Portal - Monitoring FB current values
Figure 11.3: RFID Read/Write in Siemens TIA Portal - Monitoring FB current values

Apply the same step to the IdentData module, reviewing and tweaking 'dataSend' within 'IdentCycCmdManual' until the online and offline values match up.

Figure 11.4: RFID Read/Write in Siemens TIA Portal - Synchronizing online and offline values
Figure 11.4: RFID Read/Write in Siemens TIA Portal - Synchronizing online and offline values

Back in 'IdentControlling's online view, the command runs once you switch the 'Execute' input from FALSE to TRUE. You can confirm the function block executed by viewing the device's outputs. The outputs should show these values once a tag is picked up.

Figure 11.5: RFID Read/Write in Siemens TIA Portal - Confirming write operation success
Figure 11.5: RFID Read/Write in Siemens TIA Portal - Confirming write operation success

Conclusion

In conclusion, you have learned how to set up cyclic PROFINET I/O communication using the LIDENT library, starting with configuring the CPU, communication module, and readers inside TIA Portal's hardware configuration. You've seen how to integrate function blocks, create IdentControlling and IdentData data blocks, and connect hardware IDs to the Auto and Manual function blocks in OB1. You now understand the difference between automatic and user-controlled command execution, how to read a transponder's UID, retrieve stored user memory data, and write new data to a tag. With these skills, you're ready to build and troubleshoot your own PROFINET-based identification applications.