示例#1
0
 public static OneDasDataType GetOneDasDataTypeFromEthercatDataType(string value)
 {
     if (value == null)
     {
         return(0);
     }
     else
     {
         return(EcUtilities.GetOneDasDataTypeFromEthercatDataType((EthercatDataType)Enum.Parse(typeof(EthercatDataType), value)));
     }
 }
示例#2
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);
        }