Beispiel #1
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.SYNTHETIC_BOARD;

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            BoardShim.log_message((int)LogLevels.LEVEL_INFO, "Start sleeping in the main thread");
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            Console.WriteLine("data count: {0}", board_shim.get_board_data_count());
            double[,] unprocessed_data = board_shim.get_current_board_data(20);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            board_shim.release_session();

            for (int i = 0; i < eeg_channels.Length; i++)
            {
                Console.WriteLine("Before processing:");
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(eeg_channels[i])));
                // you can use MEAN, MEDIAN or EACH for downsampling
                double[] filtered = DataFilter.perform_downsampling(unprocessed_data.GetRow(eeg_channels[i]), 3, (int)AggOperations.MEDIAN);
                Console.WriteLine("Before processing:");
                Console.WriteLine("[{0}]", string.Join(", ", filtered));
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id      = (int)BoardIds.SYNTHETIC_BOARD;
            int sampling_rate = BoardShim.get_sampling_rate(board_id);
            int nfft          = DataFilter.get_nearest_power_of_two(sampling_rate);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(10000);
            board_shim.stop_stream();
            double[,] data = board_shim.get_board_data();
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            // use second channel of synthetic board to see 'alpha'
            int channel = eeg_channels[1];

            board_shim.release_session();
            double[] detrend = DataFilter.detrend(data.GetRow(channel), (int)DetrendOperations.LINEAR);
            Tuple <double[], double[]> psd = DataFilter.get_psd_welch(detrend, nfft, nfft / 2, sampling_rate, (int)WindowFunctions.HANNING);
            double band_power_alpha        = DataFilter.get_band_power(psd, 7.0, 13.0);
            double band_power_beta         = DataFilter.get_band_power(psd, 14.0, 30.0);

            Console.WriteLine("Alpha/Beta Ratio:" + (band_power_alpha / band_power_beta));
        }
Beispiel #3
0
    // Start is called before the first frame update

    void Start()
    {
        try
        {
            BoardShim.enable_dev_board_logger();

            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.MINDROVE_BLUETOOTH_BOARD;//= parse_args(args, input_params);

            board_shim = new BoardShim(board_id, input_params);
            board_shim.prepare_session();

            board_shim.start_stream(); // use this for default options
                                       //board_shim.start_stream(450000, "file://file_stream.csv:w");

            BrainFlowModelParams concentration_params = new BrainFlowModelParams((int)BrainFlowMetrics.CONCENTRATION, (int)BrainFlowClassifiers.REGRESSION);
            concentration = new MLModel(concentration_params);
            concentration.prepare();
            sampling_rate = 250;//BoardShim.get_sampling_rate(board_id);
            eeg_channels  = BoardShim.get_eeg_channels(board_id);
        }
        catch (BrainFlowException ex)
        {
            Debug.Log(ex);
        }
    }
