private void EnableStreamingButton(Bitalino device)
        {
            if (device != null)
            {
                startStreamingButton.IsEnabled = true;

                // It is important to disable these options once the bitalino is connected.
                idTextBox.IsReadOnly          = true;
                ECGCheck.IsEnabled            = false;
                EDACheck.IsEnabled            = false;
                RespCheck.IsEnabled           = false;
                EMGCheck.IsEnabled            = false;
                EGGCheck.IsEnabled            = false;
                SamplingRateListBox.IsEnabled = false;
            }
            else
            {
                startStreamingButton.IsEnabled = false;
                idTextBox.IsReadOnly           = false;
                ECGCheck.IsEnabled             = true;
                EDACheck.IsEnabled             = true;
                RespCheck.IsEnabled            = true;
                EMGCheck.IsEnabled             = true;
                EGGCheck.IsEnabled             = true;
                SamplingRateListBox.IsEnabled  = true;
            }
        }
        private void connectLSL()
        {
            // Connect user selected device if not device is currently connected
            if (BlinoDeviceList.SelectedValue != null && connected_device == null && lslChannelCount > 0)
            {
                macAddress = BlinoDeviceList.SelectedValue.ToString().Split('-')[0];

                infoOutputBox.Text = "Connecting to Device ... " + macAddress;

                connected_device = new Bitalino(macAddress);

                infoOutputBox.Text = "Device " + macAddress + " Sucessfully Connected.";

                LinkLabStreamingLayer();                 // Link to Lab Streaming Layer
            }
            // If a device is already connected warn the user.
            else if (connected_device != null)
            {
                infoOutputBox.Text = "Existing Device (" + macAddress + ") Already Connected";
            }
            else if (lslChannelCount == 0)
            {
                infoOutputBox.Text = "Error! Atleast one stream must be selected in order to start streaming.";
            }
        }
        static void Main(string[] args)
        {
            try
            {
                // uncomment this block to search for Bluetooth devices

                /*
                 * Bitalino.DevInfo[] devs = Bitalino.find();
                 * foreach (Bitalino.DevInfo d in devs)
                 * Console.WriteLine("{0} - {1}", d.macAddr, d.name);
                 * return;
                 */

                Console.WriteLine("Connecting to device...");

                Bitalino dev = new Bitalino("20:15:05:29:22:23");  // device MAC address
                                                                   //Bitalino dev = new Bitalino("COM7");  // Bluetooth virtual COM port or USB-UART COM port

                Console.WriteLine("Connected to device. Press Enter to exit.");

                string ver = dev.version();    // get device version string
                Console.WriteLine("BITalino version: {0}", ver);

                dev.battery(10);                                 // set battery threshold (optional)

                dev.start(1000, new int[] { 0, 1, 2, 3, 4, 5 }); // start acquisition of all channels at 1000 Hz

                bool ledState = false;

                Bitalino.Frame[] frames = new Bitalino.Frame[100];
                for (int i = 0; i < frames.Length; i++)
                {
                    frames[i] = new Bitalino.Frame();   // must initialize all elements in the array
                }
                do
                {
                    ledState = !ledState;   // toggle LED state
                    dev.trigger(new bool[] { false, false, ledState, false });

                    dev.read(frames);                                                     // get 100 frames from device
                    Bitalino.Frame f = frames[0];                                         // get a reference to the first frame of each 100 frames block
                    Console.WriteLine("{0} : {1} {2} {3} {4} ; {5} {6} {7} {8} {9} {10}", // dump the first frame
                                      f.seq,
                                      f.digital[0], f.digital[1], f.digital[2], f.digital[3],
                                      f.analog[0], f.analog[1], f.analog[2], f.analog[3], f.analog[4], f.analog[5]);
                } while (!Console.KeyAvailable); // until a key is pressed


                dev.stop();    // stop acquisition

                dev.Dispose(); // disconnect from device
            }
            catch (Bitalino.Exception e)
            {
                Console.WriteLine("BITalino exception: {0}", e.Message);
                Console.ReadLine();
            }
        }
