private async void V_main_carregaLista_registos() { try { using (Stream fileStream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync("DadosRegistos.xml"))//abre { DataContractSerializer dcs = new DataContractSerializer(typeof(List <Registo>)); Program.model.listaRegistos = (List <Registo>)dcs.ReadObject(fileStream); //le para a lista. } StorageFolder pasta = Windows.Storage.ApplicationData.Current.LocalFolder; List <FrameRegisto> fr = new List <FrameRegisto>(); foreach (Registo r in Program.model.listaRegistos) { Stream streamFicheiro = await pasta.OpenStreamForReadAsync(r.Id_utilizador + ".txt"); StreamReader leitor = new StreamReader(streamFicheiro); fr.Clear(); while (!leitor.EndOfStream) { string[] st = leitor.ReadLine().Split(';'); FrameRegisto frame = new FrameRegisto(); frame.resultado0 = Convert.ToInt32(st[0]); frame.resultado1 = Convert.ToInt32(st[1]); frame.resultado2 = Convert.ToInt32(st[2]); frame.resultado3 = Convert.ToInt32(st[3]); frame.resultado4 = Convert.ToInt32(st[4]); frame.resultado5 = Convert.ToInt32(st[5]); fr.Add(frame); } r.Resultados = fr; } //StorageFolder pasta = Windows.Storage.ApplicationData.Current.LocalFolder; //Stream streamFicheiro = await pasta.OpenStreamForReadAsync("DadosRegistos.txt"); //Registo novo; //List<FrameRegisto> fr; //using (StreamReader sr = new StreamReader(streamFicheiro)) //{ // for (int i = 0; !sr.EndOfStream; i++) // { // fr = new List<FrameRegisto>(); // string[] separar = sr.ReadLine().Split(';'); // //string[] dataI = separar[3].Split('/'); // //string[] dataF = separar[4].Split('/'); // //DateTime dataInicio = new DateTime(Convert.ToDateTime(separar[3])); // //DateTime dataFim = new DateTime(Convert.ToInt32(dataF[2]), Convert.ToInt32(dataF[1]), Convert.ToInt32(dataF[0])); // Stream streamFicheiroR = await pasta.OpenStreamForReadAsync(separar[0]+".txt"); // StreamReader leitor = new StreamReader(streamFicheiroR); // while (!leitor.EndOfStream) // { // string[] st = leitor.ReadLine().Split(';'); // FrameRegisto frame = new FrameRegisto(); // frame.resultado0 = Convert.ToInt32(st[0]); // frame.resultado1 = Convert.ToInt32(st[1]); // frame.resultado2 = Convert.ToInt32(st[2]); // frame.resultado3 = Convert.ToInt32(st[3]); // frame.resultado4 = Convert.ToInt32(st[4]); // frame.resultado5 = Convert.ToInt32(st[5]); // fr.Add(frame); // } // novo = new Registo(Convert.ToInt32(separar[0]), Convert.ToInt32(separar[1]), separar[2], Convert.ToDateTime(separar[3], CultureInfo.InvariantCulture), Convert.ToDateTime(separar[4], CultureInfo.InvariantCulture), fr, separar[5], Convert.ToInt32(separar[6])); // Program.model.AdicionarNovoRegistoLista(novo); // } //} } catch (FileNotFoundException) { } Program.model.AtualizaDataRegistosMetodo(); }
private async void Ler() { //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[Convert.ToInt32(Program.v_main.comboBox_Frame.SelectedItem)]; //for (int i = 0; i < frames.Length; i++) //{ // frames[i] = new Bitalino.Frame(); // must initialize all elements in the array //} StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///OUTPUTS.txt")); StreamReader sr = new StreamReader(await file.OpenStreamForReadAsync()); string str; do { //ledState = !ledState; // toggle LED state //dev.trigger(new bool[] { false, false, ledState, false }); //dev.read(frames); // get the number of frames selected 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[] s = frame.ToString().Split(';'); // FrameRegisto fra = new FrameRegisto(); // fra.resultado0 = Convert.ToInt32(s[0]); // fra.resultado1 = Convert.ToInt32(s[1]); // fra.resultado2 = Convert.ToInt32(s[2]); // fra.resultado3 = Convert.ToInt32(s[3]); // fra.resultado4 = Convert.ToInt32(s[4]); // fra.resultado5 = Convert.ToInt32(s[5]); // temp.Add(fra); // await Program.v_main.listBox_logs.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => Program.v_main.atualizaLOGS("time: " + timer.ElapsedMilliseconds + " - " + frame.ToString())); //} //_-------temp str = sr.ReadLine(); //Apresenta dados nos LOGS //listBox.Invoke(new Action(() => listBox.Items.Add("time: " + timer.ElapsedMilliseconds + " - " + str.ToString()))); await Program.v_main.listBox_logs.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => Program.v_main.atualizaLOGS("time: " + timer.ElapsedMilliseconds + " - " + str.ToString())); string[] st = str.Split(';'); 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]); Task.Delay(50).Wait(); //System.Threading.Tasks.Task.Delay(50).Wait(); //Thread.Sleep(50); temp.Add(fr); //----- if (timer.ElapsedMilliseconds > EndTime * 1000) { readContinue = false; } //falta por duração limite } while (readContinue); //PÁRA QUANDO PRESSIONAR STOP OU A DURAÇÃO ATINGIR O LIMITE (SE O UTILIZADOR POS DURAÇÃO) fim = DateTime.Now; timer.Stop(); //duracaoReal = timer.ElapsedMilliseconds; timer.Reset(); //dev.stop(); // stop acquisition //dev.Dispose(); // disconnect from device }