Beispiel #4
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int       board_id      = parse_args(args, input_params);
            BoardShim board_shim    = new BoardShim(board_id, input_params);
            int       sampling_rate = BoardShim.get_sampling_rate(board_shim.get_board_id());
            int       nfft          = DataFilter.get_nearest_power_of_two(sampling_rate);

            int[] eeg_channels = BoardShim.get_eeg_channels(board_shim.get_board_id());

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(10000);
            board_shim.stop_stream();
            double[,] data = board_shim.get_board_data();
            board_shim.release_session();

            Tuple <double[], double[]> bands = DataFilter.get_avg_band_powers(data, eeg_channels, sampling_rate, true);

            double[]             feature_vector = bands.Item1.Concatenate(bands.Item2);
            BrainFlowModelParams model_params   = new BrainFlowModelParams((int)BrainFlowMetrics.CONCENTRATION, (int)BrainFlowClassifiers.REGRESSION);
            MLModel concentration = new MLModel(model_params);

            concentration.prepare();
            Console.WriteLine("Concentration: " + concentration.predict(feature_vector));
            concentration.release();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.SYNTHETIC_BOARD;

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            double[,] unprocessed_data = board_shim.get_current_board_data(20);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            Console.WriteLine("Before serialization:");
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(index)));
            }
            board_shim.release_session();

            // demo for data serialization
            DataFilter.write_file(unprocessed_data, "test.csv", "w");
            double[,] restored_data = DataFilter.read_file("test.csv");
            Console.WriteLine("After Serialization:");
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", restored_data.GetRow(index)));
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id      = (int)BoardIds.SYNTHETIC_BOARD;
            int sampling_rate = BoardShim.get_sampling_rate(board_id);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            double[,] data = board_shim.get_current_board_data(DataFilter.get_nearest_power_of_two(sampling_rate));
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            board_shim.release_session();

            for (int i = 0; i < eeg_channels.Length; i++)
            {
                // optional: you can subtract mean from signal before PSD calculation
                Tuple <double[], double[]> psd = DataFilter.get_psd(data.GetRow(eeg_channels[i]), 0,
                                                                    data.GetRow(eeg_channels[i]).Length, sampling_rate, (int)WindowFunctions.HANNING);
                double band_power_alpha = DataFilter.get_band_power(psd, 7.0, 13.0);
                double band_power_beta  = DataFilter.get_band_power(psd, 14.0, 30.0);
                Console.WriteLine("Alpha/Beta Ratio:" + (band_power_alpha / band_power_beta));
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id      = (int)BoardIds.SYNTHETIC_BOARD;
            int sampling_rate = BoardShim.get_sampling_rate(board_id);
            int nfft          = DataFilter.get_nearest_power_of_two(sampling_rate);

            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(10000);
            board_shim.stop_stream();
            double[,] data = board_shim.get_board_data();
            board_shim.release_session();

            Tuple <double[], double[]> bands = DataFilter.get_avg_band_powers(data, eeg_channels, sampling_rate, true);

            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Avg: " + bands.Item1[i] + " Stddev: " + bands.Item2[i]);
            }
        }
