示例#1
0
 public static void DetectAllPorts(int baudRate)
 {
     try
     {
         if (!MySerialPortProcess.IfUpdatingFirmware)
         {
             lock (MySerialPortProcess._lock)
             {
                 foreach (System.Collections.Generic.KeyValuePair <string, SerialPort> current in MySerialPortProcess.SerialPortList)
                 {
                     bool flag2 = false;
                     foreach (DevicePort current2 in MySerialPortProcess.DevicePortList)
                     {
                         if (current.Key.Contains(current2.PortName))
                         {
                             flag2 = true;
                             break;
                         }
                     }
                     if (!flag2)
                     {
                         MySerialPortProcess.DetectPortForTimes(current.Key, baudRate, current.Value);
                     }
                 }
             }
         }
     }
     catch (System.Exception e)
     {
         ErrorXMLProcess.ExceptionProcess(e);
     }
 }
示例#2
0
        public int GetRev2IndexByOrder(HardwareStructure.MyComputer data, int orderTh)
        {
            int num = -1;
            int result;

            try
            {
                int num2 = 1;
                if (data.get_GridFanHub() != null)
                {
                    for (int i = 0; i < data.get_GridFanHub().Length; i++)
                    {
                        if (data.get_GridFanHub()[i].get_Name().Contains("GridRev2"))
                        {
                            num = i;
                            if (num2 == orderTh)
                            {
                                result = num;
                                return(result);
                            }
                            num2++;
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                ErrorXMLProcess.ExceptionProcess(e);
            }
            result = num;
            return(result);
        }
示例#3
0
 public static void InitialDetectPort()
 {
     try
     {
         MySerialPortProcess.PreviDevicePortList.Clear();
         MySerialPortProcess.DevicePortList.Clear();
         System.Collections.Generic.List <object> portFriendlyName = MySerialPortProcess.GetPortFriendlyName();
         using (System.Collections.Generic.List <object> .Enumerator enumerator = portFriendlyName.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 string text = (string)enumerator.Current;
                 try
                 {
                     string text2 = text;
                     text2 = text2.Substring(text2.IndexOf("(") + 1);
                     text2 = text2.Substring(0, text2.IndexOf(")"));
                     MySerialPortProcess.SerialPortList.Add(text2, new SerialPort(text2, 4800));
                     MySerialPortProcess.SerialPortList[text2].Open();
                     MySerialPortProcess.SerialPortList[text2].DataReceived -= new SerialDataReceivedEventHandler(MySerialPortProcess.SerialPort_DataReceived);
                     MySerialPortProcess.SerialPortList[text2].DataReceived += new SerialDataReceivedEventHandler(MySerialPortProcess.SerialPort_DataReceived);
                 }
                 catch (System.Exception e)
                 {
                     ErrorXMLProcess.ExceptionProcess(e);
                 }
             }
         }
     }
     catch (System.Exception e)
     {
         ErrorXMLProcess.ExceptionProcess(e);
     }
 }
示例#4
0
 public static void OpenSerialPort()
 {
     try
     {
         foreach (System.Collections.Generic.KeyValuePair <string, SerialPort> current in MySerialPortProcess.SerialPortList)
         {
             current.Value.Open();
         }
     }
     catch (System.Exception e)
     {
         ErrorXMLProcess.ExceptionProcess(e);
     }
 }
示例#5
0
        public static void ReadWriteCommand(byte[] commandBytes, DevicePort product, byte[] replyBytes)
        {
            try
            {
                if (!MySerialPortProcess.IfUpdatingFirmware)
                {
                    lock (MySerialPortProcess._lock)
                    {
                        if (product.PortName != null && MySerialPortProcess.CheckSerialPortExist(product))
                        {
                            if (!MySerialPortProcess.SerialPortList[product.PortName].IsOpen)
                            {
                                MySerialPortProcess.SerialPortList[product.PortName].Open();
                            }
                            MySerialPortProcess.SerialPortList[product.PortName].Write(commandBytes, 0, commandBytes.Length);
                            int num = 0;
                            while (true)
                            {
                                num++;
                                System.Threading.Thread.Sleep(10);
                                if (MySerialPortProcess.SerialPortList[product.PortName].BytesToRead > 0)
                                {
                                    break;
                                }
                                if (num > 20)
                                {
                                    goto Block_9;
                                }
                            }
                            System.Threading.Thread.Sleep(50);
Block_9:
                            int bytesToRead = MySerialPortProcess.SerialPortList[product.PortName].BytesToRead;
                            byte[] array = new byte[bytesToRead];
                            MySerialPortProcess.SerialPortList[product.PortName].Read(array, 0, bytesToRead);
                            MySerialPortProcess.CheckReplyValue(array, replyBytes);
                        }
                    }
                }
            }
            catch (System.IO.IOException)
            {
            }
            catch (System.Exception e)
            {
                ErrorXMLProcess.ExceptionProcess(e);
            }
        }
示例#6
0
 private static void DetectPortForTimes(string portStr, int baudRate, SerialPort TheSerialPort)
 {
     try
     {
         byte[] buffer = new byte[]
         {
             192
         };
         TheSerialPort.BaudRate = baudRate;
         TheSerialPort.DiscardInBuffer();
         TheSerialPort.DiscardOutBuffer();
         TheSerialPort.Write(buffer, 0, 1);
     }
     catch (System.Exception e)
     {
         ErrorXMLProcess.ExceptionProcess(e);
     }
 }
示例#7
0
 public static void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     try
     {
         SerialPort serialPort  = (SerialPort)sender;
         int        bytesToRead = serialPort.BytesToRead;
         byte[]     array       = new byte[bytesToRead];
         MySerialPortProcess.SerialPortList[serialPort.PortName].Read(array, 0, bytesToRead);
         if (array.Length == 1)
         {
             MySerialPortProcess.AddProductToList(array, MySerialPortProcess.SerialPortList[serialPort.PortName]);
         }
     }
     catch (System.Exception e2)
     {
         ErrorXMLProcess.ExceptionProcess(e2);
     }
 }
示例#8
0
 public static System.Collections.Generic.List <object> GetPortFriendlyName()
 {
     System.Collections.Generic.List <object> result = null;
     try
     {
         using (ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM WIN32_SerialPort"))
         {
             string[] portNames = SerialPort.GetPortNames();
             System.Collections.Generic.List <ManagementBaseObject> list = managementObjectSearcher.Get().Cast <ManagementBaseObject>().ToList <ManagementBaseObject>();
             list   = list.FindAll((ManagementBaseObject x) => x["PNPDeviceID"].ToString().Contains("VID_04D8&PID_00DF&MI_00")).ToList <ManagementBaseObject>();
             result = (from n in portNames
                       join p in list on n equals p["DeviceID"].ToString()
                       select p["Caption"]).ToList <object>();
         }
     }
     catch (System.Exception e)
     {
         ErrorXMLProcess.ExceptionProcess(e);
     }
     return(result);
 }
示例#9
0
        private static bool CheckSerialPortExist(DevicePort product)
        {
            bool result;

            try
            {
                foreach (string current in MySerialPortProcess.SerialPortList.Keys)
                {
                    if (current == product.PortName)
                    {
                        result = true;
                        return(result);
                    }
                }
                result = false;
            }
            catch (System.Exception e)
            {
                ErrorXMLProcess.ExceptionProcess(e);
                result = false;
            }
            return(result);
        }
示例#10
0
 private static void AddProductToList(byte[] receiveBytes, SerialPort TheSerialPort)
 {
     try
     {
         foreach (int current in MySerialPortProcess.DeviceDictionary.Keys)
         {
             if ((int)receiveBytes[0] == current)
             {
                 MySerialPortProcess.DevicePortList.Add(new DevicePort
                 {
                     Device   = MySerialPortProcess.DeviceDictionary[current],
                     PortName = TheSerialPort.PortName,
                     BaudRate = TheSerialPort.BaudRate
                 });
                 MySerialPortProcess.WaitingCount++;
                 MySerialPortProcess.SerialPortList[TheSerialPort.PortName].DataReceived -= new SerialDataReceivedEventHandler(MySerialPortProcess.SerialPort_DataReceived);
             }
         }
     }
     catch (System.Exception e)
     {
         ErrorXMLProcess.ExceptionProcess(e);
     }
 }
示例#11
0
 private static void CheckReplyValue(byte[] receiveBytes, byte[] replyBytes)
 {
     try
     {
         if (receiveBytes.Length == 5)
         {
             if (receiveBytes[0] / 64 == 3)
             {
                 for (int i = 0; i < receiveBytes.Length; i++)
                 {
                     replyBytes[i] = receiveBytes[i];
                 }
             }
         }
         else if (receiveBytes.Length == 1)
         {
             replyBytes[0] = receiveBytes[0];
         }
     }
     catch (System.Exception e)
     {
         ErrorXMLProcess.ExceptionProcess(e);
     }
 }
示例#12
0
 public static void SetAudioNewHueBytes(byte[] bytes, byte commandType, byte componentNum, byte modeType, byte dir, byte sw, byte group, byte colorTh, byte ledea, byte speed, byte[] g, byte[] r, byte[] b)
 {
     try
     {
         bytes[0] = commandType;
         bytes[1] = componentNum;
         bytes[2] = modeType;
         bytes[3] = dir * 16 + sw * 8 + group;
         bytes[4] = colorTh * 32 + ledea * 8 + speed;
         int   num   = 0;
         int[] array = new int[120];
         for (int i = 0; i < 40; i++)
         {
             array[3 * i]     = (int)g[num];
             array[3 * i + 1] = (int)r[num];
             array[3 * i + 2] = (int)b[num];
             num++;
         }
         num = 0;
         for (int i = 0; i < 60; i++)
         {
             string text  = System.Convert.ToString(array[2 * num], 2).PadLeft(8, '0');
             string text2 = System.Convert.ToString(array[2 * num + 1], 2).PadLeft(8, '0');
             num++;
             text  = text.Remove(4, 4);
             text2 = text2.Remove(4, 4);
             string value = text + text2;
             int    num2  = System.Convert.ToInt32(value, 2);
             bytes[i + 5] = (byte)num2;
         }
     }
     catch (System.Exception e)
     {
         ErrorXMLProcess.ExceptionProcess(e);
     }
 }
示例#13
0
 public void SetAllGridRev2ChannelFanSpeedFromMode(ref HardwareStructure.MyComputer data, System.Collections.Generic.List <GridXMLOverview> GridSettingsList)
 {
     try
     {
         if (data != null && data.get_CPUs() != null && data.get_CPUs()[0].get_Temperature() != 0.0)
         {
             double num = 0.0;
             for (int i = 0; i < data.get_CPUs().Length; i++)
             {
                 num += data.get_CPUs()[i].get_Temperature();
             }
             num /= (double)data.get_CPUs().Length;
             double num2 = 0.0;
             int    num3 = 0;
             if (data.get_GPUs() != null && data.get_GPUs().Length > 0)
             {
                 for (int i = 0; i < data.get_GPUs().Length; i++)
                 {
                     if (data.get_GPUs()[i].get_Temperature() != -1.0 || data.get_GPUs()[i].get_Temperature() != 0.0)
                     {
                         num2 += data.get_GPUs()[i].get_Temperature();
                         num3++;
                     }
                 }
             }
             num2 /= (double)((num3 > 0) ? num3 : 1);
             for (int j = 0; j < data.get_GridFanHub().Length; j++)
             {
                 if (data.get_GridFanHub()[j].get_Name().Contains("GridRev2"))
                 {
                     for (int i = 1; i < 7; i++)
                     {
                         double num4 = num;
                         if (GridSettingsList[j].ChannelSpeedChangeWith[i - 1] == "GPU")
                         {
                             bool flag = true;
                             if (data == null || data.get_GPUs() == null || data.get_GPUs().Length == 0 || num2 == 0.0)
                             {
                                 flag = false;
                             }
                             if (flag)
                             {
                                 num4 = num2;
                             }
                         }
                         if (num4 >= 100.0)
                         {
                             data.get_GridFanHub()[j].get_SetFanSpeedPercentOfChannel()[i] = 100;
                         }
                         else if (GridSettingsList[j].ChannelModeIndex[i - 1] == 0)
                         {
                             if (GridSettingsList[j].NameAndPort.Contains("GridRev2"))
                             {
                                 data.get_GridFanHub()[j].get_SetFanSpeedPercentOfChannel()[i] = GridSettingsList[j].V2ManualRPMValue[i - 1];
                             }
                             else
                             {
                                 data.get_GridFanHub()[j].get_SetFanSpeedPercentOfChannel()[i] = GridSettingsList[j].ManualRPMValue;
                             }
                         }
                         else if (GridSettingsList[j].ChannelModeIndex[i - 1] == 1)
                         {
                             data.get_GridFanHub()[j].get_SetFanSpeedPercentOfChannel()[i] = Common.CalculateSlopeValue(num4, ConstStrings.GridSilentSpeedLevels);
                         }
                         else if (GridSettingsList[j].ChannelModeIndex[i - 1] == 2)
                         {
                             data.get_GridFanHub()[j].get_SetFanSpeedPercentOfChannel()[i] = Common.CalculateSlopeValue(num4, ConstStrings.GridPerformanceSpeedLevels);
                         }
                         else if (GridSettingsList[j].ChannelModeIndex[i - 1] - 3 < GridSettingsList[j].V2CustomMode.Count)
                         {
                             data.get_GridFanHub()[j].get_SetFanSpeedPercentOfChannel()[i] = Common.CalculateSlopeValue(num4, GridSettingsList[j].V2CustomMode[GridSettingsList[j].ChannelModeIndex[i - 1] - 3].SpeedTempCurve);
                         }
                         else
                         {
                             data.get_GridFanHub()[j].get_SetFanSpeedPercentOfChannel()[i] = Common.CalculateSlopeValue(num4, ConstStrings.GridPerformanceSpeedLevels);
                         }
                     }
                 }
             }
         }
     }
     catch (System.Exception e)
     {
         ErrorXMLProcess.ExceptionProcess(e);
     }
 }