static public void SearchDevice()
        {
            if (Manager == null)
            {
                Manager = new wclBluetoothManager();

                //Manager.OnNumericComparison += new wclBluetoothNumericComparisonEvent(Manager_OnNumericComparison);
                //Manager.OnPasskeyNotification += new wclBluetoothPasskeyNotificationEvent(Manager_OnPasskeyNotification);
                //Manager.OnPasskeyRequest += new wclBluetoothPasskeyRequestEvent(Manager_OnPasskeyRequest);
                //Manager.OnPinRequest += new wclBluetoothPinRequestEvent(Manager_OnPinRequest);
                Manager.OnDeviceFound          += new wclBluetoothDeviceEvent(Manager_OnDeviceFound);
                Manager.OnDiscoveringCompleted += new wclBluetoothResultEvent(Manager_OnDiscoveringCompleted);
                //Manager.OnDiscoveringStarted += new wclBluetoothEvent(Manager_OnDiscoveringStarted);

                Manager.Open();

                Radio = GetRadio();
            }

            if (Radio != null)
            {
                Int32 Res = Radio.Discover(3, wclBluetoothDiscoverKind.dkBle);
                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    CSLibrary.Debug.WriteLine("Error starting discovering: 0x" + Res.ToString("X8"));
                }
            }
        }
        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            _client.Disconnect();
            _client = null;

            _manager.Close();
            _manager = null;

            Cleanup();
        }
Exemple #3
0
        private void fmMain_Load(object sender, EventArgs e)
        {
            FManager              = new wclBluetoothManager();
            FManager.AfterOpen   += FManager_AfterOpen;
            FManager.BeforeClose += FManager_BeforeClose;

            FClient = new wclGattClient();
            FClient.ConnectOnRead = true;
            FClient.OnConnect    += FClient_OnConnect;
            FClient.OnDisconnect += FClient_OnDisconnect;
        }
Exemple #4
0
        private void FmMain_Load(Object Sender, EventArgs e)
        {
            FManager = new wclBluetoothManager();

            FWatcher                   = new wclWeDoWatcher();
            FWatcher.OnHubFound       += FWatcher_OnHubFound;
            FWatcher.OnHubNameChanged += FWatcher_OnHubNameChanged;
            FWatcher.OnStarted        += FWatcher_OnStarted;
            FWatcher.OnStopped        += FWatcher_OnStopped;

            FHubs = new List <wclWeDoHub>();
        }
Exemple #5
0
 public string ConnectBLE(string portName)
 {
     Manager = new wclBluetoothManager();
     Manager.OnDeviceFound          += new wclBluetoothDeviceEvent(Manager_OnDeviceFound);
     Manager.OnDiscoveringCompleted += new wclBluetoothResultEvent(Manager_OnDiscoveringCompleted);
     Manager.OnDiscoveringStarted   += new wclBluetoothEvent(Manager_OnDiscoveringStarted);
     Client               = new wclGattClient();
     Client.OnConnect    += Client_OnConnect;
     Client.OnDisconnect += Client_OnDisconnect;
     Manager.Open();
     Radio = GetRadio();
     return(Radio != null ? portName : null);
 }
Exemple #6
0
        private void fmMain_Load(object sender, EventArgs e)
        {
            FManager = new wclBluetoothManager();

            FWatcher             = new wclWeDoWatcher();
            FWatcher.OnHubFound += FWatcher_OnHubFound;

            FHub                   = new wclWeDoHub();
            FHub.OnConnected      += FHub_OnConnected;
            FHub.OnDisconnected   += FHub_OnDisconnected;
            FHub.OnDeviceAttached += FHub_OnDeviceAttached;
            FHub.OnDeviceDetached += FHub_OnDeviceDetached;

            FColor = null;
            FRgb   = null;
        }
        private void fmMain_Load(object sender, EventArgs e)
        {
            FDevices = null;

            FManager                         = new wclBluetoothManager();
            FManager.AfterOpen              += new EventHandler(FManager_AfterOpen);
            FManager.BeforeClose            += new EventHandler(FManager_BeforeClose);
            FManager.OnDiscoveringStarted   += new wclBluetoothEvent(FManager_OnDiscoveringStarted);
            FManager.OnDeviceFound          += new wclBluetoothDeviceEvent(FManager_OnDeviceFound);
            FManager.OnDiscoveringCompleted += new wclBluetoothResultEvent(FManager_OnDiscoveringCompleted);

            FClient = new wclGattClient();
            FClient.OnDisconnect            += new wclCommunication.wclClientConnectionDisconnectEvent(FClient_OnDisconnect);
            FClient.OnConnect               += new wclCommunication.wclClientConnectionConnectEvent(FClient_OnConnect);
            FClient.OnCharacteristicChanged += new wclGattCharacteristicChangedEvent(FClient_OnCharacteristicChanged);
        }
