Example #1
0
        public static SlavePdo[] UploadPdoConfig(IntPtr context, UInt16 slave, UInt16 smIndex)
        {
            int    pdoCount;
            IntPtr ecPdoInfoPtrSet;

            SlavePdo[]      slavePdoSet;
            SyncManagerType syncManagerType;
            DataDirection   dataDirection;

            //
            EcHL.GetSyncManagerType(context, slave, smIndex, out syncManagerType);

            switch (syncManagerType)
            {
            case SyncManagerType.Inputs:
                dataDirection = DataDirection.Input;
                break;

            case SyncManagerType.Outputs:
                dataDirection = DataDirection.Output;
                break;

            default:
                throw new ArgumentException();
            }

            EcHL.UploadPdoConfig(context, slave, smIndex, out ecPdoInfoPtrSet, out pdoCount);

            slavePdoSet = Enumerable.Range(0, pdoCount).Select(index =>
            {
                ec_pdo_info_t ecPdoInfo;
                SlavePdo slavePdo;
                IntPtr ecPdoInfoPtr;

                ecPdoInfoPtr = IntPtr.Add(ecPdoInfoPtrSet, index * Marshal.SizeOf(typeof(ec_pdo_info_t)));
                ecPdoInfo    = Marshal.PtrToStructure <ec_pdo_info_t>(ecPdoInfoPtr);
                slavePdo     = new SlavePdo(null, ecPdoInfo.name, ecPdoInfo.index, 0, true, true, smIndex - 0x1C10);

                slavePdo.SetVariableSet(Enumerable.Range(0, ecPdoInfo.variableCount).Select(index2 =>
                {
                    ec_variable_info_t ecVariableInfo;
                    SlaveVariable slaveVariable;
                    IntPtr ecVariableInfoPtr;

                    ecVariableInfoPtr = IntPtr.Add(ecPdoInfo.variableInfoSet, index2 * Marshal.SizeOf(typeof(ec_variable_info_t)));
                    ecVariableInfo    = Marshal.PtrToStructure <ec_variable_info_t>(ecVariableInfoPtr);
                    slaveVariable     = new SlaveVariable(slavePdo, ecVariableInfo.name, ecVariableInfo.index, ecVariableInfo.subIndex, dataDirection, EcUtilities.GetOneDasDataTypeFromEthercatDataType(ecVariableInfo.dataType));

                    return(slaveVariable);
                }).ToList());

                EcHL.Free(ecPdoInfo.variableInfoSet);

                return(slavePdo);
            }).ToArray();

            EcHL.Free(ecPdoInfoPtrSet);

            return(slavePdoSet);
        }
Example #2
0
        public static SlavePdo[] UploadPdoConfig(IntPtr context, UInt16 slave, UInt16 smIndex)
        {
            EcHL.GetSyncManagerType(context, slave, smIndex, out var syncManagerType);

            DataDirection dataDirection;

            switch (syncManagerType)
            {
            case SyncManagerType.Inputs:
                dataDirection = DataDirection.Input;
                break;

            case SyncManagerType.Outputs:
                dataDirection = DataDirection.Output;
                break;

            default:
                throw new ArgumentException();
            }

            EcHL.UploadPdoConfig(context, slave, smIndex, out var ecPdoInfoPtrs, out var pdoCount);

            var slavePdos = Enumerable.Range(0, pdoCount).Select(index =>
            {
                var ecPdoInfoPtr = IntPtr.Add(ecPdoInfoPtrs, index * Marshal.SizeOf(typeof(ec_pdo_info_t)));
                var ecPdoInfo    = Marshal.PtrToStructure <ec_pdo_info_t>(ecPdoInfoPtr);
                var slavePdo     = new SlavePdo(null, ecPdoInfo.name, ecPdoInfo.index, 0, true, true, smIndex - 0x1C10);

                slavePdo.SetVariables(Enumerable.Range(0, ecPdoInfo.variableCount).Select(index2 =>
                {
                    var ecVariableInfoPtr = IntPtr.Add(ecPdoInfo.variableInfos, index2 * Marshal.SizeOf(typeof(ec_variable_info_t)));
                    var ecVariableInfo    = Marshal.PtrToStructure <ec_variable_info_t>(ecVariableInfoPtr);
                    var slaveVariable     = new SlaveVariable(slavePdo, ecVariableInfo.name, ecVariableInfo.index, ecVariableInfo.subIndex, dataDirection, ecVariableInfo.dataType);

                    return(slaveVariable);
                }).ToList());

                EcHL.Free(ecPdoInfo.variableInfos);

                return(slavePdo);
            }).ToArray();

            EcHL.Free(ecPdoInfoPtrs);

            return(slavePdos);
        }