private void CardsMonitoring()
        {
            var messageBus = _messageBusFactory.Create();

            Task.Factory.StartNew(async() =>
            {
                do
                {
                    _lockEvent.WaitOne();
                    try
                    {
                        var ctrlGpu        = new ControlMemory();
                        var voltageMonitor = new HardwareMonitor();
                        var voltage        = new List <VoltageInfo>();
                        var temp           = new List <TempInfo>();

                        foreach (var vol in voltageMonitor.Entries.Where(x => x.SrcId == 96))
                        {
                            voltage.Add(new VoltageInfo {
                                Current = vol.Data, Max = vol.MaxLimit, CardId = vol.GPU
                            });
                        }
                        messageBus.Handle(new AutobernerVoltageCardsInfoMessage {
                            VoltageInfoModel = voltage.ToArray()
                        });

                        foreach (var vol in voltageMonitor.Entries.Where(x => x.SrcId == 0))
                        {
                            temp.Add(new TempInfo {
                                Current = vol.Data, CardId = vol.GPU
                            });
                        }
                        messageBus.Handle(new AutobernerTempCardsInfoMessage {
                            TempInfoModel = temp.ToArray()
                        });

                        ctrlGpu.Connect();
                        ctrlGpu.ReloadAll();
                        ctrlGpu.Reinitialize();

                        var actualList = FindCards(ctrlGpu);

                        messageBus.Handle(new AutobernerInformationMessage {
                            CurrentInfoCards = actualList.ToList()
                        });
                        ctrlGpu.Disconnect();
                    }
                    catch (Exception ex)
                    {
                        _logger.Error($"CardsMonitoring error: {ex.Message}");
                    }
                    await Task.Delay(_config.MonitoringInterval, _token.Token);
                } while (!_token.IsCancellationRequested);
            }, _token.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default)
            .ContinueWith((x) =>
            {
                messageBus.Handle <AutobernerStopWatchingMessage>();
            },
                          TaskContinuationOptions.OnlyOnFaulted);
        }
		/// <summary>
		///   Retrieves the text of a list-view item.
		/// </summary>
		/// <param name="index">Index of the desired item of which to retrieve the text.</param>
		public string GetItemText( int index )
		{
			string text = "";
			using ( var memory = new ControlMemory( Window, Marshal.SizeOf( typeof( User32.ListViewItem ) ) ) )
			{
				// TODO: Any way of knowing the maximum length of item text here?
				// Trial and error might be needed, trying a bigger buffer when the whole string is not retrieved:
				// http://forums.codeguru.com/showthread.php?351972-Getting-listView-item-text-length;
				var stringBuffer = new ControlMemory( Window, Constants.MaximumPathLength * 2 );
				var itemData = new User32.ListViewItem
				{
					TextMax = Constants.MaximumPathLength,
					Text = stringBuffer.Address
				};
				memory.Write( itemData );
				int length = (int)SendMessage( Message.GetItemText, new IntPtr( index ), memory.Address );
				itemData = memory.Read<User32.ListViewItem>();
				if ( length > 0 )
				{
					byte[] textBuffer = stringBuffer.Read<byte>( length * 2 );
					text = Encoding.Unicode.GetString( textBuffer );
				}
				stringBuffer.Dispose();
			}

			return text;
		}
