public static int InsertData1000(ObsParams params1, float[] GHISum1000, float[] GTISum1000) { int ret = MysqlDAO.Insert2Db1000(params1, GHISum1000, GTISum1000); return(ret); /* string sql = @" insert into obsdata(StationName,StationNO,ObsTime,GHI,GTI,PanleTemp,Temperature,Humitity,WindSpeed,WindDir,GHISum,GTISum) * values(@StationName,@StationNO,@ObsTime,@GHI,@GTI,@PanleTemp,@Temperature,@Humitity,@WindSpeed,@WindDir,@GHISum,@GTISum) * * "; * * try * { * List<OleDbParameter> paramList = new List<OleDbParameter>(); * paramList.Add(new OleDbParameter("@StationName", params1.StationName)); * paramList.Add(new OleDbParameter("@StationNO", params1.StationNO)); * paramList.Add(new OleDbParameter("@ObsTime", params1.ObsTime)); * paramList.Add(new OleDbParameter("@GHI", params1.GHI)); * paramList.Add(new OleDbParameter("@GTI", params1.GTI)); * paramList.Add(new OleDbParameter("@PanleTemp", params1.PanleTemp)); * paramList.Add(new OleDbParameter("@Temperature", params1.Temperature)); * paramList.Add(new OleDbParameter("@Humitity", params1.Humitity)); * paramList.Add(new OleDbParameter("@WindSpeed", params1.WindSpeed)); * paramList.Add(new OleDbParameter("@WindDir", params1.WindDir)); * paramList.Add(new OleDbParameter("@GHISum", params1.GHISum)); * paramList.Add(new OleDbParameter("@GTISum", params1.GTISum)); * * return AccessHelper.ExecuteNonQuery(conn, sql, paramList.ToArray()); * } * catch (System.Exception ex) * { * return 0; * }*/ }
public static ObsParams GetObsParams(byte[] data1) { ObsParams param = null; using (MemoryStream memoryStream = new MemoryStream(data1)) { try { BinaryReader br = new BinaryReader(memoryStream); br.ReadBytes(2); int Count = Convert.ToInt32(br.ReadByte()); if (Count < 20) { return(null); } param = new ObsParams(); //param.EquipNO = Convert.ToInt32(ChangeXL(br.ReadSingle())).ToString(); //param.StationNO = Convert.ToInt32(ChangeXL(br.ReadSingle())); //param.Year = Convert.ToInt32(ChangeXL(br.ReadSingle())); //param.Month = Convert.ToInt32(ChangeXL(br.ReadSingle())); //param.Day = Convert.ToInt32(ChangeXL(br.ReadSingle())); //param.Hour = Convert.ToInt32(ChangeXL(br.ReadSingle())); //param.Minute = Convert.ToInt32(ChangeXL(br.ReadSingle())); //param.Second= Convert.ToInt32(ChangeXL(br.ReadSingle())); param.GHISum = Convert.ToSingle(ChangeXLU16(br.ReadUInt16())) / 1000; param.GTISum = Convert.ToSingle(ChangeXLU16(br.ReadUInt16())) / 1000; param.PanleTemp = Convert.ToSingle(ChangeXL16(br.ReadInt16())) / 10; param.Temperature = Convert.ToSingle(ChangeXL16(br.ReadInt16())) / 10; param.Humitity = Convert.ToSingle(ChangeXLU16(br.ReadUInt16())) / 10; param.WindSpeed = Convert.ToSingle(ChangeXLU16(br.ReadUInt16())) / 10; param.WindSpeed = Convert.ToSingle(ChangeXLU16(br.ReadUInt16())) / 10; param.WindDir = Convert.ToSingle(ChangeXLU16(br.ReadUInt16())); param.GHI = Convert.ToSingle(ChangeXLU16(br.ReadUInt16())); param.GTI = Convert.ToSingle(ChangeXLU16(br.ReadUInt16())); //param.WindSpeed = ChangeXL(br.ReadSingle()); // param.WindDir = ChangeXL(br.ReadSingle()); //param.mVisibity = ChangeXL(br.ReadSingle()); //param.BatteryVolt = ChangeXL(br.ReadSingle()); return(param); } catch { return(null); } } }
public static int Insert2Db1000(ObsParams params1, float[] GHISum1000, float[] GTISum1000) { //"datasource=localhost;username=root;password=NCEPU_fluence.;database=topflag string connectionString = "Server=localhost;User Id=root;Password=123456789;Persist Security Info=True;Database=topflag;"; MySqlConnection cn = new MySqlConnection(connectionString); //int EXIST = Exist(params1.StationName, params1.ObsTime); //if (EXIST==1) //{ //return 0; // } int res = 0; try {//( StationID) Values ( @StationID); string sql = @" insert into obsdata1000(StationName,StationNO,ObsTime,GHI,GTI,GHISum,GTISum,GHISum1000,GTISum1000) values(@StationName,@StationNO,@ObsTime,@GHI,@GTI,@GHISum,@GTISum,@GHISum1000,@GTISum1000)"; MySqlCommand cmd = new MySqlCommand(sql, cn); cmd.Parameters.Add(new MySqlParameter("@StationName", MySqlDbType.VarChar) { Value = params1.StationName }); cmd.Parameters.Add(new MySqlParameter("@StationNO", MySqlDbType.Int32) { Value = params1.StationNO }); cmd.Parameters.Add(new MySqlParameter("@ObsTime", MySqlDbType.DateTime) { Value = params1.ObsTime }); cmd.Parameters.Add(new MySqlParameter("@GHI", MySqlDbType.Float) { Value = params1.GHI }); cmd.Parameters.Add(new MySqlParameter("@GTI", MySqlDbType.Float) { Value = params1.GTI }); cmd.Parameters.Add(new MySqlParameter("@GHISum", MySqlDbType.Float) { Value = params1.GHISum }); cmd.Parameters.Add(new MySqlParameter("@GTISum", MySqlDbType.Float) { Value = params1.GTISum }); cmd.Parameters.Add(new MySqlParameter("@GHISum1000", MySqlDbType.Float) { Value = GHISum1000[params1.StationNO - 1] }); cmd.Parameters.Add(new MySqlParameter("@GTISum1000", MySqlDbType.Float) { Value = GTISum1000[params1.StationNO - 1] }); cn.Open(); res = cmd.ExecuteNonQuery(); } catch (System.Exception ex) { res = -1; } finally { cn.Close(); cn.Dispose(); } return(res); }
public static ObsParams GetObsParams_old(string data1) { ObsParams param = new ObsParams(); try { string StationNO = data1.Substring(1, 4); uint num = uint.Parse(StationNO, System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals = BitConverter.GetBytes(num); param.StationNO = BitConverter.ToInt16(floatVals, 0); string hexString = data1.Substring(87, 4); uint num2 = uint.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals2 = BitConverter.GetBytes(num2); param.GHISum = Convert.ToSingle(BitConverter.ToInt16(floatVals2, 0)) / 10; string GTISum = data1.Substring(79, 4); uint num3 = uint.Parse(GTISum, System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals3 = BitConverter.GetBytes(num3); param.GTISum = Convert.ToSingle(BitConverter.ToInt16(floatVals3, 0)) / 10; string PanleTemp = data1.Substring(107, 4); uint num4 = uint.Parse(PanleTemp, System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals4 = BitConverter.GetBytes(num4); param.PanleTemp = Convert.ToSingle(BitConverter.ToInt16(floatVals4, 0)); string Temperature = data1.Substring(117, 4); uint num5 = uint.Parse(Temperature, System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals5 = BitConverter.GetBytes(num5); param.Temperature = Convert.ToSingle(BitConverter.ToInt16(floatVals5, 0)) / 10; string Humitity = data1.Substring(117, 4); uint num6 = uint.Parse(Humitity, System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals6 = BitConverter.GetBytes(num6); param.Humitity = Convert.ToSingle(BitConverter.ToInt16(floatVals6, 0)) / 10; string WindSpeed = data1.Substring(117, 4); uint num7 = uint.Parse(WindSpeed, System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals7 = BitConverter.GetBytes(num7); param.WindSpeed = Convert.ToSingle(BitConverter.ToInt16(floatVals7, 0)) / 10; string WindDir = data1.Substring(117, 4); uint num8 = uint.Parse(WindDir, System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals8 = BitConverter.GetBytes(num8); param.WindDir = Convert.ToSingle(BitConverter.ToInt16(floatVals8, 0)) / 10; string GHI = data1.Substring(117, 4); uint num9 = uint.Parse(GHI, System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals9 = BitConverter.GetBytes(num9); param.GHI = Convert.ToSingle(BitConverter.ToInt16(floatVals9, 0)) / 10; string GTI = data1.Substring(117, 4); uint num10 = uint.Parse(GHI, System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals10 = BitConverter.GetBytes(num9); param.GHI = Convert.ToSingle(BitConverter.ToInt16(floatVals10, 0)) / 10; } catch (System.Exception ex) { param = null; } return(param); }
// void bw_DoWork(object sender, DoWorkEventArgs e) void bw_DoWork(System.IO.Ports.SerialPort sport) { // 需要在此写入接收程序,判断信息 // System.IO.Ports.SerialPort sport = e.Argument as System.IO.Ports.SerialPort; string sp = sport.PortName; string stationName = GetEquipNo(sp); string StationNo = GetStationNo(sp); bool equiptype = IfOld(sp); if (equiptype == false) { byte[] RcvBytes = new byte[sport.BytesToRead]; Thread.Sleep(3000); int lIntLen = sport.Read(RcvBytes, 0, RcvBytes.Length); if (params1 != null) { params1 = null; } //从串口获取数据 params1 = new ObsParams(); // 定义到数据库文件,应该是一样的 if (lIntLen < 25) { byte[] RcyByte_all = RcvBytes; sp = sport.PortName; stationName = GetEquipNo(sp); StationNo = GetStationNo(sp); byte[] RcvBytes_new = new byte[sport.BytesToRead]; lIntLen = sport.Read(RcvBytes_new, 0, RcvBytes_new.Length); byte[] result = new byte[RcyByte_all.Length + RcvBytes_new.Length]; RcyByte_all.CopyTo(result, 0); RcvBytes_new.CopyTo(result, RcyByte_all.Length); RcvBytes = result; //lIntLen = sport.Read(RcvBytes, 0, RcvBytes.Length); if (RcvBytes.Length < 25) { return; } } params1 = Common.GetObsParams(RcvBytes); } else { char[] RcvBytes_old = new char[sport.BytesToRead]; Thread.Sleep(3000); int lIntLen = sport.Read(RcvBytes_old, 0, RcvBytes_old.Length); if (params1 != null) { params1 = null; } //从串口获取数据 params1 = new ObsParams(); // 定义到数据库文件,应该是一样的 if (lIntLen < 117) { char[] RcyByte_all = RcvBytes_old; sp = sport.PortName; stationName = GetEquipNo(sp); StationNo = GetStationNo(sp); char[] RcvBytes_new =new char[sport.BytesToRead]; lIntLen = sport.Read(RcvBytes_new, 0, RcvBytes_new.Length); char[] result = new char[RcyByte_all.Length + RcvBytes_new.Length]; RcyByte_all.CopyTo(result, 0); RcvBytes_new.CopyTo(result, RcyByte_all.Length); RcvBytes_old = result; } string RcvBytes_string = new string(RcvBytes_old); params1 = Common.GetObsParams_old(RcvBytes_string); //lIntLen = sport.Read(RcvBytes, 0, RcvBytes.Length); if (RcvBytes_old.Length < 117) { return; } } if (params1 == null) { return; } params1.StationName = stationName; int.TryParse(StationNo, out params1.StationNO); // int ret = DAO.Exist(params1.StationName, params1.ObsTime);// 判断是否有重复的数据 //if (ret<1) //{ DAO.InsertData(params1); try { ObsParams parameter_lg =new ObsParams(); ObsParams parameter_yp = new ObsParams(); ObsParams parameter_gly = new ObsParams(); ObsParams parameter_zhtb = new ObsParams(); ObsParams parameter_wwz = new ObsParams(); ObsParams parameter_swzy = new ObsParams(); ObsParams parameter_jsd = new ObsParams(); ObsParams parameter_hj = new ObsParams(); ObsParams parameter_tc = new ObsParams(); if (params1.StationNO != null) { // Member.obsParamsList.Add(params1); switch (Convert.ToInt32(params1.StationNO)) { case 1: Member.parameter_lg = params1; break; case 2: Member.parameter_yp = params1; break; case 3: Member.parameter_jsd = params1; break; case 4: Member.parameter_zhtb = params1; break; case 5: Member.parameter_tc = params1; break; case 6: Member.parameter_swzy = params1; break; case 7: Member.parameter_hj = params1; break; case 8: Member.parameter_gly = params1; break; case 9: Member.parameter_wwz = params1; break; default: //Member.parameter_wwz = params1; break; } } } catch (System.Exception ex) { } /*case 1 Member.parameter_lg = params1; endswitc if (Convert.ToInt32(params1.StationNO) == 1) { Member.parameter_lg = params1; } if (Convert.ToInt32(params1.StationNO) == 2) { Member.parameter_yp = params1; } if (Convert.ToInt32(params1.StationNO) == 3) { Member.parameter_jsd = params1; } if (Convert.ToInt32(params1.StationNO) == 4) { Member.parameter_zhtb = params1; } if (Convert.ToInt32(params1.StationNO) == 5) { Member.parameter_tc = params1; } if (Convert.ToInt32(params1.StationNO) == 6) { Member.parameter_swzy = params1; } if (Convert.ToInt32(params1.StationNO) == 7) { Member.parameter_hj = params1; } if (Convert.ToInt32(params1.StationNO) == 8) { Member.parameter_gly = params1; } if (Convert.ToInt32(params1.StationNO) == 9) { Member.parameter_wwz = params1; }*/ //frmobsdatall.FenpeiData(params1); // 判断是否大于1000,数据是否增加 biyonghrng xinjia //if (params1.Hour==0 && params1.Minute==0) //{ // GHISum1000 = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // GTISum1000 = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; //} //else //{ // if (params1.GHI >= 1000 || params1.GTI >= 1000) // { // GHISum1000[params1.StationNO-1] = GHISum1000[params1.StationNO-1] + params1.GHI / 1000000*20; // GTISum1000[params1.StationNO-1] = GTISum1000[params1.StationNO-1] + params1.GTI / 1000000*20; // DAO.InsertData1000(params1,GHISum1000,GTISum1000); // } //} ////// //MysqlConnection.InsertToDb(params1); //InsertFirstDataDao.readHistoryData(); //Ms_SQLDAO.InsertToDb(params1); //} if (stationName == selectStationNo) { MethodInvoker mi = new MethodInvoker(SetControlsProp); BeginInvoke(mi); } }