Пример #1
0
 public static Environment_dataDataContext Create_Environment_SqlData()
 {
     if (sql_env == null)
     {
         sql_env = new Environment_dataDataContext();
     }
     return(sql_env);
 }
Пример #2
0
        void CheckString(string strRecv)
        {
            printLine("Receive:" + strRecv);
            String Environment_Value = @"<T(\-|\+)?\d+(\.\d+)?H(\-|\+)?\d+(\.\d+)?C(\-|\+)?\d+(\.\d+)?L(\-|\+)?\d+(\.\d+)?S(\-|\+)?\d+(\.\d+)?>";

            string Distance_Value  = @"%Dis(\-|\+)?\d+(\.\d+)?Dis(\-|\+)?\d+(\.\d+)?Dis(\-|\+)?\d+(\.\d+)?Dis(\-|\+)?\d+(\.\d+)?Dis(\-|\+)?\d+(\.\d+)?Dis(\-|\+)?\d+(\.\d+)?Dis(\-|\+)?\d+(\.\d+)?Dis(\-|\+)?\d+(\.\d+)?%";
            string Direction_Value = @"%XYZ(\-|\+)?\d+(\.\d+)?XYZ(\-|\+)?\d+(\.\d+)?XYZ(\-|\+)?\d+(\.\d+)?%";

            if (Regex.IsMatch(strRecv, Environment_Value))
            {
                String str1 = strRecv.Split(new char[2] {
                    '<', '>'
                })[1];
                String[] data = str1.Split(new char[5] {
                    'T', 'H', 'C', 'L', 'S'
                });
                for (int i = 0; i < data.Length; i++)
                {
                    printLine(data[i]);
                }

                //记录插入到数据库中
                Env_Data E_Data = new Env_Data()
                {
                    WiFi_Name_   = "No.1",
                    DataTime_    = DateTime.Now,
                    Temperature_ = Convert.ToDouble(data[1]),
                    Humi_        = Convert.ToDouble(data[2]),
                    CO2_         = Convert.ToDouble(data[3]),
                    light        = Convert.ToDouble(data[4]),
                    smokescope_  = Convert.ToDouble(data[5])
                };
                Environment_dataDataContext sql_env = Sql_Environment.Create_Environment_SqlData();
                sql_env.Env_Data.InsertOnSubmit(E_Data);
                sql_env.SubmitChanges();

                //跟新单例莫斯的数据
                Latast_data latast_da = Latast_data.getSingleon();
                latast_da.Temperature = Convert.ToDouble(data[1]);
                latast_da.Humi        = Convert.ToDouble(data[2]);
                latast_da.CO2         = Convert.ToDouble(data[3]);
                latast_da.Light       = Convert.ToDouble(data[4]);
                latast_da.smokescope  = Convert.ToDouble(data[5]);
                latast_da.datatime    = DateTime.Now.ToString();
            }
            else if (Regex.IsMatch(strRecv, Direction_Value))
            {
                printLine("陀螺仪:" + Environment.NewLine);
            }
        }