Пример #3
0
 // 0 = coreClock, 1 = memClock, 2= shaderClock, 3 = fanSpeed
 private static int MSIConnect(int inputNumber)
 {
     ControlMemory macm = new ControlMemory();
     int coreClock = Convert.ToInt32(macm.GpuEntries[0].CoreClockCur);
     int memClock = Convert.ToInt32(macm.GpuEntries[0].MemoryClockCur);
     int shaderClock = Convert.ToInt32(macm.GpuEntries[0].ShaderClockCur);
     int fanSpeed = Convert.ToInt32(macm.GpuEntries[0].FanSpeedCur);
     if (inputNumber == 1)
     {
         return coreClock;
     }
     else if (inputNumber == 2)
     {
         return memClock;
     }
     else if (inputNumber == 3)
     {
         return shaderClock;
     }
     else if (inputNumber == 4)
     {
         return fanSpeed;
     }
     return 0;
 }
        private static IEnumerable <CardParam> FindCards(ControlMemory ctlm)
        {
            const int divider   = 1000;
            var       cardCount = ctlm.GpuEntries.Length;
            var       cards     = new CardParam[cardCount];

            for (uint i = 0; i < cardCount; i++)
            {
                var v1 = ctlm.GpuEntries[i];

                var flags        = v1.Flags;
                var voltageBoost = flags.HasFlag(MACM_SHARED_MEMORY_GPU_ENTRY_FLAG.CORE_VOLTAGE_BOOST);
                var voltage      = new CardMinMaxCurrent
                {
                    Current = voltageBoost ? v1.CoreVoltageBoostCur : (int)v1.CoreVoltageCur,
                    Max     = voltageBoost ? v1.CoreVoltageBoostMax : (int)v1.CoreVoltageMax,
                    Min     = voltageBoost ? v1.CoreVoltageBoostMin : (int)v1.CoreVoltageMin
                };
                var templimit = new CardMinMaxCurrent
                {
                    Current = v1.ThermalLimitCur,
                    Max     = v1.ThermalLimitMax,
                    Min     = v1.ThermalLimitMin
                };
                var voltagelimit = new CardMinMaxCurrent
                {
                    Current = v1.PowerLimitCur,
                    Max     = v1.PowerLimitMax,
                    Min     = v1.PowerLimitMin
                };
                var coreclockBoost = flags.HasFlag(MACM_SHARED_MEMORY_GPU_ENTRY_FLAG.CORE_CLOCK_BOOST);
                var coreclock      = new CardMinMaxCurrent
                {
                    Current = coreclockBoost ? v1.CoreClockBoostCur / divider : (int)v1.CoreClockCur / divider,
                    Max     = coreclockBoost ? v1.CoreClockBoostMax / divider : (int)v1.CoreClockMax / divider,
                    Min     = coreclockBoost ? v1.CoreClockBoostMin / divider : (int)v1.CoreClockMin / divider
                };
                var memoryclockBoost = flags.HasFlag(MACM_SHARED_MEMORY_GPU_ENTRY_FLAG.MEMORY_CLOCK_BOOST);
                var memoryclock      = new CardMinMaxCurrent
                {
                    Current = memoryclockBoost ? v1.MemoryClockBoostCur / divider : (int)v1.MemoryClockCur / divider,
                    Max     = memoryclockBoost ? v1.MemoryClockBoostMax / divider : (int)v1.MemoryClockMax / divider,
                    Min     = memoryclockBoost ? v1.MemoryClockBoostMin / divider : (int)v1.MemoryClockMin / divider
                };

                var fancontrol =
                    new CardMinMaxCurrent {
                    Current = v1.FanSpeedCur, Max = v1.FanSpeedMax, Min = v1.FanSpeedMin
                };
                var ismaster = v1.IsMaster;
                cards[i] = new CardParam(v1.Index, ismaster, voltage,
                                         templimit, voltagelimit, coreclock, memoryclock, fancontrol);
            }

            return(cards);
        }
