示例#1
0
        private void OnTimer(object sender, ElapsedEventArgs e)
        {
            //Attempt to read shared memory.
            bool readSuccess = coreTempInfo.GetData();

            //If read was successful the post the new info on the console.
            if (readSuccess)
            {
                var temps   = coreTempInfo.GetTemp;
                var maxTemp = temps.Max();
                logWriter.WriteLine("Tmax {0}", maxTemp);
            }
            else
            {
                eventLog.WriteEntry("Internal error name: " + coreTempInfo.GetLastError);
                eventLog.WriteEntry("Internal error message: " + coreTempInfo.GetErrorMessage(coreTempInfo.GetLastError));
            }
        }
        // from the core temp demo code
        private void RefreshInfo_Elapsed(object sender, ElapsedEventArgs e)
        {
            //Attempt to read shared memory.
            bool bReadSuccess = CTInfo.GetData();

            if (bReadSuccess)
            {
                uint  index;
                float maxT = 1.0f;
                int   load = 0;
                // get max and avg load for all cpu's + cores
                for (uint i = 0; i < CTInfo.GetCPUCount; i++)
                {
                    for (uint g = 0; g < CTInfo.GetCoreCount; g++)
                    {
                        index = g + (i * CTInfo.GetCoreCount);
                        if (!CTInfo.IsDistanceToTjMax)
                        {
                            if (maxT <= CTInfo.GetTemp[index])
                            {
                                maxT = CTInfo.GetTemp[index];
                            }
                            load += (int)CTInfo.GetCoreLoad[index];
                        }
                    }
                }

                //date string
                string   datePatt = @"HH:mm";
                DateTime saveNow  = DateTime.Now;
                DateTime myDt;
                myDt = DateTime.SpecifyKind(saveNow, DateTimeKind.Local);
                string dtString;


                // setup output string
                // Core Speed, Core Temp, Max Core Temp, Time, Average Load,
                // #.#Ghz,#.#,##:##,###

                dtString = myDt.ToString(datePatt);
                HardwareMonitor mahm = new HardwareMonitor();
                //String output = Math.Round((CTInfo.GetCPUSpeed / 1000), 1) + "Ghz" + ";" + Math.Round(maxT, 1) + ";" + dtString + ";" + +((int)(load / CTInfo.GetCoreCount));
                //String output = "RAM:" + (((totalRam - getAvailableRAM()) * 100 / totalRam)) + "%" + ";" + Math.Round(maxT, 1) + ";" + dtString + ";" + +((int)(load / CTInfo.GetCoreCount)); //CPU
                String output = "0:" + mahm.Entries[0].Data.ToString() + "C;1:" + mahm.Entries[1].Data.ToString() + "C;" + (((totalRam - getAvailableRAM()) * 100 / totalRam)) + ";" + Math.Round(maxT, 0) + "C;" + mahm.Entries[2].Data.ToString() + ";" + ((int)(load / CTInfo.GetCoreCount));
                //update tooltip icon
                ACTnotf.Text = "Module Running - " + output;

                // write com if avail if not notify
                if (comPort.IsOpen)
                {
                    try{
                        comPort.WriteLine(output);
                    }
                    catch (System.IO.IOException argEx)
                    {
                    }
                    try
                    {
                        this.Invoke((MethodInvoker) delegate
                        {                            // added ram to display not to string as arduino is not updated to show it yet.
                            //tbConsole.Text = output + ";" + getAvailableRAM() + ";" + totalRam + ";" + ((getAvailableRAM() * 100 / totalRam))+"%"; // runs on UI thread
                            tbConsole.Text = output; // modificado
                        });
                    }

                    catch (Exception excp)
                    {
                    }
                }
                else // no com available
                {
                    try
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            tbConsole.Text = "Com port not available"; // runs on UI thread
                        });
                    }
                    catch (Exception excp)
                    {
                    }
                }
            }
            else // coretemp not avail
            {
                this.Invoke((MethodInvoker) delegate
                {
                    tbConsole.Text = CTInfo.GetErrorMessage(CTInfo.GetLastError); // runs on UI thread
                });
            }
        }