Skip to end of metadata
Go to start of metadata

 

Define the Driver’s Settings

By extending the PersistentRecord class, you can define any configurable properties your driver needs to present to the user, as well as a few pieces of metadata that are displayed in the Ignition Gateway when editing or creating a new device. 

 

Define a Driver Type

The DriverType class is one of the base extension point type classes from which all drivers must extend.  Defining a driver type will allow you to create new driver instances, as well as bridge the gap between the gateway and your driver’s settings.

 

Create a Gateway Module Hook

Best Practice

A partial implementation of a drivers GatewayModuleHook can be found in AbstractDriverModuleHook. This class takes care of all the details of registering and unregistering your driver.  Subclasses need only provide a List<DriverType> to register. 

 

Creating a gateway module hook will allow you to register your driver with the Driver Manager, as well as enforce licensing and API version compatibility.

 

Registering Your Driver

Registering your DriverType is a three step procedure:

  1. Implement the ModuleServiceConsumer interface on your module's hook class. For more information about module hooks, see Scopes, Hooks, and Contexts.

  2. During startup(), subscribe to DeviceManager.class.

    context.getModuleServicesManager().subscribe(DeviceManager.class, this);
  3. In serviceRead(Class<?> serviceClass), do something like the following:

    @Override
    public void serviceReady(Class<?> serviceClass) { 
    	if (serviceClass == DriverManager.class) {
    		driverManager = (DriverManager) context.getModuleServicesManager().getService(DriverManager.class);
    
    		if (driverManager != null) {
    			for (DriverType driverType : driverTypes) {
    				try {
    					driverManager.registerDriverType(driverType);
    				} catch (Exception e) {
    					Logger.getLogger(getClass()).error("Error registering DriverType.", e);
    				}
    			}
    		}
    	}
    } 

Shutdown

During shutdown() it's important to unsubscribe to the DeviceManager.class service as well as unregister any drivers you may have registered.

 

@Override
public void shutdown() { 
	if (context != null) {
		context.getModuleServicesManager().unsubscribe(DriverManager.class, this);

		if (driverManager != null) {
			for (DriverType driverType : driverTypes) {
				try {
					driverManager.unregisterDriverType(driverType);
				} catch (Exception e) {
					Logger.getLogger(getClass()).error("Error unregistering DriverType.", e);
				}
			}
		}

		context = null;
		driverManager = null;
	}
} 

 

 

During the course of startup you should check and make sure DriverAPI.VERSION is the API version number your driver is written against. Changes in API version number are not meant to be backwards compatible. If you extend from AbstractDriverModuleHook all you need to do is implement getExpectedAPIVersion().
@Override
public void startup(LicenseState activationState) { 
	if (DriverAPI.VERSION != EXPECTED_API_VERSION) {
		throw new RuntimeException(String.format("Expected Driver API version %s but found %s instead.", 
												getExpectedAPIVersion(), DriverAPI.VERSION));
	} 
	//...
}

 

Implement the Driver Interface


All OPC-UA drivers must, at a minimum, implement the Driver interface. This interface defines the basic functionality any driver must provide - reading, writing, browsing, subscription management, and life cycle/state management. 
A partially complete implementation of Driver is available by extending from AbstractDriver. Extending from this class is encouraged as the complexities derived from managing subscription state and the request life cycle of your subscriptions in a highly asynchronous environment are handled for you. 

Best Practice

Extending from AbstractDriver will make your life a whole lot easier.

 

 

  • No labels