Пример #5
0
        private static Task MSIconnecting(MainModel mm)
        {
            return(Task.Run(() =>
            {
                while (Process.GetProcessesByName("MSIAfterburner").Length == 0)
                {
                    Thread.Sleep(100);
                }
                try
                {
                    MSIpath = Process.GetProcessesByName("MSIAfterburner").First().MainModule.FileName;
                }
                catch { mm.Logging("Добавьте права администратора", true); }

                IEnumerable <ControlMemoryGpuEntry> GEs = new List <ControlMemoryGpuEntry>();
                while (GEs.Count() == 0)
                {
                    try
                    {
                        CM = new ControlMemory();
                        CM.ReloadAll();
                        GEs = CM.GpuEntries.Where(e => e.PowerLimitMax - e.PowerLimitMin != 0);
                        ValidGPUS = CM.GpuEntries.Select(e => e.PowerLimitMax - e.PowerLimitMin != 0);
                        Thread.Sleep(1000);
                    }
                    catch { Thread.Sleep(1000); }
                }

                MSIconnected = true;

                Task.Run(() => ConnectedToMSI?.Invoke(new DefClock
                {
                    PowerLimits = GEs.Select(e => e.PowerLimitDef).ToArray(),
                    CoreClocks = GEs.Select(e => (e.CoreClockBoostMin != 0 ? e.CoreClockBoostDef :
                                                  (e.CoreClockMin != 0 ? Convert.ToInt32(e.CoreClockDef) : 0)) / 1000).ToArray(),
                    MemoryClocks = GEs.Select(e => (e.MemoryClockBoostMin != 0 ? e.MemoryClockBoostDef :
                                                    (e.MemoryClockMin != 0 ? Convert.ToInt32(e.MemoryClockDef) : 0)) / 1000).ToArray(),
                    FanSpeeds = GEs.Select(e => Convert.ToInt32(e.FanSpeedDef)).ToArray()
                }));
            }));
        }
