コード例 #1
0
ファイル: Form1.cs プロジェクト: bankotamas/SerialDebugger
        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);
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: bankotamas/SerialDebugger
        public Form1()
        {
            InitializeComponent();

            /* Check Data Monitor folder is Exist or not. If not, we need to create it. */
            if (!Directory.Exists(DataMonitorFolderPath))
            {
                Directory.CreateDirectory(DataMonitorFolderPath);
            }

            /* Check Settings folder is Exist or not. If not, we need to create it. */
            if (!Directory.Exists(SettingsFolderPath))
            {
                Directory.CreateDirectory(SettingsFolderPath);
            }

            /* Set default serialport parameters for arduino */
            Arduino.ArduinoDefaults(baudrate_cbox, databit_cbox, parity_cbox, stopbit_cbox);

            /* Alive timer... */
            serialPortAliveTimer.Enabled = true;

            /* Data structures for read and handling settings data */
            ArduinoSerial.saveSettings   readSettings = new ArduinoSerial.saveSettings();
            ArduinoSerial.serialportData portData     = new ArduinoSerial.serialportData();

            List <string> settingsList = new List <string>();

            /* Find all settings file in Settings directory */
            foreach (string filePath in Directory.EnumerateFiles(SettingsFolderPath, "*.settings"))
            {
                settingsList.Add(filePath);
            }

            /* If the result is higher than zero, we have settings */
            if (settingsList.Count > 0)
            {
                foreach (string filePath in settingsList)
                {
                    /* Read settings from json file format */
                    try
                    {
                        readSettings = Jason.ReadFromJsonFile <ArduinoSerial.saveSettings>(filePath);
                        portData     = new ArduinoSerial.serialportData(readSettings);
                        dataList.Add(portData);
                        settings_lbox.Items.Add(portData.dataName);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Sajna nem sikerült beolvasni");
                    }
                }
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: bankotamas/SerialDebugger
        private void loadDataSet_btn_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = Path.GetFullPath(DataMonitorFolderPath);
            openFileDialog1.Filter           = "Data Monitor Collection files |*.dmc|All files |*.*";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.Multiselect      = false;
            openFileDialog1.FileName         = "";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    /* Datatype for loading */
                    DataMonitorSet dmSet;

                    string   fileName  = openFileDialog1.FileName;
                    string[] fileLines = File.ReadAllLines(fileName);

                    foreach (string fileContent in fileLines)
                    {
                        File.WriteAllText("Data Monitor//temp.dmc", fileContent);

                        try
                        {
                            dmSet = Jason.ReadFromJsonFile <DataMonitorSet>("Data Monitor//temp.dmc");
                            DataSetControl dsControl = new DataSetControl();

                            dsControl.dataSetName.Text = dmSet.DataSetName;
                            dsControl.MessageID.Text   = dmSet.DataSetID;
                            dsControl.Unit.Text        = dmSet.DataSetUnit;
                            dsControl.TabIndex         = GetNextTabIndex(dmSet.DataSetIndex);

                            /* Add to list for handling */
                            dataControlList.Add(dsControl);

                            /* Add to list for display the control */
                            flowLayoutPanel1.Controls.Add(dsControl);

                            /* Add double click event to control */
                            dsControl.dataSetName.DoubleClick += delegate(object sender2, EventArgs e2)
                            {
                                dataControl_DoubleClick_Event(sender, e, dsControl);
                            };
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Sajna nem sikerült beolvasni");
                        }
                        finally
                        {
                            if (File.Exists("Data Monitor//temp.dmc"))
                            {
                                File.Delete("Data Monitor//temp.dmc");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: bankotamas/SerialDebugger
        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");
            }
        }