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(); } }
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); } }); }
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); } }); }
public void Ler() { try { 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[Program.V_CriarRegisto.nbFrames]; for (int i = 0; i < frames.Length; i++) { frames[i] = new Bitalino.Frame(); // must initialize all elements in the array } //StreamReader sr = new StreamReader("OUTPUTS.txt"); // string str = ""; 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]); //passar para a ListBoxLogs e para o nosso frame foreach (Bitalino.Frame frame in frames) { //string[] st = frame.ToString().Split(';'); FrameRegisto fr = new FrameRegisto(); fr.resultado0 = f.analog[0]; fr.resultado1 = f.analog[1]; fr.resultado2 = f.analog[2]; fr.resultado3 = f.analog[3]; fr.resultado4 = f.analog[4]; fr.resultado5 = f.analog[5]; Program.V_CriarRegisto.temp.Add(fr); string c = ""; if (Program.V_CriarRegisto.CAAC) { if (Program.V_CriarRegisto.aac == "0") { c += "AAC: " + fr.resultado0.ToString() + " "; } if (Program.V_CriarRegisto.aac == "1") { c += "AAC: " + fr.resultado1.ToString() + " "; } if (Program.V_CriarRegisto.aac == "2") { c += "AAC: " + fr.resultado2.ToString() + " "; } if (Program.V_CriarRegisto.aac == "3") { c += "AAC: " + fr.resultado3.ToString() + " "; } if (Program.V_CriarRegisto.aac == "4") { c += "AAC: " + fr.resultado4.ToString() + " "; } if (Program.V_CriarRegisto.aac == "5") { c += "AAC: " + fr.resultado5.ToString() + " "; } } if (Program.V_CriarRegisto.CBATT) { if (Program.V_CriarRegisto.batt == "0") { c += "BATT: " + fr.resultado0.ToString() + " "; } if (Program.V_CriarRegisto.batt == "1") { c += "BATT: " + fr.resultado1.ToString() + " "; } if (Program.V_CriarRegisto.batt == "2") { c += "BATT: " + fr.resultado2.ToString() + " "; } if (Program.V_CriarRegisto.batt == "3") { c += "BATT: " + fr.resultado3.ToString() + " "; } if (Program.V_CriarRegisto.batt == "4") { c += "BATT: " + fr.resultado4.ToString() + " "; } if (Program.V_CriarRegisto.batt == "5") { c += "BATT: " + fr.resultado5.ToString() + " "; } } if (Program.V_CriarRegisto.CECG) { if (Program.V_CriarRegisto.ecg == "0") { c += "ECG: " + fr.resultado0.ToString() + " "; } if (Program.V_CriarRegisto.ecg == "1") { c += "ECG: " + fr.resultado1.ToString() + " "; } if (Program.V_CriarRegisto.ecg == "2") { c += "ECG: " + fr.resultado2.ToString() + " "; } if (Program.V_CriarRegisto.ecg == "3") { c += "ECG: " + fr.resultado3.ToString() + " "; } if (Program.V_CriarRegisto.ecg == "4") { c += "ECG: " + fr.resultado4.ToString() + " "; } if (Program.V_CriarRegisto.ecg == "5") { c += "ECG: " + fr.resultado5.ToString() + " "; } } if (Program.V_CriarRegisto.CEMG) { if (Program.V_CriarRegisto.emg == "0") { c += "EMG: " + fr.resultado0.ToString() + " "; } if (Program.V_CriarRegisto.emg == "1") { c += "EMG: " + fr.resultado1.ToString() + " "; } if (Program.V_CriarRegisto.emg == "2") { c += "EMG: " + fr.resultado2.ToString() + " "; } if (Program.V_CriarRegisto.emg == "3") { c += "EMG: " + fr.resultado3.ToString() + " "; } if (Program.V_CriarRegisto.emg == "4") { c += "EMG: " + fr.resultado4.ToString() + " "; } if (Program.V_CriarRegisto.emg == "5") { c += "EMG: " + fr.resultado5.ToString() + " "; } } if (Program.V_CriarRegisto.CLUX) { if (Program.V_CriarRegisto.lux == "0") { c += "LUX: " + fr.resultado0.ToString() + " "; } if (Program.V_CriarRegisto.lux == "1") { c += "LUX: " + fr.resultado1.ToString() + " "; } if (Program.V_CriarRegisto.lux == "2") { c += "LUX: " + fr.resultado2.ToString() + " "; } if (Program.V_CriarRegisto.lux == "3") { c += "LUX: " + fr.resultado3.ToString() + " "; } if (Program.V_CriarRegisto.lux == "4") { c += "LUX: " + fr.resultado4.ToString() + " "; } if (Program.V_CriarRegisto.lux == "5") { c += "LUX: " + fr.resultado5.ToString() + " "; } } if (Program.V_CriarRegisto.CEDA) { if (Program.V_CriarRegisto.eda == "0") { c += "EDA: " + fr.resultado0.ToString() + " "; } if (Program.V_CriarRegisto.eda == "1") { c += "EDA: " + fr.resultado1.ToString() + " "; } if (Program.V_CriarRegisto.eda == "2") { c += "EDA: " + fr.resultado2.ToString() + " "; } if (Program.V_CriarRegisto.eda == "3") { c += "EDA: " + fr.resultado3.ToString() + " "; } if (Program.V_CriarRegisto.eda == "4") { c += "EDA: " + fr.resultado4.ToString() + " "; } if (Program.V_CriarRegisto.eda == "5") { c += "EDA: " + fr.resultado5.ToString() + " "; } } Program.V_CriarRegisto.mostraLog(c); } //_-------temp //str = sr.ReadLine(); //listBoxLogs.Invoke(new Action(() => listBoxLogs.Items.Add("time: " + timer.ElapsedMilliseconds + " - " + str.ToString()))); //string[] st = str.Split(';'); //if (st[0] != "") { //FrameRegisto fr = new FrameRegisto(); //fr.resultado0 = Convert.ToInt32(st[0]); //fr.resultado1 = Convert.ToInt32(st[1]); //fr.resultado2 = Convert.ToInt32(st[2]); //fr.resultado3 = Convert.ToInt32(st[3]); //fr.resultado4 = Convert.ToInt32(st[4]); //fr.resultado5 = Convert.ToInt32(st[5]); //Thread.Sleep(50); //temp.Add(fr); //} //----- if (Program.V_CriarRegisto.timer.ElapsedMilliseconds > duração) { Program.V_CriarRegisto.readContinue = false; } //falta por duração limite } while (Program.V_CriarRegisto.readContinue); Program.V_CriarRegisto.readContinue = false; Program.V_CriarRegisto.BUTstart(); fim = DateTime.Now; Program.V_CriarRegisto.timer.Stop(); duraçãoReal = Program.V_CriarRegisto.timer.ElapsedMilliseconds; Program.V_CriarRegisto.timer.Reset(); Program.V_CriarRegisto.guardarTh(); // PÁRA QUANDO PRESSIONAR STOP OU A DURAÇÃO ATINGIR O LIMITE (SE O UTILIZADOR POS DURAÇÃO) dev.stop(); // stop acquisition dev.Dispose(); // disconnect from device } catch (Bitalino.Exception ex) { Program.V_CriarRegisto.ERRO(ex); Program.V_CriarRegisto.readContinue = false; } readThread.Abort(); }
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); } }); }