Пример #6
0
        public static void SetFanSpeed(string arg)
        {
            try
            {
                if (arg.Equals("auto", StringComparison.OrdinalIgnoreCase))
                {
                    ControlMemory control = new ControlMemory();

                    var gpu = control.GpuEntries.First();
                    gpu.FanFlagsCur = MACM_SHARED_MEMORY_GPU_ENTRY_FAN_FLAG.AUTO;
                    Console.WriteLine("Setting Fan Speed to AUTO");
                    control.CommitChanges();
                }
                else if (uint.TryParse(arg, out uint resultParse))
                {
                    if (resultParse >= 0 && resultParse <= 100)
                    {
                        ControlMemory control = new ControlMemory();

                        var gpu = control.GpuEntries.First();
                        gpu.FanFlagsCur = MACM_SHARED_MEMORY_GPU_ENTRY_FAN_FLAG.None;
                        gpu.FanSpeedCur = resultParse;
                        Console.WriteLine($"Setting Fan Speed to {resultParse}");
                        control.CommitChanges();
                    }
                    else
                    {
                        DisplayError();
                    }
                }
                else
                {
                    DisplayError();
                }
            }
            catch (Exception)
            {
                Console.WriteLine($"Error while setting fan value.");
                throw;
            }
        }
        private void CardsMonitoring(CardParam[] configCards)
        {
            var messageBus = _messageBusFactory.Create();

            Task.Factory.StartNew(async() =>
            {
                do
                {
                    _lockEvent.WaitOne();
                    try
                    {
                        var ctrlGpu = new ControlMemory();
                        ctrlGpu.Connect();
                        ctrlGpu.ReloadAll();
                        ctrlGpu.Reinitialize();

                        var actualList = FindCards(ctrlGpu);

                        ctrlGpu.Disconnect();

                        if (_config.WatchDog)
                        {
                            WatchDog(configCards, actualList);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error($"CardsMonitoring error: {ex.Message}");
                    }
                    await Task.Delay(_config.MonitoringInterval, _token.Token);
                } while (!_token.IsCancellationRequested);
            }, _token.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default)
            .ContinueWith((x) =>
            {
                messageBus.Publish <AutobernerStopWatchingMessage>();
            },
                          TaskContinuationOptions.OnlyOnFaulted);
        }
        private void RestoreCard(CardPramsMessageModel card)
        {
            const int divider    = 1000;
            var       messageBus = _messageBusFactory.Create();

            try
            {
                var lmacm = new ControlMemory();
                lmacm.Connect();

                var flags = lmacm.GpuEntries[card.Id].Flags;

                var voltageBoost     = flags.HasFlag(MACM_SHARED_MEMORY_GPU_ENTRY_FLAG.CORE_VOLTAGE_BOOST);
                var coreclockBoost   = flags.HasFlag(MACM_SHARED_MEMORY_GPU_ENTRY_FLAG.CORE_CLOCK_BOOST);
                var memoryclockBoost = flags.HasFlag(MACM_SHARED_MEMORY_GPU_ENTRY_FLAG.MEMORY_CLOCK_BOOST);


                lmacm.GpuEntries[card.Id].ThermalLimitCur = (int)card.TempLimit;
                lmacm.GpuEntries[card.Id].PowerLimitCur   = (int)card.PowerLimit;
                lmacm.GpuEntries[card.Id].FanSpeedCur     = (uint)card.FanSpeed;

                if (voltageBoost)
                {
                    lmacm.GpuEntries[card.Id].CoreVoltageBoostCur = (int)card.Voltage;
                }
                else
                {
                    lmacm.GpuEntries[card.Id].CoreVoltageCur = (uint)card.Voltage;
                }

                if (coreclockBoost)
                {
                    lmacm.GpuEntries[card.Id].CoreClockBoostCur = (int)card.CoreClock * divider;
                }
                else
                {
                    lmacm.GpuEntries[card.Id].CoreClockCur = (uint)card.CoreClock * divider;
                }

                if (memoryclockBoost)
                {
                    lmacm.GpuEntries[card.Id].MemoryClockBoostCur = (int)card.MemoryClock * divider;
                }
                else
                {
                    lmacm.GpuEntries[card.Id].MemoryClockCur = (uint)card.MemoryClock * divider;
                }


                lmacm.CommitChanges();
                lmacm.Disconnect();

                if (_logger.IsWarnEnabled)
                {
                    _logger.Warn($"Restore card > {card}");
                }
                messageBus.Handle(new AutobernerWatchdogResetMessage {
                    Status = MessageStatus.Ok
                });
            }
            catch (Exception ex)
            {
                _logger.Error($"inner exception: {ex.InnerException?.Message ?? string.Empty} > exception: {ex.Message}", ex);
                messageBus.Handle(new AutobernerWatchdogResetMessage {
                    Status = MessageStatus.Error
                });
            }
        }
        private void RestoreCard(CardParam[] configCards, CardParam card)
        {
            const int divider    = 1000;
            var       messageBus = _messageBusFactory.Create();

            try
            {
                if (card == null)
                {
                    _logger.Error("card for restore is null!, ret <");
                    return;
                }

                var lmacm = new ControlMemory();
                lmacm.Connect();

                var configCardParam = configCards.FirstOrDefault(x => x.Id == card.Id);

                if (configCardParam == null)
                {
                    if (_logger.IsDebugEnabled)
                    {
                        _logger.Debug($"Try restore card > {card} - error > not found in config");
                    }
                    return;
                }

                var flags = lmacm.GpuEntries[card.Id].Flags;

                var voltageBoost     = flags.HasFlag(MACM_SHARED_MEMORY_GPU_ENTRY_FLAG.CORE_VOLTAGE_BOOST);
                var coreclockBoost   = flags.HasFlag(MACM_SHARED_MEMORY_GPU_ENTRY_FLAG.CORE_CLOCK_BOOST);
                var memoryclockBoost = flags.HasFlag(MACM_SHARED_MEMORY_GPU_ENTRY_FLAG.MEMORY_CLOCK_BOOST);


                lmacm.GpuEntries[card.Id].ThermalLimitCur = (int)configCardParam.TempLimit.Current;
                lmacm.GpuEntries[card.Id].PowerLimitCur   = (int)configCardParam.PowerLimit.Current;
                lmacm.GpuEntries[card.Id].FanSpeedCur     = (uint)configCardParam.FanSpeed.Current;

                if (voltageBoost)
                {
                    lmacm.GpuEntries[card.Id].CoreVoltageBoostCur = (int)configCardParam.Voltage.Current;
                }
                else
                {
                    lmacm.GpuEntries[card.Id].CoreVoltageCur = (uint)configCardParam.Voltage.Current;
                }

                if (coreclockBoost)
                {
                    lmacm.GpuEntries[card.Id].CoreClockBoostCur = (int)configCardParam.CoreClock.Current * divider;
                }
                else
                {
                    lmacm.GpuEntries[card.Id].CoreClockCur = (uint)configCardParam.CoreClock.Current * divider;
                }

                if (memoryclockBoost)
                {
                    lmacm.GpuEntries[card.Id].MemoryClockBoostCur = (int)configCardParam.MemoryClock.Current * divider;
                }
                else
                {
                    lmacm.GpuEntries[card.Id].MemoryClockCur = (uint)configCardParam.MemoryClock.Current * divider;
                }


                lmacm.CommitChanges();
                lmacm.Disconnect();

                if (_logger.IsWarnEnabled)
                {
                    _logger.Warn($"Restore card > {card}");
                }
                messageBus.Publish(new AutobernerWatchdogResetMessage {
                    Status = MessageStatus.Ok
                });
            }
            catch (Exception ex)
            {
                _logger.Error($"inner exception: {ex.InnerException.Message} > exception: {ex.Message}", ex);
                messageBus.Publish(new AutobernerWatchdogResetMessage {
                    Status = MessageStatus.Error
                });
            }
        }
Пример #10
0
        public static void ApplyOverclock(IOverclock OC)
        {
            Task.Run(() =>
            {
                while (!MSIconnected)
                {
                    Thread.Sleep(100);
                }

                Process.Start(MSIpath);

                tryApplyClock:

                CM = new ControlMemory();
                ControlMemory nConf;
                List <ControlMemoryGpuEntry> gpuEnries = new List <ControlMemoryGpuEntry>();

                do
                {
                    Thread.Sleep(50);
                    CM.ReloadAll();
                    nConf = CM;
                    if (nConf.GpuEntries.Length > 0)
                    {
                        var vals = ValidGPUS.ToArray();
                        for (int i = 0; i < vals.Length; i++)
                        {
                            if (vals[i])
                            {
                                gpuEnries.Add(nConf.GpuEntries[i]);
                            }
                        }
                    }
                }while (gpuEnries[0].PowerLimitMax == 0);

                for (int i = 0; i < gpuEnries.Count; i++)
                {
                    try
                    {
                        gpuEnries[i].PowerLimitCur = SetParam(i, 1, OC.PowLim,
                                                              gpuEnries[i].PowerLimitMax,
                                                              gpuEnries[i].PowerLimitMin,
                                                              gpuEnries[i].PowerLimitDef);
                    }
                    catch { }

                    if (gpuEnries[i].CoreClockBoostMax - gpuEnries[i].CoreClockBoostMin != 0)
                    {
                        try
                        {
                            gpuEnries[i].CoreClockBoostCur = SetParam(i, 1000, OC.CoreClock,
                                                                      gpuEnries[i].CoreClockBoostMax,
                                                                      gpuEnries[i].CoreClockBoostMin,
                                                                      gpuEnries[i].CoreClockBoostDef);
                        }
                        catch { }
                    }
                    else if (gpuEnries[i].CoreClockMax - gpuEnries[i].CoreClockMin != 0)
                    {
                        try
                        {
                            gpuEnries[i].CoreClockCur = SetParam(i, 1000, OC.CoreClock,
                                                                 gpuEnries[i].CoreClockMax,
                                                                 gpuEnries[i].CoreClockMin,
                                                                 gpuEnries[i].CoreClockDef);
                        }
                        catch { }
                    }

                    if (gpuEnries[i].MemoryClockBoostMax - gpuEnries[i].MemoryClockBoostMin != 0)
                    {
                        try
                        {
                            gpuEnries[i].MemoryClockBoostCur = SetParam(i, 1000, OC.MemoryClock,
                                                                        gpuEnries[i].MemoryClockBoostMax,
                                                                        gpuEnries[i].MemoryClockBoostMin,
                                                                        gpuEnries[i].MemoryClockBoostDef);
                        }
                        catch { }
                    }
                    else if (gpuEnries[i].MemoryClockMax - gpuEnries[i].MemoryClockMin != 0)
                    {
                        try
                        {
                            gpuEnries[i].MemoryClockCur = SetParam(i, 1000, OC.MemoryClock,
                                                                   gpuEnries[i].MemoryClockMax,
                                                                   gpuEnries[i].MemoryClockMin,
                                                                   gpuEnries[i].MemoryClockDef);
                        }
                        catch { }
                    }

                    try
                    {
                        if (OC.FanSpeed != null)
                        {
                            if (OC.FanSpeed.Length > i)
                            {
                                gpuEnries[i].FanFlagsCur = MACM_SHARED_MEMORY_GPU_ENTRY_FAN_FLAG.None;
                                if (OC.FanSpeed[i] > gpuEnries[i].FanSpeedMax)
                                {
                                    gpuEnries[i].FanSpeedCur = gpuEnries[i].FanSpeedMax;
                                }
                                else if (OC.FanSpeed[i] < gpuEnries[i].FanSpeedMin)
                                {
                                    gpuEnries[i].FanSpeedCur = gpuEnries[i].FanSpeedMin;
                                }
                                else
                                {
                                    gpuEnries[i].FanSpeedCur = Convert.ToUInt32(OC.FanSpeed[i]);
                                }
                            }
                            else
                            {
                                gpuEnries[i].FanFlagsCur = MACM_SHARED_MEMORY_GPU_ENTRY_FAN_FLAG.AUTO;
                            }
                        }
                        else
                        {
                            gpuEnries[i].FanFlagsCur = MACM_SHARED_MEMORY_GPU_ENTRY_FAN_FLAG.AUTO;
                        }
                    }
                    catch { }
                }

                while (true)
                {
                    try
                    {
                        CM = nConf;
                        CM.CommitChanges();

                        Thread.Sleep(3000);

                        if (MSICurrent != null)
                        {
                            var msi = MSICurrent.Value;

                            for (int i = 0; i < OC.PowLim.Length; i++)
                            {
                                if (OC.PowLim != null)
                                {
                                    if (msi.PowerLimits[i] != OC.PowLim[i])
                                    {
                                        goto tryApplyClock;
                                    }
                                }

                                if (OC.CoreClock != null)
                                {
                                    if (msi.CoreClocks[i] != OC.CoreClock[i])
                                    {
                                        goto tryApplyClock;
                                    }
                                }

                                if (OC.MemoryClock != null)
                                {
                                    if (msi.MemoryClocks[i] != OC.MemoryClock[i])
                                    {
                                        goto tryApplyClock;
                                    }
                                }
                            }
                        }
                        else
                        {
                            goto tryApplyClock;
                        }


                        Task.Run(() => OverclockApplied?.Invoke());
                        return;
                    }
                    catch { }
                    Thread.Sleep(50);
                }
            });
        }
Пример #11
0
        private bool Testmab(int i)
        {
            bool          result = true;
            AppExtControl aec    = new AppExtControl("", AppExtOperation.Connect, 10000, 2000);

            string s = i.ToString() + ". (" + DateTime.Now + "): ";

            s += "exeApp1.Start = ";
            try
            {
                s += MSIAB.Start(txtMSIABFile.Text, "-Profile1", aec).ToString() + "; ";
            }
            catch (Exception e)
            {
                s     += e.Message + "; ";
                result = false;
            }

            System.Threading.Thread.Sleep(5000);


            s += "new ControlMemory() = ";
            try
            {
                macm = new ControlMemory();
                s   += "Ok; ";
            }
            catch (Exception e)
            {
                s     += e.Message + "; ";
                result = false;
            }

            s += "new HardwareMonitor() = ";
            try
            {
                mahm = new HardwareMonitor();
                s   += "Ok; ";
            }
            catch (Exception e)
            {
                s     += e.Message + "; ";
                result = false;
            }

            System.Threading.Thread.Sleep(8000);

            s += "Close = " + MSIAB.Close(2000).ToString() + "; ";

            System.Threading.Thread.Sleep(2000);

            StreamWriter file;

            file = new StreamWriter(CommonProc.ApplicationExePath + "log.txt", i != 0);
            file.Write(s + Environment.NewLine);
            file.Close();
            Wr(s);


            return(result);
        }
Пример #12
0
        //private void a

        private bool ShowMsiState()
        {
            txtLog.Clear();
            //lvMsi.Items.Clear();
            //lvMsi.Clear();

            int normalColumnWidth = 20;

            dgvMSI.Rows.Clear();
            dgvMSI.Columns.Clear();
            dgvMSI.AutoGenerateColumns       = false;
            dgvMSI.RowHeadersVisible         = false;
            dgvMSI.MultiSelect               = false;
            dgvMSI.SelectionMode             = DataGridViewSelectionMode.FullRowSelect;
            dgvMSI.AutoSizeRowsMode          = DataGridViewAutoSizeRowsMode.AllCells;
            dgvMSI.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

            //dgvMSI.Columns.Add(new DataGridViewTextBoxColumn() {HeaderText = "Index", ReadOnly = true, AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, FillWeight = normalColumnWidth });
            //dgvMSI.Columns.Add(new DataGridViewTextBoxColumn() {HeaderText = "Device", ReadOnly = true, AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, FillWeight = normalColumnWidth });
            //dgvMSI.Columns.Add(new DataGridViewTextBoxColumn() {HeaderText = "GpuId", ReadOnly = true, AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, FillWeight = normalColumnWidth });

            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "Index", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "Device", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "GpuId", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "Val", ReadOnly = true, FillWeight = normalColumnWidth
            });

            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "FanSpeed", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "CoreClock", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "ShaderClock", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "MemoryClock", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "CoreVoltage", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "MemoryVoltage", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "AuxVoltage", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "CoreVoltageBoost", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "MemoryVoltageBoost", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "AuxVoltageBoost", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "PowerLimit", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "CoreClockBoost", ReadOnly = true, FillWeight = normalColumnWidth
            });
            dgvMSI.Columns.Add(new DataGridViewTextBoxColumn()
            {
                HeaderText = "MemoryClockBoost", ReadOnly = true, FillWeight = normalColumnWidth
            });


            //lvMsi.Columns.Add("Index", normalColumnWidth);
            //lvMsi.Columns.Add("Device", normalColumnWidth);
            //lvMsi.Columns.Add("GpuId", normalColumnWidth);

            //foreach (ColumnHeader cl in lvMsi.Columns)
            //{
            //  //cl.
            //}

            bool result = true;

            try
            {
                if (macm == null)
                {
                    macm = new ControlMemory();
                }
                else
                {
                    macm.Disconnect();
                    macm.Connect();
                }
            }
            catch (Exception e)
            {
                Wr(e.Message);
                result = false;
                //return false;
            }

            try
            {
                if (mahm == null)
                {
                    mahm = new HardwareMonitor();
                }
                else
                {
                    mahm.Disconnect();
                    mahm.Connect();
                }
            }
            catch (Exception e)
            {
                Wr(e.Message);
                result = false;
                //return false;
            }

            if (!result)
            {
                return(result);
            }

            for (int i = 0; i < mahm.Header.GpuEntryCount; i++)
            {
                //wr("***** MSI AFTERTERBURNER GPU " + i + " *****");
                ControlMemoryGpuEntry ge = macm.GpuEntries[i];
                dgvMSI.Rows.Add(new String[]
                                { i.ToString(),
                                  mahm.GpuEntries[i].Index.ToString(),
                                  mahm.GpuEntries[i].Device,
                                  mahm.GpuEntries[i].GpuId,
                                  "Cur:" + "\n" + "Min:" + "\n" + "Max:" + "\n" + "Def:",
                                  ge.FanSpeedCur.ToString() + "\n" + ge.FanSpeedMin.ToString() + "\n" + ge.FanSpeedMax.ToString() + "\n" + ge.FanSpeedDef.ToString(),
                                  ge.CoreClockCur.ToString() + "\n" + ge.CoreClockMin.ToString() + "\n" + ge.CoreClockMax.ToString() + "\n" + ge.CoreClockDef.ToString(),
                                  ge.ShaderClockCur.ToString() + "\n" + ge.ShaderClockMin.ToString() + "\n" + ge.ShaderClockMax.ToString() + "\n" + ge.ShaderClockDef.ToString(),
                                  ge.MemoryClockCur.ToString() + "\n" + ge.MemoryClockMin.ToString() + "\n" + ge.MemoryClockMax.ToString() + "\n" + ge.MemoryClockDef.ToString(),
                                  ge.CoreVoltageCur.ToString() + "\n" + ge.CoreVoltageMin.ToString() + "\n" + ge.CoreVoltageMax.ToString() + "\n" + ge.CoreVoltageDef.ToString(),
                                  ge.MemoryVoltageCur.ToString() + "\n" + ge.MemoryVoltageMin.ToString() + "\n" + ge.MemoryVoltageMax.ToString() + "\n" + ge.MemoryVoltageDef.ToString(),
                                  ge.AuxVoltageCur.ToString() + "\n" + ge.AuxVoltageMin.ToString() + "\n" + ge.AuxVoltageMax.ToString() + "\n" + ge.AuxVoltageDef.ToString(),
                                  ge.CoreVoltageBoostCur.ToString() + "\n" + ge.CoreVoltageBoostMin.ToString() + "\n" + ge.CoreVoltageBoostMax.ToString() + "\n" + ge.CoreVoltageBoostDef.ToString(),
                                  ge.MemoryVoltageBoostCur.ToString() + "\n" + ge.MemoryVoltageBoostMin.ToString() + "\n" + ge.MemoryVoltageBoostMax.ToString() + "\n" + ge.MemoryVoltageBoostDef.ToString(),
                                  ge.AuxVoltageBoostCur.ToString() + "\n" + ge.AuxVoltageBoostMin.ToString() + "\n" + ge.AuxVoltageBoostMax.ToString() + "\n" + ge.AuxVoltageBoostDef.ToString(),
                                  ge.PowerLimitCur.ToString() + "\n" + ge.PowerLimitMin.ToString() + "\n" + ge.PowerLimitMax.ToString() + "\n" + ge.PowerLimitDef.ToString(),
                                  ge.CoreClockBoostCur.ToString() + "\n" + ge.CoreClockBoostMin.ToString() + "\n" + ge.CoreClockBoostMax.ToString() + "\n" + ge.CoreClockBoostDef.ToString(),
                                  ge.MemoryClockBoostCur.ToString() + "\n" + ge.MemoryClockBoostMin.ToString() + "\n" + ge.MemoryClockBoostMax.ToString() + "\n" + ge.MemoryClockBoostDef.ToString() });

                //ListViewItem li =  lvMsi.Items.Add(mahm.GpuEntries[i].Index.ToString());
                //li.SubItems.Add(mahm.GpuEntries[i].Device);
                //li.SubItems.Add(mahm.GpuEntries[i].GpuId);

                //li.SubItems.Add(mahm.Entries[i].);
            }

            Wr("***** macm.Header.MasterGpu " + macm.Header.MasterGpu.ToString());
            Wr();
            for (int i = 0; i < macm.Header.GpuEntryCount; i++)
            {
                Wr("***** MSI AFTERTERBURNER GPU " + i + " *****");
                Wr("Index: " + macm.GpuEntries[i].Index.ToString());
                Wr(macm.GpuEntries[i].ToString().Replace(";", Environment.NewLine));
                Wr();
            }

            Wr();
            Wr("****************************************************************");
            Wr();
            for (int i = 0; i < mahm.Header.EntryCount; i++)
            {
                Wr("***** MSI AFTERTERBURNER DATA SOURCE " + i + " *****");
                Wr(mahm.Entries[i].ToString());//.Replace(";", "\n"));
                Wr();
            }
            return(true);
        }