Beispiel #1
0
        /// <summary>
        /// Request connection on serial port with provided settings
        /// </summary>
        /// <param name="selected_settings"></param>
        public void ConnectionRequest(COMSettings selected_settings)
        {
            string settings = JSON.serialize(selected_settings);

            settings = "{\"connection_request\":" + settings + "}";
            WriteData(settings);
            connectionStatus = ConnectionStatus.WaitingConnectInit;
        }
Beispiel #2
0
        private void ApplyComSettings()
        {
            string      portName    = null;
            int         baudRate    = (int)SerialHandler.default_settings.BaudRate;
            COMSettings comSettings = new COMSettings();

            if (UIcomSourcesList.SelectedIndex >= 0)
            {
                portName = portNames[UIcomSourcesList.SelectedIndex];
                Program.settings.portName        = portName;
                Program.settings.portDescription = UIcomSourcesList.Items[UIcomSourcesList.SelectedIndex].ToString();
            }

            if (UIbaudRateInputList.SelectedIndex >= 0)
            {
                baudRate = (int)UIbaudRateInputList.Items[UIbaudRateInputList.SelectedIndex];
                comSettings.baud_rate = baudRate;
            }

            // Fix this
            comSettings.config  = "8N1";
            comSettings.newline = "\r\n";

            Program.settings.comSettings = comSettings;

            if (portName != null)
            {
                // Save last com settings to db
                string path = Program.settings.DatabasePath;
                using (LiteDatabase db = new LiteDatabase(@path))
                {
                    LiteCollection <DB_ComSettingsItem> collection = db.GetCollection <DB_ComSettingsItem>(Program.settings.COMSettingsDB);

                    IEnumerable <DB_ComSettingsItem> results = collection.FindAll();

                    DB_ComSettingsItem store = new DB_ComSettingsItem
                    {
                        baud_rate       = baudRate,
                        Parity          = (int)SerialHandler.default_settings.Parity,
                        DataBits        = (int)SerialHandler.default_settings.DataBits,
                        StopBits        = (int)SerialHandler.default_settings.StopBits,
                        NewLine         = @SerialHandler.default_settings.NewLine,
                        Config          = "8N1",
                        PortDescription = Program.settings.portDescription,
                        PortName        = Program.settings.portName
                    };

                    if (results.Count() > 0)
                    {
                        // Update existing item
                        DB_ComSettingsItem existing = results.First();
                        ObjectId           id       = existing.Id;
                        store.Id = id;
                        collection.Update(store);
                    }
                    else
                    {
                        // Add item
                        collection.Insert(store);
                    }
                }
            }
        }