Exemplo n.º 1
0
        public static Boolean Initialize()
        {
            try
            {
                if (!m_boolInitialized && !m_boolInitError)
                {
                    PortForm formPort = new PortForm();
                    if (formPort.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            _thinkGearWrapper = new ThinkGearWrapper();
                            _thinkGearWrapper.ThinkGearChanged += _thinkGearWrapper_ThinkGearChanged;
                            if (_thinkGearWrapper.Connect(formPort.SelectedPort, 57600, true))
                            {
                                _thinkGearWrapper.EnableBlinkDetection(true);
                                Algorithm = formPort.Algorithm;
                                Threshold = formPort.Threshold;

                                TCMP  = formPort.TCMP;
                                NZT48 = formPort.NZT48;

                                Arduino      = formPort.Arduino;
                                ArduinoPort  = formPort.ArduinoPort;
                                ArduinoDelay = formPort.ArduinoDelay;
                                ArduinoOn    = formPort.ArduinoOn;
                                ArduinoOff   = formPort.ArduinoOff;

                                m_boolInitialized = true;
                            }
                            else
                            {
                                throw new Exception("Could not connect to port " + formPort.SelectedPort + ".");
                            }
                        }
                        catch (Exception ex)
                        {
                            if (!m_boolInitError)
                            {
                                MessageBox.Show(ex.Message, "LucidScribe.InitializePlugin()", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            m_boolInitError = true;
                        }
                    }
                    else
                    {
                        m_boolInitError = true;
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                m_boolInitError = true;
                throw (new Exception("The 'NeuroSky' plugin failed to initialize: " + ex.Message));
            }
        }
 public static Boolean Initialize()
 {
     try
       {
     if (!m_boolInitialized && !m_boolInitError)
     {
       PortForm formPort = new PortForm();
       if (formPort.ShowDialog() == DialogResult.OK)
       {
     try
     {
       _thinkGearWrapper = new ThinkGearWrapper();
       _thinkGearWrapper.ThinkGearChanged += _thinkGearWrapper_ThinkGearChanged;
       if (_thinkGearWrapper.Connect(formPort.SelectedPort, 57600, true))
       {
         _thinkGearWrapper.EnableBlinkDetection(true);
         Algorithm = formPort.Algorithm;
         Threshold = formPort.Threshold;
         TCMP = formPort.TCMP;
         m_boolInitialized = true;
       }
       else
       {
         throw new Exception("Could not connect to port " + formPort.SelectedPort + ".");
       }
     }
     catch (Exception ex)
     {
       if (!m_boolInitError)
       {
         MessageBox.Show(ex.Message, "LucidScribe.InitializePlugin()", MessageBoxButtons.OK, MessageBoxIcon.Error);
       }
       m_boolInitError = true;
     }
       }
       else
       {
     m_boolInitError = true;
     return false;
       }
     }
     return true;
       }
       catch (Exception ex)
       {
     m_boolInitError = true;
     throw (new Exception("The 'NeuroSky' plugin failed to initialize: " + ex.Message));
       }
 }