Driver Development

Advantages of Rapid SCADA as a platform for driver creation:

  • Communicator is responsible for the connection (Serial, TCP, UDP). The developer implements encoding and decoding of data packets.
  • A driver can collect current, historical data and events, and send commands.
  • The built-in OPC UA server provides data received from the developed driver to third-party OPC clients.
  • A ready-made logging system.
  • Unified user interface for configuration.

Next, let's look at the development of the logical part and user interface of a simple driver, which will be named DrvAbc. To develop a complex driver that implements an industrial protocol, learn and use the source code of existing drivers on GitHub as examples (link 1, link 2).

Logic Implementation

Create a new project based on the Class Library template. Enter the project name DrvAbc.Logic, and select the .NET 8.0 framework.

Add dependencies to the ScadaCommon.dll, ScadaCommon.Log.dll and ScadaCommCommon.dll libraries. Binary files of the libraries can be found in the Rapid SCADA installation directory, or compiled from source code.

Double click a project node in Solution Explorer to open the project file DrvAbc.Logic.csproj and edit its properties as shown below.

<PropertyGroup>
  <TargetFramework>net8.0</TargetFramework>
  <ImplicitUsings>enable</ImplicitUsings>
  <Nullable>disable</Nullable>
  <RootNamespace>Scada.Comm.Drivers.DrvAbc.Logic</RootNamespace>
</PropertyGroup>

Create a DevAbcLogic class and copy the code below. This class implements the logic for interacting with a device. Note that the namespace and class name must contain the DrvAbc driver code. Explore the source code of the DeviceLogic base class to learn about the capabilities available when implementing device interaction logic.

using Scada.Comm.Config;
using Scada.Comm.Devices;
using Scada.Data.Models;

namespace Scada.Comm.Drivers.DrvAbc.Logic
{
    internal class DevAbcLogic : DeviceLogic
    {
        public DevAbcLogic(ICommContext commContext, ILineContext lineContext, DeviceConfig deviceConfig)
            : base(commContext, lineContext, deviceConfig)
        {
            CanSendCommands = true;
            ConnectionRequired = false;
        }

        public override void Session()
        {
            base.Session();
            Log.WriteLine("DrvAbc driver polling session");
            FinishRequest();
            FinishSession();
        }

        public override void SendCommand(TeleCommand cmd)
        {
            base.SendCommand(cmd);
            Log.WriteLine("Command value = {0}", cmd.CmdVal);
            FinishCommand();
        }
    }
}

Create a DrvAbcLogic class whose code is shown below. This class implements general, non-device specific driver logic. View the source code of the DriverLogic base class to learn about the available features.

using Scada.Comm.Config;
using Scada.Comm.Devices;

namespace Scada.Comm.Drivers.DrvAbc.Logic
{
    public class DrvAbcLogic : DriverLogic
    {
        public DrvAbcLogic(ICommContext commContext)
            : base(commContext)
        {
        }

        public override string Code => "DrvAbc";

        public override DeviceLogic CreateDevice(ILineContext lineContext, DeviceConfig deviceConfig)
        {
            return new DevAbcLogic(CommContext, lineContext, deviceConfig);
        }
    }
}

An example of the logical part of the driver is ready. Build the project and copy DrvAbc.Logic.dll to the Communicator drivers directory ScadaComm\Drv

Interface Implementation

Create a new project based on the Windows Forms Class Library template. Enter the project name DrvAbc.View, and select the .NET 8.0 framework.

Add dependencies to the ScadaCommon.dll, ScadaCommon.Forms.dll, ScadaCommon.Log.dll and ScadaCommCommon.dll libraries.

Double click a project node in Solution Explorer to open the project file DrvAbc.View.csproj and edit its properties as shown below.

<PropertyGroup>
  <TargetFramework>net8.0-windows</TargetFramework>
  <Nullable>disable</Nullable>
  <UseWindowsForms>true</UseWindowsForms>
  <ImplicitUsings>enable</ImplicitUsings>
  <RootNamespace>Scada.Comm.Drivers.DrvAbc.View</RootNamespace>
</PropertyGroup>

Create a DevAbcView class and copy the code below. This class implements the user interface for configuring parameters for interacting with a device. Note that the namespace and class name must contain the DrvAbc driver code. In the example, there is actually no user interface for the driver, however, a minimal implementation of the interface is required so that the driver can be used in the Administrator application. View the source code of the DeviceView base class to learn about the available features.

using Scada.Comm.Config;
using Scada.Comm.Devices;

namespace Scada.Comm.Drivers.DrvAbc.View
{
    internal class DevAbcView : DeviceView
    {
        public DevAbcView(DriverView parentView, LineConfig lineConfig, DeviceConfig deviceConfig)
            : base(parentView, lineConfig, deviceConfig)
        {
        }
    }
}

Create a DrvAbcView class whose code is shown below. This class implements a general, non-device specific driver user interface. View the source code of the DriverView base class to learn about the available features.

using Scada.Comm.Config;
using Scada.Comm.Devices;

namespace Scada.Comm.Drivers.DrvAbc.View
{
    public class DrvAbcView : DriverView
    {
        public DrvAbcView()
            : base()
        {
            CanCreateDevice = true;
        }

        public override string Name => "ABC Driver";

        public override string Descr => "Simple driver example";

        public override DeviceView CreateDeviceView(LineConfig lineConfig, DeviceConfig deviceConfig)
        {
            return new DevAbcView(this, lineConfig, deviceConfig);
        }
    }
}

An example of the driver part responsible for the user interface is ready. Build the project and copy DrvAbc.View.dll to the Administrator libraries directory ScadaAdmin\Lib

Run Driver

Start the Administrator application or restart it if it is open. Create a new project and find the developed driver in the Communicator > Drivers section. Select the driver and make sure its description is displayed correctly. If an error occurs when displaying a driver description, there is most likely an inaccuracy in the namespace or class names of the driver user interface.

Create a communication line and add a device using the DrvAbc driver to the line. Run the project. In the communication line log you can see information about the operation of the created driver:

2024-04-18 13:15:41 Session with the device [3] ABC
DrvAbc driver polling session