private void ConfigureSlaves(IList <SlaveInfo> slaves) { var callbacks = new List <EcHL.PO2SOCallback>(); foreach (var slave in slaves) { // SDO / PDO config / PDO assign var currentSlaveIndex = (ushort)(Convert.ToUInt16(slaves.ToList().IndexOf(slave)) + 1); var extensions = slave.Extensions; var sdoWriteRequests = slave.GetConfiguration(extensions).ToList(); EcHL.PO2SOCallback callback = slaveIndex => { sdoWriteRequests.ToList().ForEach(sdoWriteRequest => { EcUtilities.CheckErrorCode(this.Context, EcUtilities.SdoWrite(this.Context, slaveIndex, sdoWriteRequest.Index, sdoWriteRequest.SubIndex, sdoWriteRequest.Dataset), nameof(EcHL.SdoWrite)); }); return(0); }; EcHL.RegisterCallback(this.Context, currentSlaveIndex, callback); callbacks.Add(callback); } callbacks.ForEach(callback => { GC.KeepAlive(callback); }); }
private void ConfigureSlaves(IList <SlaveInfo> slaveInfoSet) { List <EcHL.PO2SOCallback> callbackSet; callbackSet = new List <EcHL.PO2SOCallback>(); foreach (SlaveInfo slaveInfo in slaveInfoSet) { ushort currentSlaveIndex; IEnumerable <SlaveExtensionLogic> extensionSet; IEnumerable <SdoWriteRequest> sdoWriteRequestSet; EcHL.PO2SOCallback callback; // SDO / PDO config / PDO assign currentSlaveIndex = (ushort)(Convert.ToUInt16(slaveInfoSet.ToList().IndexOf(slaveInfo)) + 1); extensionSet = slaveInfo.SlaveExtensionSet.Select(slaveExtension => _extensionFactory.BuildLogic <SlaveExtensionLogic>(slaveExtension)).ToList(); sdoWriteRequestSet = slaveInfo.GetConfiguration(extensionSet).ToList(); callback = slaveIndex => { sdoWriteRequestSet.ToList().ForEach(sdoWriteRequest => { EcUtilities.CheckErrorCode(this.Context, EcUtilities.SdoWrite(this.Context, slaveIndex, sdoWriteRequest.Index, sdoWriteRequest.SubIndex, sdoWriteRequest.Dataset), nameof(EcHL.SdoWrite)); }); return(0); }; EcHL.RegisterCallback(this.Context, currentSlaveIndex, callback); callbackSet.Add(callback); } callbackSet.ForEach(callback => { GC.KeepAlive(callback); }); }