Beispiel #8
0
        static int parse_args(string[] args, BrainFlowInputParams input_params, BrainFlowModelParams model_params)
        {
            int board_id = (int)BoardIds.SYNTHETIC_BOARD; //assume synthetic board by default

            // use docs to get params for your specific board, e.g. set serial_port for Cyton
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].Equals("--ip-address"))
                {
                    input_params.ip_address = args[i + 1];
                }
                if (args[i].Equals("--mac-address"))
                {
                    input_params.mac_address = args[i + 1];
                }
                if (args[i].Equals("--serial-port"))
                {
                    input_params.serial_port = args[i + 1];
                }
                if (args[i].Equals("--other-info"))
                {
                    input_params.other_info = args[i + 1];
                }
                if (args[i].Equals("--ip-port"))
                {
                    input_params.ip_port = Convert.ToInt32(args[i + 1]);
                }
                if (args[i].Equals("--ip-protocol"))
                {
                    input_params.ip_protocol = Convert.ToInt32(args[i + 1]);
                }
                if (args[i].Equals("--board-id"))
                {
                    board_id = Convert.ToInt32(args[i + 1]);
                }
                if (args[i].Equals("--timeout"))
                {
                    input_params.timeout = Convert.ToInt32(args[i + 1]);
                }
                if (args[i].Equals("--serial-number"))
                {
                    input_params.serial_number = args[i + 1];
                }
                if (args[i].Equals("--file"))
                {
                    input_params.file = args[i + 1];
                }
                if (args[i].Equals("--metric"))
                {
                    model_params.metric = Convert.ToInt32(args[i + 1]);
                }
                if (args[i].Equals("--classifier"))
                {
                    model_params.classifier = Convert.ToInt32(args[i + 1]);
                }
            }
            return(board_id);
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.SYNTHETIC_BOARD;

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            double[,] unprocessed_data = board_shim.get_current_board_data(20);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            board_shim.release_session();

            // for demo apply different filters to different channels
            double[] filtered;
            for (int i = 0; i < eeg_channels.Length; i++)
            {
                Console.WriteLine("Before processing:");
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(eeg_channels[i])));
                switch (i)
                {
                case 0:
                    filtered = DataFilter.perform_lowpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 20.0, 4, (int)FilterTypes.BESSEL, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 1:
                    filtered = DataFilter.perform_highpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 2.0, 4, (int)FilterTypes.BUTTERWORTH, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 2:
                    filtered = DataFilter.perform_bandpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 15.0, 5.0, 2, (int)FilterTypes.BUTTERWORTH, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 3:
                    filtered = DataFilter.perform_bandstop(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 50.0, 1.0, 6, (int)FilterTypes.CHEBYSHEV_TYPE_1, 1.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                default:
                    filtered = DataFilter.remove_environmental_noise(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), (int)NoiseTypes.FIFTY);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;
                }
            }
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.SYNTHETIC_BOARD;

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            BoardShim.log_message((int)LogLevels.LEVEL_INFO, "Start sleeping in the main thread");
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            Console.WriteLine("data count: {0}", board_shim.get_board_data_count());
            double[,] unprocessed_data = board_shim.get_current_board_data(64);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(index)));
            }
            board_shim.release_session();

            // for demo apply different methods to different channels
            double[] filtered;
            for (int i = 0; i < eeg_channels.Length; i++)
            {
                switch (i)
                {
                // first of all you can try simple moving average or moving median
                case 0:
                    filtered = DataFilter.perform_rolling_filter(unprocessed_data.GetRow(eeg_channels[i]), 3, (int)AggOperations.MEAN);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 1:
                    filtered = DataFilter.perform_rolling_filter(unprocessed_data.GetRow(eeg_channels[i]), 3, (int)AggOperations.MEDIAN);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                // if for your signal these methods dont work good you can try wavelet based denoising
                default:
                    // feel free to try different functions and different decomposition levels
                    filtered = DataFilter.perform_wavelet_denoising(unprocessed_data.GetRow(eeg_channels[i]), "db4", 3);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Create and start a board data reader
        /// </summary>
        private async Task StartBoard(BrainFlowInputParams startupParams)
        {
            DataLatencyTimer = new System.Diagnostics.Stopwatch();
            DataLatencyTimer.Start();


            BrainflowBoard = new BoardDataReader();
            BrainflowBoard.ConnectToBoard += OnConnectToBoard;
            BrainflowBoard.Log            += OnLog;

            await Task.Run(async() =>
            {
                await BrainflowBoard.StartBoardDataReaderAsync(Properties.Settings.Default.BoardId, startupParams, checkBoxSRB.Checked);
            });
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            // use synthetic board for demo
            BoardShim.enable_dev_board_logger();
            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = (int)BoardIds.SYNTHETIC_BOARD;

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            BoardShim.log_message((int)LogLevels.LEVEL_INFO, "Start sleeping in the main thread");
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            Console.WriteLine("data count: {0}", board_shim.get_board_data_count());
            double[,] unprocessed_data = board_shim.get_current_board_data(64);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            board_shim.release_session();

            for (int i = 0; i < eeg_channels.Length; i++)
            {
                Console.WriteLine("Original data:");
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(eeg_channels[i])));
                // demo for wavelet transform
                // tuple of coeffs array in format[A(J) D(J) D(J-1) ..... D(1)] where J is a
                // decomposition level, A - app coeffs, D - detailed coeffs, and array which stores
                // length for each block, len of this array is decomposition_length + 1
                Tuple <double[], int[]> wavelet_data = DataFilter.perform_wavelet_transform(unprocessed_data.GetRow(eeg_channels[i]), "db4", 3);
                // print app coeffs
                for (int j = 0; j < wavelet_data.Item2[0]; j++)
                {
                    Console.Write(wavelet_data.Item1[j] + " ");
                }
                Console.WriteLine();
                // you can do smth with wavelet coeffs here, for example denoising works via thresholds for wavelets coeffs
                double[] restored_data = DataFilter.perform_inverse_wavelet_transform(wavelet_data, unprocessed_data.GetRow(eeg_channels[i]).Length, "db4", 3);
                Console.WriteLine("Restored wavelet data:");
                Console.WriteLine("[{0}]", string.Join(", ", restored_data));

                // demo for fft
                // end_pos - start_pos must be a power of 2
                Complex[] fft_data = DataFilter.perform_fft(unprocessed_data.GetRow(eeg_channels[i]), 0, 64);
                // len of fft_data is N / 2 + 1
                double[] restored_fft_data = DataFilter.perform_ifft(fft_data);
                Console.WriteLine("Restored fft data:");
                Console.WriteLine("[{0}]", string.Join(", ", restored_fft_data));
            }
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            try
            {
                BoardShim.enable_dev_board_logger();

                BrainFlowInputParams input_params = new BrainFlowInputParams();
                int board_id = (int)BoardIds.MINDROVE_WIFI_BOARD;//= parse_args(args, input_params);

                board_shim = new BoardShim(board_id, input_params);
                board_shim.prepare_session();

                board_shim.start_stream(); // use this for default options
                                           //board_shim.start_stream(450000, "file://file_stream.csv:w");

                board_shim.config_board(BoardShim.MindroveWifiConfigMode.EEG_MODE);
                BrainFlowModelParams concentration_params = new BrainFlowModelParams((int)BrainFlowMetrics.CONCENTRATION, (int)BrainFlowClassifiers.REGRESSION);
                concentration = new MLModel(concentration_params);
                concentration.prepare();

                sampling_rate = BoardShim.get_sampling_rate(board_id);
                eeg_channels  = BoardShim.get_eeg_channels(board_id);
                counter_idx   = BoardShim.get_package_num_channel(board_id);
            }
            catch (BrainFlowException ex)
            {
                Console.WriteLine(ex);
            }
            while (Update() >= 0)
            {
            }

            if (board_shim != null)
            {
                try
                {
                    board_shim.release_session();
                    concentration.release();
                }
                catch (BrainFlowException e)
                {
                    Console.WriteLine(e);
                }
                Console.WriteLine("Brainflow streaming was stopped");
            }
            Console.ReadLine();
        }
