private async void Save() { try { if (saveProcessFlag) { await Task.Run(() => { while (saveProcessFlag) { } }); } saveProcessFlag = true; //string Path = $"{Environment.CurrentDirectory}\\programConfig.progc"; StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFile configFile = await localFolder.CreateFileAsync("programConfig.progc", CreationCollisionOption.ReplaceExisting); ProgramConfig prog = ProgramConfig.Instance; await FileIO.WriteTextAsync(configFile, JsonConvert.SerializeObject(prog)); saveProcessFlag = false; } catch (Exception e) { CommonFunction.CommonConsoleWrite(e.Message); } }
Task send; //поток для приняти данных //Task execution; //поток для отправки коллекции точек public MainPage() { try { this.InitializeComponent(); ConsoleWrite("Hello word "); programConfig = ProgramConfig.Instance; //Serial port initialize serialPort = ManipulatorSerialPort.Instance; this.components = new System.ComponentModel.Container(); SerialPort sr = this.serialPort; sr = new System.IO.Ports.SerialPort(this.components); this.serialPort.BaudRate = 115200; // this.serialPort.WriteTimeout = 50; this.serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort_DataReceived); CommonFunction.SetsendMessage(ConsoleWrite); //для доступа к консоли другим Page comboSelectPort.Items.Clear(); GetPortNames(); //загрузить список портов в comboSelectPort // по умолчанию открываем страницу home.xaml myFrame.Navigate(typeof(Home)); TitleTextBlock.Text = "Главная"; //passing Passing.ContextStrategy = new SinPassingStrategy(); Passing.SentPointFunction = serialPort.Write; } catch (Exception e) { ConsoleWrite(e.ToString(), Colors.Red); } }
private async void Load() { try { //string Path = $"{Environment.CurrentDirectory}\\programConfig.progc"; //var data = File.ReadAllText(Path);//File.ReadAllText($"{Environment.CurrentDirectory}\\{Path}"); StorageFolder localFolder = ApplicationData.Current.LocalFolder; // получаем файл StorageFile configFile = await localFolder.GetFileAsync("programConfig.progc"); var data = await FileIO.ReadTextAsync(configFile); ProgramConfig p = JsonConvert.DeserializeObject <ProgramConfig>(data); if (p == null) { p = new ProgramConfig(); } } catch (FileNotFoundException) { ProgramConfig p = ProgramConfig.Instance; p.Speed = 9600; p.PortNum = 0; p.MaxGripValue = 180; p.MinGripValue = 0; } catch (Exception e) { throw new Exception(e.Message); } }