public static void SetSerial(SerialPortEx serial)
        {
            Device = serial;
            Device.DataReceived += SerialDataReceived;

            JavascriptEvent.SerialChange();
        }
Esempio n. 2
0
        private static void Moitor(object sender, ElapsedEventArgs e)
        {
            m_Mutex.WaitOne();
            if (m_Computer.Ports.SerialPortNames.Count != m_PortCount)
            {
                try
                {
                    m_PortCount = m_Computer.Ports.SerialPortNames.Count;

                    JavascriptEvent.PortChange();

                    if (SerialPortManager.Device.IsOpen)
                    {
                        try
                        {
                            bool exist = m_Computer.Ports.SerialPortNames.Contains <string>(SerialPortManager.Device.PortName);
                            if (!exist)
                            {
                                SerialPortManager.Close();
                            }
                        }
                        catch (Exception ex)
                        {
                            Log4Helper.ErrorInfo(ex.Message, ex);
                            JavascriptEvent.ErrorMessage(ex.Message);
                        }
                        finally
                        {
                            JavascriptEvent.SerialChange();
                        }
                    }

                    if (!SerialPortManager.Device.IsOpen)
                    {
                        ConnectionManager.Start();
                    }
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                    JavascriptEvent.ErrorMessage(ex.Message);
                }
            }
            m_Mutex.ReleaseMutex();
        }