private void Save(object parameter) { Microsoft.Win32.SaveFileDialog save = new Microsoft.Win32.SaveFileDialog { Title = "Save a file", DefaultExt = ".json", Filter = "JSON (*.json)|*.JSON|All Files (*.*)|*.*", }; if (save.ShowDialog() == true) { Model.JsonFormat jsonFormat = new Model.JsonFormat { Worker = Worker, Loop = Cycle }; String json = JsonConvert.SerializeObject(jsonFormat, Formatting.Indented); System.IO.File.WriteAllText(save.FileName, json.ToString()); Console.WriteLine(json); } }
private void Load(object parameter) { /* * using (var searcher = new ManagementObjectSearcher ("SELECT * FROM WIN32_SerialPort")) * { * string[] portnames = SerialPort.GetPortNames(); * var ports = searcher.Get().Cast<ManagementBaseObject>().ToList(); * var tList = (from n in portnames * join p in ports on n equals p["DeviceID"].ToString() * select n + " - " + p["Caption"]).ToList(); * * tList.ForEach(Console.WriteLine); * } * * */ // https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/win32-serialport ManagementClass processClass = new ManagementClass("Win32_SerialPort"); // Win32_PnPEntity ManagementObjectCollection Ports = processClass.GetInstances(); string device = "No recognized"; foreach (ManagementObject property in Ports) { if (property.GetPropertyValue("Name") != null) { //if (property.GetPropertyValue("Name").ToString().Contains("COM")) //{ Console.WriteLine(property.GetPropertyValue("DeviceID")); } Console.WriteLine(property.GetPropertyValue("Name").ToString()); device = property.GetPropertyValue("Name").ToString(); //} } //string[] ports = SerialPort.GetPortNames(); //foreach (string port in ports) //{ // Console.WriteLine(port); //} // Microsoft.Win32.OpenFileDialog open = new Microsoft.Win32.OpenFileDialog { Title = "Select a file", DefaultExt = ".json", Filter = "JSON (*.JSON)|*.JSON|All Files (*.*)|*.*", InitialDirectory = System.AppDomain.CurrentDomain.BaseDirectory }; if (open.ShowDialog() == true) { Model.JsonFormat jsonFormat = JsonConvert.DeserializeObject <Model.JsonFormat>(System.IO.File.ReadAllText(open.FileName)); //Console.WriteLine(jsonFormat.Loop); Worker.AddRange(jsonFormat.Worker); Cycle = jsonFormat.Loop; } }