PID Data Reader
This section describes the PidDataReader. Module can be used in any application hosted in the ProconTEL 4 environment which is using components pipeline builder. The PID Data Reader allows the application to read information from the PID block and produce data for the pipeline.
The extension method AddS7PidDataReader allows a user to create a reader that reads PID data from S7-1200 and S7-1500 PLCs families. However, it is required to add the MxPidCommunication function block to the PLC program. For details read the instruction: How to prepare the PLC
Definition
Namespace: ProconTel.Components.Communication.PidCommunication
Assembly: ProconTel.Components.Communication.PidCommunication.dll
Module Instalation
To install a PidDataReader module into project, Nuget Package Manager Console can be used:
Install-Package ProconTel.Components.Communication.PidCommunication -ProjectName <ProjectName>
Nuget package can be found in the repository: https://nexus.macrix.eu/repository/pct2022/
Available Pipeline extensions and configuration methods
The module provides two extensions method that allows to inject PidDataReader module support to application.
public static PidConnectionSyntax AddS7PidDataReader(
this PipelineBootstrapper bootstrapper,
string plcIpAddress,
int communicationDataBlockNumber,
TimeSpan delayOfCyclicDataRead,
TimeSpan delayOfResetWriteFlag)
public static PidConnectionSyntax AddS7PidDataReader(
this PipelineBootstrapper bootstrapper,
Action<S7ConnectionSettings> configuration)
S7ConnectionSettings contains a number of parameters that can be passed when needed. Note that PlcIpAddress doesn't include the default value. Therefore this value has to be set by the user. The table below describes all available parameters and default values:
| ParameterName | Default | Description |
|---|---|---|
| PlcIpAddress | null | The IP address of the PLC device. |
| CommunicationDataBlockNumber | 2000 | The number of the communication data block in TIA Portal. Check the details below. |
| DelayOfCyclicDataRead | 100 [ms] | The delay for the cyclic read. |
| DelayOfResetWriteFlag | 100 [ms] | The delay time after each write data execution. |
| AutomaticReconnectEnabled | true | Enabling auto reconnect mechanism. |
| Cpu | S71500 | The Siemens CPU type. |
| Rack | 0 | The PLC rack number. |
| Slot | 1 | The PLC slot number. |
| InputsStartByteAdr | 0 | Start byte address in the communication data block for input values. |
| OutputsStartByteAdr | 32 | Start byte address in the communication data block for outputs values. |
Example of usage
This example shows the usage of the PidDataReader module. The module opens a connection to the PID block and reads values. After the successful read, the module sends data to the pipeline and refreshes its own app feed.
First, register the PID data reader in the Program.cs class.
await ProconTelApp.StartAsync(args, (services, configuration) => services.AddPipeline(pipeline =>
{
var config = new S7ConnectionSettings();
configuration.Bind("S7PidConfig", config);
services.AddPipeline(pipeline =>
{
pipeline.SetId("pid_to_messagebus");
pipeline.AddS7PidDataReader(config.PlcIpAddress!,
config.CommunicationDataBlockNumber,
config.DelayOfCyclicDataRead,
config.DelayOfResetWriteFlag);
pipeline.AddConsumer<PidData, MessageBusConsumer>();
});
}));
Add the most important connection parameters to appsettings.
"S7PidConfig": {
"PlcIpAddress": "127.0.0.1",
"CommunicationDataBlockNumber": "2000"
}
Note that PlcIpAddress and CommunicationDataBlockNumber must match the actual values set in your PLC. For details read the instruction: How to prepare the PLC
Add a consumer implementation that will receive and process data from the PidDataReader.
internal sealed class MessageBusConsumer : IConsumer<PidData>
{
private readonly ILogger<MessageBusConsumer> _logger;
private readonly IMessageBus _messageBus;
private readonly IAppFeedBus _appFeedBus;
public MessageBusConsumer(ILogger<MessageBusConsumer> logger, IMessageBus messageBus, IAppFeedBus appFeedBus)
{
_logger = logger;
_messageBus = messageBus;
_appFeedBus = appFeedBus;
}
public async Task ConsumeAsync(PidData payload)
{
_logger.LogDebug("PidData received.");
await _appFeedBus.SendAsync(payload);
await _messageBus.PublishAsync(payload);
}
}
The complete example can be found in the following link: Example of the PID data reader
Data exchange diagram