Example #4
0
        public event EventDataDeviceHandler NewData;//evento
        public async Task ReadDevice()
        {
            await Task.Run(() => {
                try
                {
                    // uncomment this block to search for Bluetooth devices

                    Console.WriteLine("A conectar ao dispositivo...");

                    Bitalino dev = new Bitalino("20:16:04:12:01:94");  // device MAC address
                                                                       //Bitalino dev = new Bitalino("COM7");

                    Console.WriteLine("Dispositivo conectado. Pressione Enter para sair.");

                    string ver = dev.version();    // get device version string
                    Console.WriteLine("Bitalino versão: {0}", ver);

                    dev.battery(10);                 // set battery threshold (optional)

                    dev.start(100, new int[] { 0 }); // start acquisition of all channels at 1000 Hz
                    // NECESSARIO ESCOLHER O CANAL
                    bool ledState = false;

                    Bitalino.Frame[] frames = new Bitalino.Frame[100];
                    for (int i = 0; i < frames.Length; i++)
                    {
                        frames[i] = new Bitalino.Frame();   // must initialize all elements in the array
                    }
                    connected = true;
                    do
                    {
                        ledState = !ledState;   // toggle LED state
                        dev.trigger(new bool[] { false, false, ledState, false });

                        dev.read(frames);             // get 100 frames from device
                        Bitalino.Frame f = frames[0]; // get a reference to the first frame of each 100 frames block
                        String dataStr   = String.Format("{0} ", f.analog[0]);

                        Console.WriteLine(dataStr);

                        EventDataDeviceHandler handler = NewData;
                        if (handler != null)
                        {
                            NewData(dataStr);
                        }
                    }while (connected); // until a key is pressed

                    dev.stop();         // stop acquisition

                    dev.Dispose();      // disconnect from device*/
                }
                catch (Bitalino.Exception e)
                {
                    Console.WriteLine("Bitalino Excepção: {0}", e.Message);
                }
            });
        }
 public async Task SearchDevices()
 {
     await Task.Run(() => {
         Bitalino.DevInfo[] devs          = Bitalino.find();
         EventSearchDeviceHandler handler = EnconteredDevices;
         if (handler != null)
         {
             handler(devs);
         }
     });
 }
        // Backgroundworker events
        private void bw_scannbluetooth_DoWork(object sender, DoWorkEventArgs e)
        {
            // search for bluetooth devices
            Bitalino.DevInfo[] BTLdevice = Bitalino.find();

            // add all found bloutooth devices to combobox
            foreach (Bitalino.DevInfo d in BTLdevice)
            {
                IDList.Add(d.macAddr);
                names.Add(d.name);
            }
        }
