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 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); } }); }