Create driver extension - COPA-DATA/DriverExtensions GitHub Wiki
Driver Extensions are .NET Standard or .NET Core libraries (*.dll) that must be located within the zenon installation. Refer to the zenon help for the matching version. If additional dependencies are used, they must be located in the same directory. You can use a development environment of your choice, in this document Visual Studio 2022 was used.
With Visual Studio according project templates are available out of the box.
All needed types to create a driver extension are located in the assembly CopaData.Drivers.Contracts.dll. The following paths refer to the zenon 12 installation but must be adjusted according to your version.
C:\Program Files (x86)\COPA-DATA\zenon Software Platform 12\Engineering\DriverFramework\CopaData.Drivers.Contracts.dll
Hint: Use $(registry:HKEY_LOCAL_MACHINE\SOFTWARE\COPA-DATA\DataDir@ProgramDir32_12000)DriverFramework\CopaData.Drivers.Contracts.dll in the Visual Studio project file to target your installation directory independent of your installation.
See sample here
A driver extension class is a public .NET class, that implements interface CopaData.Drivers.Contracts.IDriverExtension. The next listing shows an implementation of the class in a very basic way. The interface is designed to work in a asynchronous way.
using CopaData.Drivers.Contracts;
public class DriverExtension : IDriverExtension
{
private ILogger _logger;
private IValueCallback _valueCallback;
public Task InitializeAsync(ILogger logger, IValueCallback valueCallback, string configFilePath)
{
_logger = logger;
_valueCallback = valueCallback;
return Task.CompletedTask;
}
public Task ShutdownAsync()
{
return Task.CompletedTask;
}
public Task<bool> SubscribeAsync(string symbolicAddress)
{
return Task.FromResult(true);
}
public Task UnsubscribeAsync(string symbolicAddress)
{
return Task.CompletedTask;
}
public Task ReadAllAsync()
{
return Task.CompletedTask;
}
public Task<bool> WriteStringAsync(string symbolicAddress, string value, DateTime dateTime, StatusBits status)
{
return Task.FromResult(true);
}
public Task<bool> WriteNumericAsync(string symbolicAddress, double value, DateTime dateTime, StatusBits status)
{
return Task.FromResult(true);
}
}- InitializeAsync: The driver is initialized (e. g. on Runtime start)
- ShutdownAsync: The driver is shutting down (e. g. on Runtime exit)
- SubscribeAsync: This method is called by zenon, when a variable (by using the symbolic address) is requested (variable is adviced by showing on a screen, using in archives, etc.)
- UnsubscribeAsync: This method is called by zenon, when a variable (by using the symbolic address) is not needed any more (e. g. a screen switch to another screen or stopping an archive)
- WriteStringAsync: This method is called by zenon, when the string value of a variable is set.
- WriteNumericAsync: This method is called by zenon, when the numeric/boolean value of a variable is set.
Driver Extensions must be located in a sub directory of C:\Program Files (x86)\COPA-DATA\zenon Software Platform 12\Engineering\DriverExtensions folder, for example C:\Program Files (x86)\COPA-DATA\zenon Software Platform 12\Engineering\DriverExtensions\MyDriverExtension.
The folder must contain the Driver Extension assembly (the project previously created) and all dependencies.
Ensure that you have write access rights to folder C:\Program Files (x86)\COPA-DATA\zenon Software Platform 12\Engineering\DriverExtensions (e. g. by starting Visual Studio in Admin-Mode.
In project properties, add a Post-Build event, here a sample:
if not exist "$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\COPA-DATA\DataDir@ProgramDir32_12000)DriverExtensions\BasicSample" mkdir "$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\COPA-DATA\DataDir@ProgramDir32_12000)DriverExtensions\BasicSample"
copy /y "$(TargetDir)\*.*" "$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\COPA-DATA\DataDir@ProgramDir32_12000)DriverExtensions\BasicSample"By default, the build process does not copy all dependencies of .NET Standard or .NET Core libraries to the output directory. To ensure that all dependencies are copied, add the following XML tag to the driver extension project:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>See sample here