Ejemplo n.º 1
0
        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");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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");
            }
        }