7. How to integrate EniEngine

This chapter gives you an idea how to integrate the EniEngine.

7.1. Create Environment

At first you need to create the environment. You need for example the path to the ESI files and have to create a EniFile object.

var defaultFileIo = new EcDefaultFileIo
{
EsiPath = "PathToESIs" //Path to your ESI files
};


// Initialize ENI Engine's factory.
EniFile = new EcEniFile
(null, // optional implement IErrorHandler for Error handling (see below)
defaultFileIo);

// Load ESI cache (ESICache.xml) or create a new one if not already existing.
EniFile.EsiManager.LoadCache();

If you need Error Messages for the Error Handler, implement this function.

public void HandleEniEngineNotification(EcEniEngineCode code, params object[] args)

Conclusion: Now a EcEniFile object with an EcEniDevice is created.

7.2. Configure created Device

Now you can pick your device and change name and settings.

var device = EniFile.Device;

device.Name = "MyMasterName";
device.SettingsData.CycleTimeUs = 1000;
device.SettingsUpdate(device.SettingsData); //Important to update the value!!

7.3. Create slaves

Now it is possible to create some slaves:

var ek1100 = device.CreateSlave(2, 72100946, 1179648); //(VendorId, ProductCode, RevisionNumber)
var el2004 = device.CreateSlave(2, 131346514, 1179648);
var el3152 = device.CreateSlave(2, 206581842, 1245184);

7.4. Build Tree and configure slaves

Now that there is a device and some slaves you have to build your tree.

device.AddSlave(ek1100);
ek1100.AppendSlave(el2004, EcEniSlave.SlavePort.PortName.EPortB);
el2004.AppendSlave(el3152, EcEniSlave.SlavePort.PortName.EPortB);

Also you can change settings of the slaves.

ek1100.SettingsData.Settings.CheckRevisionNo = EcEniSlaveSettings.CheckType.ENone;
ek1100.SettingsData.Write(ek1100.SettingsData.Settings); //Important to update the value!!

You can also change other things, like adding a CoE InitCommand if CoE is supported

if (el3152.IsSupported(EcEniSlave.EFeature.ECoe))
    {
        var coe = new EcEniSlaveCoe.InitCmd { Ccs = 1, Index = 9999, SubIndex = 0 };
        coe.Transition.Add(EcEniSlaveInitCmd.ETransition.EOp);

        el3152.CoeData.AddInitCmd(coe);
    }

7.5. Generate ENI

If you have changed all the things you like, you can generate the ENI file:

device.GenerateEni("PathToENIFile");

So you generated an ENI file with less than 100 lines of code.