Beispiel #14
0
        /// <summary>
        /// Save the connection settings and
        /// create a brainflow input params object to start the board
        /// </summary>
        private BrainFlowInputParams SaveConnectionSettings()
        {
            SaveUiInputToProperties();

            BrainFlowInputParams startupParams = new BrainFlowInputParams()
            {
                serial_port = Properties.Settings.Default.ComPort,
            };

            if (checkBoxUseBFStream.Checked)
            {
                startupParams.ip_address = Properties.Settings.Default.IPAddress;
                startupParams.ip_port    = Properties.Settings.Default.IPPort;
            }

            return(startupParams);
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            BoardShim.enable_dev_board_logger();

            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = parse_args(args, input_params);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(450000, "file://file_stream.csv:w");
            for (int i = 1; i < 5; i++)
            {
                System.Threading.Thread.Sleep(1000);
                board_shim.insert_marker(i);
            }
            board_shim.stop_stream();
            board_shim.release_session();
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            BoardShim.enable_dev_board_logger();

            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = parse_args(args, input_params);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            // board_shim.start_stream (); // use this for default options
            board_shim.start_stream(450000, "file://file_stream.csv:w");
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            double[,] unprocessed_data = board_shim.get_current_board_data(20);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(index)));
            }
            board_shim.release_session();
        }
Beispiel #17
0
        // Public Interface
        #region PublicInterface

        /// <summary>
        /// Start the board data reader process
        /// </summary>
        public async Task StartBoardDataReaderAsync(int boardId, BrainFlowInputParams inputParams, bool startSrb1Set)
        {
            await StopBoardDataReaderAsync();

            StartSrb1CytonSet = startSrb1Set;
            StartSrb1DaisySet = startSrb1Set;

            Log?.Invoke(this, new LogEventArgs(this, "StartBoardDataReaderAsync", $"Starting board data reader", LogLevel.DEBUG));

            BoardId     = boardId;
            InputParams = inputParams;

            CancelTokenSource = new CancellationTokenSource();
            RunTask           = RunBoardDataReaderAsync(CancelTokenSource.Token);

            LastReportTime             = DateTimeOffset.UtcNow;
            ReadCounter                = 0;
            LastReadingTimestamp       = -1.0;
            LastSampleIndex            = -1;
            CountMissingIndex          = 0;
            RequestToggleStreamingMode = false;
        }
