static int RunRecordAndReturnExitCode(RecordOptions opts) { // create Muse instance var dataToRead = opts.Data.Aggregate((acc, x) => acc | x); var muse = new Muse() { DataToRead = dataToRead }; // print Muse info Console.WriteLine($"Muse Model = {muse.Model}"); Console.WriteLine($"Muse Name = {muse.Name}"); // create GSR/PPG sampler instance var gsrPpgSampler = new GsrPpgSampler(opts.PortName, 115200, SamplingRate.SR500Hz, SamplingRate.SR500Hz); // print GSR/PPG sampler info Console.WriteLine($"GSR/PPG Sampler COM port = {gsrPpgSampler.PortName}, baudrate = {gsrPpgSampler.BaudRate}"); Console.WriteLine($"GSR sampling rate = {gsrPpgSampler.GsrSamplingRate}"); Console.WriteLine($"PPG sampling rate = {gsrPpgSampler.PpgSamplingRate}"); var stopwatch = new Stopwatch(); bool cancelKeyPressed = false; Console.WriteLine("Press any key to start recording"); Console.ReadKey(true); muse.StartReading(); gsrPpgSampler.StartReading(); stopwatch.Start(); // wait for a key press to exit Console.CancelKeyPress += (s, e) => { e.Cancel = true; cancelKeyPressed = true; }; Console.WriteLine("Press Ctrl + C to exit"); while (!cancelKeyPressed) { Console.Write($"\r{stopwatch.Elapsed.ToString("g")}"); Thread.Sleep(100); } Console.WriteLine(); stopwatch.Stop(); muse.StopReading(); gsrPpgSampler.StopReading(); Console.WriteLine("Saving data..."); var museJson = JObject.Parse(muse.ConvertDataToJson()); var gsrPpgJson = JObject.Parse(gsrPpgSampler.ConvertDataToJson()); museJson.Merge(gsrPpgJson); File.WriteAllText(opts.OutputFile, museJson.ToString()); return(0); }