Пример #1
0
 void LoadConfig()
 {
     try
     {
         serialPortConfig config = serialPortConfig.getDefaultConfig();
         if (config == null)
         {
             return;
         }
         string portname = config.portName;
         if (string.Empty == portname)
         {
             cmbPortName.SelectedIndex = -1;
         }
         else
         {
             cmbPortName.SelectedIndex = cmbPortName.Items.IndexOf(portname);
         }
         string baudRate = config.baudRate;
         if (string.Empty != baudRate)
         {
             cmbBaudRate.SelectedIndex = cmbBaudRate.Items.IndexOf(baudRate);
         }
         else
         {
             cmbBaudRate.SelectedIndex = -1;
         }
         string parity = config.parity;
         if (string.Empty != parity)
         {
             cmbParity.SelectedIndex = cmbParity.Items.IndexOf(parity);
         }
         else
         {
             cmbParity.SelectedIndex = -1;
         }
         string stopbites = config.stopBits;
         if (string.Empty != stopbites)
         {
             cmbStopBits.SelectedIndex = cmbStopBits.Items.IndexOf(stopbites);
         }
         else
         {
             cmbStopBits.SelectedIndex = -1;
         }
         string databits = config.dataBits;
         if (string.Empty != databits)
         {
             cmbDataBits.SelectedIndex = cmbDataBits.Items.IndexOf(databits);
         }
         else
         {
             cmbDataBits.SelectedIndex = -1;
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Пример #2
0
        public static void saveConfig(serialPortConfig config)
        {
            // accessDb4o
            //IObjectContainer db = Db4oFactory.OpenFile(serialPortConfig.configFilePath);
            IObjectContainer db = staticClass.db;

            try
            {
                IList <serialPortConfig> list = db.Query <serialPortConfig>(delegate(serialPortConfig cf)
                {
                    return(cf.configName == config.configName);
                }
                                                                            );
                if (list.Count <= 0)
                {
                    db.Store(config);
                }
                else
                {
                    serialPortConfig.copy(config, list[0]);
                    db.Store(list[0]);
                }
            }
            finally
            {
                //db.Close();
            }
        }
Пример #3
0
        public static serialPortConfig getDefaultConfig()
        {
            serialPortConfig config    = null;
            string           port_name = string.Empty;
            string           baut_rate = string.Empty;
            string           sql       = "select vvalue from sys_config where vkey = '{0}'";
            DataTable        dt_temp   = CsharpSQLiteHelper.ExecuteTable(sql, new object[1] {
                "port_name"
            });

            if (dt_temp.Rows.Count > 0)
            {
                port_name = dt_temp.Rows[0]["vvalue"].ToString();
            }
            sql     = "select vvalue from sys_config where vkey = '{0}'";
            dt_temp = CsharpSQLiteHelper.ExecuteTable(sql, new object[1] {
                "baut_rate"
            });
            if (dt_temp.Rows.Count > 0)
            {
                baut_rate = dt_temp.Rows[0]["vvalue"].ToString();
            }
            config = new serialPortConfig(port_name, baut_rate);

            return(config);
        }
Пример #4
0
 public static void copy(serialPortConfig source, serialPortConfig dest)
 {
     dest.configName = source.configName;
     dest.portName   = source.portName;
     dest.baudRate   = source.baudRate;
     dest.parity     = source.parity;
     dest.dataBits   = source.dataBits;
     dest.stopBits   = source.stopBits;
 }
Пример #5
0
        private void btnSaveConfig_Click(object sender, EventArgs e)
        {
            serialPortConfig config = new serialPortConfig("default", cmbPortName.Text,
                                                           cmbBaudRate.Text,
                                                           cmbParity.Text,
                                                           cmbDataBits.Text,
                                                           cmbStopBits.Text);

            serialPortConfig.saveConfig(config);
            MessageBox.Show("保存完成!", "串口设置");
        }
Пример #6
0
        public void copy(IConfig src)
        {
            serialPortConfig source = (serialPortConfig)src;

            this.configName = source.configName;
            this.portName   = source.portName;
            this.baudRate   = source.baudRate;
            this.parity     = source.parity;
            this.dataBits   = source.dataBits;
            this.stopBits   = source.stopBits;
        }
Пример #7
0
        public static void saveConfig(serialPortConfig config)
        {
            string sql = "insert into sys_config(vkey,vvalue) values('{0}','{1}')";
            int    rtn = 0;

            rtn = CsharpSQLiteHelper.ExecuteNonQuery(sql, new object[2] {
                "port_name", config.portName
            });
            if (rtn <= 0)
            {
                return;
            }
            rtn = 0;
            rtn = CsharpSQLiteHelper.ExecuteNonQuery(sql, new object[2] {
                "baut_rate", config.baudRate
            });
            //if (rtn <= 0)
            //{
            //    return;
            //}
            //// accessDb4o
            //IObjectContainer db = Db4oFactory.OpenFile(serialPortConfig.configFilePath);
            //try
            //{
            //    IList<serialPortConfig> list = db.Query<serialPortConfig>(delegate(serialPortConfig cf)
            //    {
            //        return cf.configName == config.configName;
            //    }
            //                                              );
            //    if (list.Count <= 0)
            //    {
            //        db.Store(config);
            //    }
            //    else
            //    {
            //        serialPortConfig.copy(config, list[0]);
            //        db.Store(list[0]);
            //    }

            //}
            //finally
            //{
            //    db.Close();
            //}
        }
Пример #8
0
        public static serialPortConfig getDefaultConfig()
        {
            serialPortConfig config    = null;
            string           port_name = string.Empty;
            string           baut_rate = string.Empty;
            string           sql       = "select vvalue from sys_config where vkey = '{0}'";
            DataTable        dt_temp   = CsharpSQLiteHelper.ExecuteTable(sql, new object[1] {
                "port_name"
            });

            if (dt_temp.Rows.Count > 0)
            {
                port_name = dt_temp.Rows[0]["vvalue"].ToString();
            }
            sql     = "select vvalue from sys_config where vkey = '{0}'";
            dt_temp = CsharpSQLiteHelper.ExecuteTable(sql, new object[1] {
                "baut_rate"
            });
            if (dt_temp.Rows.Count > 0)
            {
                baut_rate = dt_temp.Rows[0]["vvalue"].ToString();
            }
            config = new serialPortConfig(port_name, baut_rate);
            //IObjectContainer db = Db4oFactory.OpenFile(serialPortConfig.configFilePath);
            //try
            //{
            //    IList<serialPortConfig> list = db.Query<serialPortConfig>(delegate(serialPortConfig cf)
            //    {
            //        return cf.configName == "default";
            //    }
            //                                              );
            //    if (list.Count > 0)
            //    {
            //        config = list[0];
            //    }

            //}
            //finally
            //{
            //    db.Close();
            //}
            return(config);
        }
Пример #9
0
        public static serialPortConfig getDefaultConfig()
        {
            serialPortConfig config = null;
            //IObjectContainer db = Db4oFactory.OpenFile(serialPortConfig.configFilePath);
            IObjectContainer db = staticClass.db;

            try
            {
                IList <serialPortConfig> list = db.Query <serialPortConfig>(delegate(serialPortConfig cf)
                {
                    return(cf.configName == "default");
                }
                                                                            );
                if (list.Count > 0)
                {
                    config = list[0];
                }
            }
            finally
            {
                //db.Close();
            }
            return(config);
        }