private void saveDataSet_btn_Click(object sender, EventArgs e) { saveFileDialog1.InitialDirectory = Path.GetFullPath(DataMonitorFolderPath); saveFileDialog1.Filter = "Data Monitor Collection files |*.dmc|All files |*.*"; saveFileDialog1.FilterIndex = 1; saveFileDialog1.FileName = ""; /* Datatype for saving */ DataMonitorSet dmSet; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { if (File.Exists(saveFileDialog1.FileName)) { File.Delete(saveFileDialog1.FileName); } foreach (DataSetControl dsControl in dataControlList) { dmSet.DataSetName = dsControl.dataSetName.Text; dmSet.DataSetID = dsControl.MessageID.Text; dmSet.DataSetUnit = dsControl.Unit.Text; dmSet.DataSetIndex = dsControl.TabIndex; Jason.WriteToJsonFile <DataMonitorSet>(saveFileDialog1.FileName, dmSet, true); } } }
private void saveSettings_btn_Click(object sender, EventArgs e) { if (settingsName_tbox.TextLength > 0) { if (!settings_lbox.Items.Contains(settingsName_tbox.Text.ToString())) { settings_lbox.Items.Add(settingsName_tbox.Text.ToString()); } ArduinoSerial.saveSettings actual = new ArduinoSerial.saveSettings(); /* Set serialport parameters for saving */ Arduino.serialPort.PortName = comport_cbox.SelectedItem.ToString(); Arduino.serialPort.BaudRate = Convert.ToInt32(baudrate_cbox.SelectedItem.ToString()); Arduino.serialPort.DataBits = Convert.ToInt32(databit_cbox.SelectedItem.ToString()); switch (parity_cbox.SelectedItem.ToString()) { case "None": Arduino.serialPort.Parity = Parity.None; break; case "Odd": Arduino.serialPort.Parity = Parity.Odd; break; case "Even": Arduino.serialPort.Parity = Parity.Even; break; case "Mark": Arduino.serialPort.Parity = Parity.Mark; break; case "Space": Arduino.serialPort.Parity = Parity.Space; break; } switch (stopbit_cbox.SelectedItem.ToString()) { case "One": Arduino.serialPort.StopBits = StopBits.One; break; case "Two": Arduino.serialPort.StopBits = StopBits.Two; break; case "OnePointFive": Arduino.serialPort.StopBits = StopBits.OnePointFive; break; } actual = new ArduinoSerial.saveSettings(settingsName_tbox.Text.ToString(), Arduino.serialPort); /* Add serial port informations to list, then write to a file (and in this way, we can read) */ dataList.Add(new ArduinoSerial.serialportData(actual)); Jason.WriteToJsonFile(SettingsFolderPath + "/" + settingsName_tbox.Text.ToString() + ".settings", actual); settingsName_tbox.Text = string.Empty; } else { MessageBox.Show("Settings name is EMPTY! You need to write something...", "Error"); } }