Exemple #1
0
 public static void Initialize()
 {
     MySerialPortProcess.AddDeviceNumberToDictionary(31, "Grid");
     MySerialPortProcess.AddDeviceNumberToDictionary(32, "GridRevA");
     MySerialPortProcess.AddDeviceNumberToDictionary(33, "GridRev2");
     MySerialPortProcess.AddDeviceNumberToDictionary(1, "HuePlus");
 }
Exemple #2
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);
     }
 }
Exemple #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);
     }
 }
Exemple #4
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);
            }
        }
Exemple #5
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);
     }
 }