Example #7
0
        public event EventSearchDeviceHandler EncontrarDispositivos;//evento

        public async Task SearchDevices()
        {
            await Task.Run(() => {
                Bitalino.DevInfo[] devs          = Bitalino.find();
                EventSearchDeviceHandler handler = EncontrarDispositivos;
                if (handler != null)
                {
                    handler(devs);
                }
            });//o metodo devolve uma tarefa, como é um async task vai estar dentro do 'await'

            // os '()' são uma função e o que está dentro dos '{}' é a solução(call back) dessa função
        }
        private void ShowDevices()
        {
            Bitalino.DevInfo[] devices = Bitalino.find();

            foreach (Bitalino.DevInfo d in devices)
            {
                string[] nameCheck = d.name.Split('-');

                if (nameCheck.Length > 0 && nameCheck[0] == "BITalino")
                {
                    BlinoDeviceList.Items.Add(d.macAddr + "-" + d.name);
                }
            }
        }
        // this method gets fired when verbinden button of SBW window gets clicked
        private void SearchBluetoothWindow_SubmitClicked(object sender, EventArgs e)
        {
            try
            {
                Bitalino dev = new Bitalino(SBW.ID);  // device MAC address

                // set information labels on UI
                label_BitalinoName2.Content    = SBW.name;
                label_BitalinoName2.Foreground = Brushes.LightGreen;
                label_BitalinoID2.Content      = SBW.ID;
                label_BitalinoID2.Foreground   = Brushes.LightGreen;
            }
            catch (Bitalino.Exception p)
            {
                MessageBox.Show("Verbindung fehlgeschlagen", "Achtung!", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void StreamData(Bitalino dev, liblsl.StreamOutlet lslout, bool ecg, bool eda, bool resp, bool emg, bool egg)
        {
            // Simpler this way. By Default lets just open all channels we assume will be open.
            dev.start(sampling_rate, new int[] { 0, 1, 2, 3, 4 });

            // Data Structure used for Streaming Data
            short[,] sample = new short[100, lslChannelCount]; // Initialize Sample to the number of available Channels and chunked samples we want to send.

            Bitalino.Frame[] frames = new Bitalino.Frame[100];
            for (int i = 0; i < frames.Length; i++)
            {
                frames[i] = new Bitalino.Frame(); // must initialize all elements in the array
            }
            while (MainWindow.IS_STREAMING)
            {
                double start_clock = liblsl.local_clock(); // Record local clock before chunk processing

                dev.read(frames);
                string s = "";

                for (int i = 0; i < frames.Length; i++)
                {
                    int auxSampleIndexer = 0; // This variable helps manage the sample array for the various channels that are currently being used.

                    // Manage the ECG Values
                    if (ecg)
                    {
                        //s += frames[i].analog[0];
                        //s += " ";
                        sample[i, auxSampleIndexer] = frames[i].analog[0];

                        auxSampleIndexer += 1;
                    }

                    // Manage the EDA Values
                    if (eda)
                    {
                        //s += frames[i].analog[1];
                        //s += " ";
                        sample[i, auxSampleIndexer] = frames[i].analog[1];

                        auxSampleIndexer += 1;
                    }

                    // Manage the Respiration Values
                    if (resp)
                    {
                        //s += frames[i].analog[2];
                        //s += " ";
                        sample[i, auxSampleIndexer] = frames[i].analog[2];

                        auxSampleIndexer += 1;
                    }

                    if (emg)
                    {
                        sample[i, auxSampleIndexer] = frames[i].analog[3];
                        auxSampleIndexer           += 1;
                    }

                    if (egg)
                    {
                        sample[i, auxSampleIndexer] = frames[i].analog[4];
                        auxSampleIndexer           += 1;
                    }
                }

                s += "  LENGTH = " + frames.Length;

                // Delegate the Output Values to the Streaming Text Box
                streamingOutputBox.Dispatcher.Invoke(
                    new UpdateStreamBoxCallback(this.AppendStreamTextBox),
                    new object[] { "Receiving Data: " + s });

                double end_clock = liblsl.local_clock();                    // Record local clock after chunk processing

                lslout.push_chunk(sample, (end_clock + start_clock) / 2.0); // Push the chunk through LabStream Layer using the average time between start and end
            }
            dev.stop();
            streamingOutputBox.Dispatcher.Invoke(
                new UpdateStreamBoxCallback(this.AppendStreamTextBox),
                new object[] { "Thread Successfully Closed" });
        }
        public async Task ReadDevice()
        {
            await Task.Run(() => {
                try
                {
                    Console.WriteLine("Connecting to device...");

                    Bitalino dev = new Bitalino(device.macAddr);  // device MAC address
                    //Bitalino dev = new Bitalino("COM7");  // Bluetooth virtual COM port or USB-UART COM port
                    Console.WriteLine("Connected to device. Press Enter to exit.");

                    string ver = dev.version();    // get device version string
                    Console.WriteLine("BITalino version: {0}", ver);

                    dev.battery(10);                 // set battery threshold (optional)

                    dev.start(100, new int[] { 1 }); // start acquisition of all channels at 1000 Hz

                    bool ledState = false;

                    Bitalino.Frame[] frames = new Bitalino.Frame[100];
                    for (int i = 0; i < frames.Length; i++)
                    {
                        frames[i] = new Bitalino.Frame();   // must initialize all elements in the array
                    }
                    connected = true;

                    do
                    {
                        ledState = !ledState;   // toggle LED state
                        dev.trigger(new bool[] { false, false, ledState, false });

                        dev.read(frames); // get 100 frames from device
                        for (int j = 0; j < 100; j++)
                        {
                            Bitalino.Frame f = frames[j];  // get a reference to the first frame of each 100 frames block



                            String dataStr = String.Format("{0}",   // dump the first frame

                                                           f.analog[0]);

                            Console.WriteLine(dataStr);


                            EventDataDeviceHandler handle = NewData;
                            if (handle != null)
                            {
                                NewData(dataStr);
                            }
                        }
                    } while (connected); // until a key is pressed

                    dev.stop();          // stop acquisition

                    dev.Dispose();       // disconnect from device
                }
                catch (Bitalino.Exception e)
                {
                    Console.WriteLine("BITalino exception: {0}", e.Message);
                }
            });
        }
Example #12
0
        public async Task ReadDevice()
        {
            await Task.Run(() => {
                try
                {
                    //Console.WriteLine("Connecting to device...");

                    Bitalino dev = new Bitalino(device.macAddr);  // device MAC address
                                                                  //Bitalino dev = new Bitalino("COM7");  // Bluetooth virtual COM port or USB-UART COM port

                    //Console.WriteLine("Connected to device. Press Enter to exit.");

                    string ver = dev.version();    // get device version string
                    //Console.WriteLine("BITalino version: {0}", ver);

                    dev.battery(10);                  // set battery threshold (optional)

                    dev.start(1000, new int[] { 1 }); // start acquisition of all channels at 1000 Hz { 0, 1, 2, 3, 4, 5 } // por canal 1

                    bool ledState = false;

                    Bitalino.Frame[] frames = new Bitalino.Frame[100];
                    for (int i = 0; i < frames.Length; i++)
                    {
                        frames[i] = new Bitalino.Frame();   // must initialize all elements in the array
                    }
                    connected = true;

                    do
                    {
                        ledState = !ledState;   // toggle LED state
                        dev.trigger(new bool[] { false, false, ledState, false });

                        dev.read(frames);             // get 100 frames from device

                        Bitalino.Frame f = frames[0]; // get a reference to the first frame of each 100 frames block dentro do f estao os valores que quero adquirir

                        /*
                         * String dataStr = String.Format("{0} : {1} {2} {3} {4} ; {5} {6} {7} {8} {9} {10}",   // dump the first frame
                         *                 f.seq,
                         *                 f.digital[0], f.digital[1], f.digital[2], f.digital[3],
                         *                 f.analog[0], f.analog[1], f.analog[2], f.analog[3], f.analog[4], f.analog[5]); //valores dos canais
                         *
                         * Console.WriteLine(dataStr);
                         */
                        EventDataDeviceHandler handle = NewData;
                        if (handle != null)
                        {
                            NewData(f.analog[1]);
                        }
                    } while (connected); // until a key is pressed

                    dev.stop();          // stop acquisition

                    dev.Dispose();       // disconnect from device
                }
                catch (Bitalino.Exception e)
                {
                    Console.WriteLine("BITalino exception: {0}", e.Message);
                }
            });
        }