コード例 #1
0
        private bool SetCooler(int busId, uint value, bool isAutoMode)
        {
            #region GTX
            if (NvapiNativeMethods.NvSetCoolerLevels != null)
            {
                try {
                    NvCoolerTarget coolerIndex = NvCoolerTarget.NVAPI_COOLER_TARGET_ALL;
                    NvCoolerLevel  info        = new NvCoolerLevel()
                    {
                        version = (uint)(VERSION1 | (Marshal.SizeOf(typeof(NvCoolerLevel)))),
                        coolers = new NvCoolerLevelItem[NvapiConst.NVAPI_MAX_COOLERS_PER_GPU]
                    };
                    info.coolers[0].currentLevel  = isAutoMode ? 0 : value;
                    info.coolers[0].currentPolicy = isAutoMode ? NvCoolerPolicy.NVAPI_COOLER_POLICY_AUTO : NvCoolerPolicy.NVAPI_COOLER_POLICY_MANUAL;
                    var r = NvapiNativeMethods.NvSetCoolerLevels(HandlesByBusId[busId], coolerIndex, ref info);
                    if (r != NvStatus.OK)
                    {
                        Write.DevError($"{nameof(NvapiNativeMethods.NvSetCoolerLevels)} {r}");
                    }
                    else
                    {
                        return(true);
                    }
                }
                catch {
                }
            }
            #endregion

            #region RTX
            if (NvapiNativeMethods.NvFanCoolersSetControl == null)
            {
                return(false);
            }
            try {
                if (NvFanCoolersGetControl(busId, out PrivateFanCoolersControlV1 info))
                {
                    for (int i = 0; i < info.FanCoolersControlCount; i++)
                    {
                        info.FanCoolersControlEntries[i].ControlMode = isAutoMode ? FanCoolersControlMode.Auto : FanCoolersControlMode.Manual;
                        info.FanCoolersControlEntries[i].Level       = isAutoMode ? 0u : (uint)value;
                    }
                    var r = NvapiNativeMethods.NvFanCoolersSetControl(HandlesByBusId[busId], ref info);
                    if (r != NvStatus.OK)
                    {
                        Write.DevError($"{nameof(NvapiNativeMethods.NvFanCoolersSetControl)} {r}");
                        return(false);
                    }
                    return(true);
                }
                return(false);
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
                return(false);
            }
            #endregion
        }
コード例 #2
0
ファイル: NvapiHelper.cs プロジェクト: machangfengjia/NtMiner
        private bool SetCooler(int busId, uint value, bool isAutoMode)
        {
            if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle))
            {
                return(false);
            }
            #region GTX
            if (NvapiNativeMethods.NvSetCoolerLevels != null)
            {
                try {
                    NvCoolerTarget coolerIndex = NvCoolerTarget.NVAPI_COOLER_TARGET_ALL;
                    NvCoolerLevel  info        = NvCoolerLevel.Create();
                    info.coolers[0].currentLevel  = isAutoMode ? 0 : value;
                    info.coolers[0].currentPolicy = isAutoMode ? NvCoolerPolicy.NVAPI_COOLER_POLICY_AUTO : NvCoolerPolicy.NVAPI_COOLER_POLICY_MANUAL;
                    var r = NvapiNativeMethods.NvSetCoolerLevels(handle, coolerIndex, ref info);
                    if (r != NvStatus.NVAPI_OK)
                    {
                        NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvSetCoolerLevels)} {r.ToString()}");
                    }
                    else
                    {
                        return(true);
                    }
                }
                catch {
                }
            }
            #endregion

            #region RTX
            if (NvapiNativeMethods.NvFanCoolersSetControl == null)
            {
                return(false);
            }
            try {
                if (NvFanCoolersGetControl(busId, out PrivateFanCoolersControlV1 info))
                {
                    for (int i = 0; i < info.FanCoolersControlCount; i++)
                    {
                        info.FanCoolersControlEntries[i].ControlMode = isAutoMode ? FanCoolersControlMode.Auto : FanCoolersControlMode.Manual;
                        info.FanCoolersControlEntries[i].Level       = isAutoMode ? 0u : (uint)value;
                    }
                    var r = NvapiNativeMethods.NvFanCoolersSetControl(handle, ref info);
                    if (r != NvStatus.NVAPI_OK)
                    {
                        NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvFanCoolersSetControl)} {r.ToString()}");
                        return(false);
                    }
                    return(true);
                }
                return(false);
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
                return(false);
            }
            #endregion
        }