Practical use case: RFID sensor (PoC)
- Ivaylo Fiziev
- 8 hours ago
- 3 min read

From the theory: Radio Frequency Identification (RFID) is a wireless technology that uses radio waves to automatically identify and track objects or people. It consists of an RFID tag containing a microchip and antenna, and an RFID reader with antennas that emit radio waves to trigger the tag and receive its data. The tag, which can be passive (battery-free) or active (battery-powered), transmits its unique information wirelessly to the reader without needing a direct line of sight.
In Process Simulate we had a lot of confusion about how exactly to simulate this type of sensor over the years. Now SCL a good enabler for it. You can easily express yourself in the code. You have strings and arrays that can be used as tags. Material Flow based on SCL was a step in the right direction as well. Being able to create part appearances in the code means that we can also assign unique tags to them at the point of creation. Then we can read the tags from another script that acts like a sensor. The sensor can recognize the tags and provide some output. Then the output can be used in simulation. Wow. Its that simple!
Let's take an actual example. A conveyor delivering parts and a RFID sensor reading their tags. The tag data is then displayed on a display. Here is how it looks:

To achieve the desired behavior we only need a number of SCL scripts. Basically one per component. One for the part source, one for the RFID sensor, one for the conveyor and one per display. We also need one for keeping all the displays in sync.
Lets take a look at the part source first. It creates a part appearance and assigns a unique tag to it. The tag is a string. You can put anything there. In this case we are putting a unique number identifying the part.
FUNCTION_BLOCK "MAIN"
VERSION:1.0
VAR_INPUT
part : TX_OBJECT; // The origin part
clk : BOOL; // The clock signal
END_VAR
VAR
trigger : R_TRIG; // Positive edge trigger
id : UDINT := 100; // unique ID of the part
END_VAR
BEGIN
#trigger(CLK:=#clk);
if #trigger.Q then
CREATE_PART_APPEARANCE(PART:=#part.NAME, TAG:=UDINT_TO_STRING(#id)); // TAG = ID as string
#id := #id + 1; // increment the ID
end_if;
END_FUNCTION_BLOCK
Next comes the sensor. It constantly looks for part appearances that have tags. Once a tag is detected it converts it back to a number and provides it as an output.
FUNCTION_BLOCK "MAIN"
VERSION:1.0
VAR_OUTPUT
id : DINT;
END_VAR
VAR_TEMP
tag : STRING;
END_VAR
BEGIN
#tag := DETECT_PART_APPEARANCE(RANGE:=100); // detect TAGs in range
if LEN(#tag) > 0 then // TAG detected ?
#id := STRING_TO_UDINT(#tag); // convert back to a number
else
#id := 0; // no TAG detected
end_if;
END_FUNCTION_BLOCK
By default detection works based on the self frames of the parts and the sensor. This however can be considered a downside. You can override the self frame of the sensor by using the 'LOC' argument of the function. Maybe it is a good idea to be able to override the self frame of the part with its geometric center?
Detection is omni-directional (like a sphere). To make it directional we need to limit the field of view of the sensor similarly to how we did it for the distance sensor (Practical use case: Distance sensor (PoC)). To do so we need the function to return the location of the part appearance and the sensor. This is still TBD.
I welcome any ideas that will make the sensor more useful.
Practical use case: Driving a seven segment display already showcased the display scripts so I won't put them here. What's left is the script of the conveyor. It simply moves the conveyor:
FUNCTION_BLOCK "MAIN"
VERSION:1.0
BEGIN
DRIVE_CONVEYOR(POS:=CONVEYOR_POSITION() + 0.5); // move the conveyor
END_FUNCTION_BLOCK
Practical use case: Applying a motion profile to a conveyor shows you how to make the conveyor accelerate/decelerate more or less realistically.
That's it. Copy/paste the scripts, wire the signals and it starts working. Simple, isn't it?
You can apply your own scheme for generating TAGs. The recently introduced string functions will help you work with them. Expect the PoC to be available in version 2512. Make sure to enable the SCL_RFID_SENSOR feature toggle so the scripts work!
Happy coding!
Comments