All Tutorials / DJ Sures / How To Make An EZ-Builder Plugin

How To Make An EZ-Builder Plugin

Code: Saving/Loading Configuration

In all plugins, there is a _cf variable which is provided by the inherited class which defines the Form. The _cf (configuration file) contains the data saved with your project. The _cf.STORAGE[key] is where your plugin configuration is kept. However, due to EZ-Builder providing the UCServoSelection user control, there is also a _cf.SERVOS[key] to store servo configuration.

The UCServoSelection user control is the common displayed control across all configuration screens in EZ-Builder. This user control allows configuration of servo ports, min and max distances. As well as multi servo support, etc.. So, if your plugin is to use the UCServoSelection, we highly recommend doing so. To move servos with UCServoSelection configuration data, the example source code in the above mentioned project should be reviewed. In short, it's easy to pass UCServoSelection.Config() data to the EZ_Builder.EZBManager.SetServoPosition(), which will take care of the magic - including relationship scaling between multiple servos, min, max and inverted options from UCServoSelection.

Configuration settings must be initialized with default values in the SetConfiguration override. This will ensure that when your plugin is loaded, there is some default configuration data assigned to the keys. Because the data is initialized using the _cf.STORAGE.AddIfNotExist(), the default data will only be added if the key doesn't exist. If the key does exist, following the user loading a project with saved configuration data, the default configuration will not be applied to the key. As demonstrated...


public override void SetConfiguration(EZ_Builder.Config.Sub.PluginV1 cf) {

cf.SERVOS.AddIfNotExist(ConfigurationDictionary._HORIZONTAL_SERVOS, new EZ_Builder.Config.Sub.ServoDescriptor[] { });
cf.SERVOS.AddIfNotExist(ConfigurationDictionary._VERTICAL_SERVOS, new EZ_Builder.Config.Sub.ServoDescriptor[] { });

cf.STORAGE.AddIfNotExist(ConfigurationDictionary._HORIZONTAL_DEGREES, 0.14m);
cf.STORAGE.AddIfNotExist(ConfigurationDictionary._VERTICAL_DEGREES, 0.14m);
cf.STORAGE.AddIfNotExist(ConfigurationDictionary._EDGE_ENABLED, true);
cf.STORAGE.AddIfNotExist(ConfigurationDictionary._EDGE_SIZE, 10);


The base.SetConfiguration in the above example is necessary to set the configuration with the inherited base. This ensures the initialized configuration is applied.

Also in the above example, the ConfigurationDictionary is a class which contains readonly static strings to reference the resource keys. We use these strings so the configuration data can be referenced without worrying about spelling mistakes where ever the data is to be accessed. Here is a look at the above example ConfigurationDictionary...


public class ConfigurationDictionary {

public static readonly string _HORIZONTAL_SERVOS = "horizontal servos";
public static readonly string _VERTICAL_SERVOS = "vertical servos";

public static readonly string _HORIZONTAL_DEGREES = "horizontal degrees";
public static readonly string _VERTICAL_DEGREES = "vertical degrees";

public static readonly string _EDGE_SIZE = "edge size";
public static readonly string _EDGE_ENABLED = "edge enabled";

Now to use the configuration data from the _cf in your project, simply cast the object from the _cf.STORAGE to the correct type. For _cf.SERVOS, pass the key result directly into the EZ_Builder.EZBManager helper methods. Like so...


if (Convert.ToBoolean(_cf.STORAGE[ConfigurationDictionary._EDGE_ENABLED])) {

int edgeSize = Convert.ToInt16(_cf.STORAGE[ConfigurationDictionary._EDGE_SIZE]);
var servosX = _cf.SERVOS[ConfigurationDictionary._HORIZONTAL_SERVOS];
var servosY = _cf.SERVOS[ConfigurationDictionary._VERTICAL_SERVOS];

if (_mousePoint.X _cameraControl.Camera.CaptureWidth - 10)
EZ_Builder.EZBManager.SetServoIncrement(servosX, 1);

if (_mousePoint.Y _cameraControl.Camera.CaptureHeight - 10)
EZ_Builder.EZBManager.SetServoIncrement(servosY, 1);

Any data in the _cf.STORAGE and _cf.SERVOS will be automatically saved with the users project. And when that project is loaded again in the future, the _cf data will be reloaded as well. This allows your plugin to save the custom configuration applied by the user.

A great example that demonstrates how to provide a Configuration Screen for your plugin is here: