Using RSC Services
Previously you learned that some PLCnext runtime features provide an application programming interface (API) in the form of Remote Service Calls, or RSC Services.
In this section, our ACF component will call C++ API on the Device Info RSC service. The Device Info service provides access to Device Information. You can use a similar technique to access any RSC service in the PLCnext Runtime.
Here are the steps to use the C++ API on the Device Info RSC service:
-
Add the relevant header file to the .hpp file of the component:
#include "Arp/Device/Interface/Services/IDeviceInfoService.hpp"
-
Declare a pointer to the Device Info service:
IDeviceInfoService::Ptr deviceInfoServicePtr = nullptr;
-
In the component .cpp file, add the header for the RSC Service Manager:
#include "Arp/System/Rsc/ServiceManager.hpp"
-
In the
SubscribeServices
method of the ACF component, get a pointer to the Device Info service:this->deviceInfoServicePtr = ServiceManager::GetService<IDeviceInfoService>();
-
In the
SetupConfig
method of the ACF component, use the Device Info service to read the device serial number, and log the value to theOutput.log
file:RscVariant<512> serialNumber = this->deviceInfoServicePtr->GetItem("General.SerialNumber"); if (serialNumber.GetType() == RscType::String) { this->log.Info("Serial number of this device: {0}%", serialNumber.GetChars()); } else this->log.Info("Error reading device serial number");
-
The above code is included in these source files:
You can use these files to update the project you created in the previous section.
-
Rebuild the project.
-
Copy the resulting library file to the target.
-
Restart the PLCnext runtime:
# sudo /etc/init.d/plcnext restart && tail -f -n 0 /opt/plcnext/logs/Output.log
Among the messages that appear in the Output.log
file, you should see an INFO message from your component containing the serial number of your device.