Exemple #8
0
        private void FmMain_Load(Object Sender, EventArgs e)
        {
            cbMode.SelectedIndex = 0;

            FManager = new wclBluetoothManager();

            FWatcher             = new wclWeDoWatcher();
            FWatcher.OnHubFound += FWatcher_OnHubFound;

            FHub                   = new wclWeDoHub();
            FHub.OnConnected      += FHub_OnConnected;
            FHub.OnDisconnected   += FHub_OnDisconnected;
            FHub.OnDeviceAttached += FHub_OnDeviceAttached;
            FHub.OnDeviceDetached += FHub_OnDeviceDetached;

            FTilt = null;
        }
Exemple #9
0
        /// <summary> Creates new instance of the WeDo Robot class. </summary>
        public wclWeDoRobot()
        {
            FHubs    = new Dictionary <Int64, wclWeDoHub>();
            FManager = new wclBluetoothManager();
            FRadio   = null;
            FWatcher = new wclWeDoWatcher();

            FWatcher.OnHubFound += WatcherHubFound;
            FWatcher.OnStarted  += WatcherStarted;
            FWatcher.OnStopped  += WatcherStopped;

            OnHubConnected    = null;
            OnHubDisconnected = null;
            OnHubFound        = null;
            OnStarted         = null;
            OnStopped         = null;
        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            _manager = new wclBluetoothManager();
            _client  = new wclGattClient();

            _manager.OnDeviceFound          += Manager_OnDeviceFound;
            _manager.OnDiscoveringCompleted += Manager_OnDiscoveringCompleted;
            _manager.OnDiscoveringStarted   += Manager_OnDiscoveringStarted;

            _client.OnCharacteristicChanged += Client_OnCharacteristicChanged;
            _client.OnConnect    += Client_OnConnect;
            _client.OnDisconnect += Client_OnDisconnect;

            // In real application you should always analize the result code.
            // In this demo we assume that all is always OK.
            _manager.Open();

            Cleanup();
        }
Exemple #11
0
        private void FmMain_Load(Object sender, EventArgs e)
        {
            // Create Bluetooth Manager. We do not need any events from it so simple
            // create the object.
            FManager = new wclBluetoothManager();

            // Now create WeDo Watcher. We need some events from it so also assign event
            // handler.
            FWatcher = new wclWeDoWatcher();
            // The event fires when we started scanning.
            FWatcher.OnStarted += FWatcher_OnStarted;
            // The event fires when we stopped scanning.
            FWatcher.OnStopped += FWatcher_OnStopped;
            // The event fires when new WeDo Hub found.
            FWatcher.OnHubFound += FWatcher_OnHubFound;
            // The event fires when WeDo hub lost.
            FWatcher.OnHubLost += FWatcher_OnHubLost;
            // The event fires when WeDo Hub name changed.
            FWatcher.OnHubNameChanged += FWatcher_OnHubNameChanged;
        }
Exemple #12
0
        private void FmMain_Load(Object sender, EventArgs e)
        {
            cbDirection1.SelectedIndex = 0;
            cbDirection2.SelectedIndex = 0;

            FManager = new wclBluetoothManager();

            FWatcher             = new wclWeDoWatcher();
            FWatcher.OnHubFound += FWatcher_OnHubFound;

            FHub                     = new wclWeDoHub();
            FHub.OnConnected        += FHub_OnConnected;
            FHub.OnDisconnected     += FHub_OnDisconnected;
            FHub.OnDeviceAttached   += FHub_OnDeviceAttached;
            FHub.OnDeviceDetached   += FHub_OnDeviceDetached;
            FHub.OnHighCurrentAlert += FHub_OnHighCurrentAlert;
            FHub.OnLowVoltageAlert  += FHub_OnLowVoltageAlert;

            FMotor1  = null;
            FMotor2  = null;
            FCurrent = null;
            FVoltage = null;
        }
Exemple #13
0
        /**
         * <summary>When the Simple_Form loads</summary>
         * <param name="sender">Object on which the change happened</param>
         * <param name="e">Additional information about the event</param>
         */
        private void Simple_Form_Load(object sender, EventArgs e)
        {
            lineTracker = new LineTracker(this);
            Manager     = new wclBluetoothManager();
            Watcher     = new wclWeDoWatcher();
            listBox1.Items.Add("Please connect one of the hubs.");

            Watcher.OnHubFound += Watcher_OnHubFound;

            int res = Manager.Open();

            if (res != wclErrors.WCL_E_SUCCESS)
            {
                MessageBox.Show("Error opening the Manager.");
            }
            else
            {
                wclBluetoothRadio radio = null;
                for (int i = 0; i < Manager.Count; i++)
                {
                    if (Manager[i].Available)
                    {
                        radio = Manager[i];
                        break;
                    }
                }
                if (radio != null)
                {
                    res = Watcher.Start(radio);
                    if (res != wclErrors.WCL_E_SUCCESS)
                    {
                        MessageBox.Show("Can't start watching.");
                    }
                }
            }
        }