Beispiel #18
0
        /// <summary>
        /// Start / Stop button
        /// </summary>
        private async void buttonStart_Click(object sender, EventArgs e)
        {
            if (BrainflowBoard == null)
            {
                if (comboBoxComPort.SelectedItem == null)
                {
                    MessageBox.Show(Properties.Resources.InvalidComPort, Properties.Resources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                EnableConnectionButtons(false);
                buttonStart.Text = Properties.Resources.Cancel;

                BrainFlowInputParams startupParams = SaveConnectionSettings();

                await StartBoard(startupParams);

                Logger.AddLog(this, new LogEventArgs(this, "buttonStart_Click", $"Started server {Properties.Settings.Default.BoardId} on {Properties.Settings.Default.ComPort}.", LogLevel.INFO));
            }
            else
            {
                if (ConfigWindow != null)
                {
                    MessageBox.Show(Properties.Resources.CloseConfigWindowBeforeStoppingServer, Properties.Resources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                Logger.AddLog(this, new LogEventArgs(this, "buttonStart_Click", $"Stopping server.", LogLevel.INFO));

                await ShutDownBoard();

                EnableConnectionButtons(true);

                buttonStart.Text             = Properties.Resources.StartServer;
                buttonStart.Enabled          = true;
                buttonConfigureBoard.Enabled = false;
            }
        }
    public void setLocalControlParameters(string board, string _controlMethod)
    {
        input_params = new BrainFlowInputParams();

        if (board.Equals("Synthetic"))
        {
            board_id = (int)BoardIds.SYNTHETIC_BOARD;
        }
        else if (board.Equals("Cyton"))
        {
            input_params.serial_port = "COM4";
            board_id = (int)BoardIds.CYTON_BOARD;
        }
        else if (board.Equals("Ganglion"))
        {
            input_params.serial_port = "COM3";
            board_id = (int)BoardIds.GANGLION_BOARD;
        }
        else if (board.Equals("Cyton+Daisy"))
        {
            input_params.serial_port = "COM4";
            board_id = (int)BoardIds.CYTON_DAISY_BOARD;
        }
    }
        static void Main(string[] args)
        {
            BoardShim.enable_dev_board_logger();

            BrainFlowInputParams input_params = new BrainFlowInputParams();
            int board_id = parse_args(args, input_params);

            BoardShim board_shim = new BoardShim(board_id, input_params);

            board_shim.prepare_session();
            board_shim.start_stream(3600);
            BoardShim.log_message((int)LogLevels.LEVEL_INFO, "Start sleeping in the main thread");
            System.Threading.Thread.Sleep(5000);
            board_shim.stop_stream();
            Console.WriteLine("data count: {0}", board_shim.get_board_data_count());
            double[,] unprocessed_data = board_shim.get_current_board_data(20);
            int[] eeg_channels = BoardShim.get_eeg_channels(board_id);
            Console.WriteLine("Before processing:");
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", unprocessed_data.GetRow(index)));
            }
            board_shim.release_session();

            // demo for data serialization
            DataFilter.write_file(unprocessed_data, "test.csv", "w");
            double[,] restored_data = DataFilter.read_file("test.csv");
            Console.WriteLine("After Serialization:");
            foreach (var index in eeg_channels)
            {
                Console.WriteLine("[{0}]", string.Join(", ", restored_data.GetRow(index)));
            }

            // for demo apply different filters to different channels
            double[] filtered;
            for (int i = 0; i < eeg_channels.Length; i++)
            {
                switch (i)
                {
                case 0:
                    filtered = DataFilter.perform_lowpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 20.0, 4, (int)FilterTypes.BESSEL, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 1:
                    filtered = DataFilter.perform_highpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 2.0, 4, (int)FilterTypes.BUTTERWORTH, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 2:
                    filtered = DataFilter.perform_bandpass(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 20.0, 5.0, 2, (int)FilterTypes.BUTTERWORTH, 0.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;

                case 3:
                    filtered = DataFilter.perform_bandstop(unprocessed_data.GetRow(eeg_channels[i]), BoardShim.get_sampling_rate(board_id), 20.0, 1.0, 6, (int)FilterTypes.CHEBYSHEV_TYPE_1, 1.0);
                    Console.WriteLine("Filtered channel " + eeg_channels[i]);
                    Console.WriteLine("[{0}]", string.Join(", ", filtered));
                    break;
                }
            }
        }