Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        internal void InsertXd100eData(int deviceID, Xd100eData data)
        {
            string columns = //string.Empty;
                             "DeviceID, DT,";
            string values =  // string.Empty;
                            string.Format("{0}, '{1}',", deviceID, data.DT.ToString());

            for (int i = Xd100eData.BeginChannelNO; i <= Xd100eData.EndChannelNO; i++)
            {
                columns += "ai" + i + ",";
                values  += data.GetChannelDataAI(i).ToString() + ",";

                columns += "di" + i + ",";
                values  += (data.GetChannelDataDI(i) ? "1" : "0") + ",";
            }


            columns += "ir,sr,REx,";
            values  += string.Format("{0}, {1}, '{2}',", data.IR, data.SR, data.REx);

            //
            //
            columns += "if1, sf1, ih1, sh1,";
            values  += string.Format("{0}, {1}, {2}, {3},", data.IF1, data.SF1, data.IH1, data.SH1);

            columns = RemoveLastChar(columns);
            values  = RemoveLastChar(values);

            string s = string.Format("insert into tblXd100eData({0}) values({1})", columns, values);

            ExecuteScalar(s);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public Xd100eData GetCachedData()
 {
     if (_cachedData == null ||
         _cachedData.IsComplete() ||
         _cachedData.IsTimeout())
     {
         _cachedData = new Xd100eData();
     }
     return(_cachedData);
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="task"></param>
        /// <param name="parseResult"></param>
        public override void OnProcess(ITask task, IParseResult pr)
        {
            if (pr.IsSuccess)
            {
                //Xd100eData data = Xd100eData.GetCachedData();

                Xd100e     xd100eDevice = (Xd100e)task.Device;
                Xd100eData data         = xd100eDevice.GetCachedData();

                Console.WriteLine("ori xd100e id: " + GuidHelper.ConvertToInt32(xd100eDevice.Guid));

                string opera = task.Opera.Name;

                if (StringHelper.Equal(opera, READ_REAL))
                {
                    for (int i = Xd100eData.BeginChannelNO; i <= Xd100eData.EndChannelNO; i++)
                    {
                        int    no          = i;
                        string channelName = GetChannelName(no);

                        float val = Convert.ToSingle(pr.Results[channelName]);
                        val /= 100f;

                        data.SetChannelDataAI(no, val);
                        data.IsSetAI = true;
                    }
                }

                else if (StringHelper.Equal(opera, READ_REAL_DI))
                {
                    //XD100EData data = xd100eDevice.XD100EData;
                    for (int i = Xd100eData.BeginChannelNO; i <= Xd100eData.EndChannelNO; i++)
                    {
                        int    no          = i;
                        string channelName = GetChannelName(no);
                        byte   value       = Convert.ToByte(pr.Results[channelName]);
                        data.SetChannelDataDI(no, value > 0);
                        data.IsSetDI = true;
                    }
                }

                //
                //
                if (data.IsComplete())
                {
                    double ir = 0d, sr = 0d;
                    //bool hasRecuritFluxDevice;
                    string recuritEx = string.Empty;

                    //bool success = GetFluxValues(xd100eDevice, FluxPlace.RecruitSide, out hasRecuritFluxDevice,
                    //    out ir, out sr, out recuritEx);

                    // get kind == fluxdevice device collection
                    //
                    DeviceCollection rDevices = xd100eDevice.Station.Devices.GetDevices(KIND_FLUX_DEVICE);
                    rDevices = Filter(rDevices, FluxPlace.RecruitSide);
                    bool hasRecuritFluxDevice = rDevices.Count > 0;
                    bool hasRecuritFluxData   = rDevices.HasData(HasDataOption.All);
                    if (hasRecuritFluxData)
                    {
                        ir        = Calc(rDevices, "InstantFlux", CalcType.Sum);
                        sr        = Calc(rDevices, "Sum", CalcType.Sum);
                        recuritEx = GetRecuritEx(rDevices);
                    }

                    // get recruite device collection
                    // get recruite data
                    //
                    // get kind == heatdevcie device collection
                    // check has data
                    // [x] get place == first ?
                    // get device gt bt

                    double if1 = 0d, sf1 = 0d, gt1 = 0d, bt1 = 0d, ih1 = 0d, sh1 = 0d;
                    //bool hasFirstFluxDevice;
                    //string firstEx;
                    //bool success2 = GetFluxValues(xd100eDevice, FluxPlace.FirstSide, out hasFirstFluxDevice,
                    //    out if1, out sf1, out firstEx);

                    DeviceCollection hs = xd100eDevice.Station.Devices.GetDevices(KIND);
                    hs = Filter(hs, FluxPlace.FirstSide);

                    bool hasFirstFluxDevice = hs.Count > 0;
                    bool hasFirstFluxData   = hs.HasData(HasDataOption.All);
                    if (hasFirstFluxData)
                    {
                        if1 = Calc(hs, "InstantFlux", CalcType.Sum);
                        sf1 = Calc(hs, "Sum", CalcType.Sum);
                        gt1 = Calc(hs, "GT", CalcType.Avg);
                        bt1 = Calc(hs, "BT", CalcType.Avg);
                        ih1 = Calc(hs, "InstantHeat", CalcType.Sum);
                        sh1 = Calc(hs, "SumHeat", CalcType.Sum);
                    }

                    bool success = true;
                    if (hasRecuritFluxDevice)
                    {
                        if (hasRecuritFluxData)
                        {
                            data.IR  = ir;
                            data.SR  = sr;
                            data.REx = recuritEx;
                        }
                        else
                        {
                            success = false;
                        }
                    }

                    //
                    //
                    if (success)
                    {
                        if (hasFirstFluxDevice)
                        {
                            if (hasFirstFluxData)
                            {
                                // xd100e ai5 == if1
                                //
                                // ai1 - gt1, ai2 - bt1
                                //
                                data.IF1 = if1;
                                data.SF1 = sf1;

                                data.AI5 = Convert.ToSingle(if1);
                                data.AI1 = Convert.ToSingle(gt1);
                                data.AI2 = Convert.ToSingle(bt1);

                                data.IH1 = ih1;
                                data.SH1 = sh1;
                            }
                            else
                            {
                                success = false;
                            }
                        }
                    }

                    if (success)
                    {
                        data.DT = DateTime.Now;
                        xd100eDevice.DeviceDataManager.Last = data;

                        int deviceID = GuidHelper.ConvertToInt32(xd100eDevice.Guid);
                        Console.WriteLine("write xd100e id: " + deviceID);
                        DBI.Instance.InsertXd100eData(deviceID, data);
                    }

                    //if (success && success2)
                    //{
                    //    data.IR = ir;
                    //    data.SR = sr;
                    //    data.REx = recuritEx;

                    //    data.IF1 = if1;
                    //    data.SF1 = sf1;

                    //    if (hasFirstFluxDevice)
                    //    {
                    //        // xd100e ai5 == if1
                    //        //
                    //        // ai1 - gt1, ai2 - bt1
                    //        //
                    //        data.AI5 = Convert.ToSingle(if1);
                    //        data.AI1 = Convert.ToSingle(GetGT1FromCRL_G(xd100eDevice));
                    //        data.AI2 = Convert.ToSingle(GetBT1FromCRL_G(xd100eDevice));
                    //    }

                    //    data.DT = DateTime.Now;
                    //    xd100eDevice.DeviceDataManager.Last = data;

                    //    int deviceID = GuidHelper.ConvertToInt32(xd100eDevice.Guid);
                    //    Console.WriteLine("write xd100e id: " + deviceID);
                    //    DBI.Instance.InsertXd100eData(deviceID, data);
                    //}
                }
            }
        }
Ejemplo n.º 4
0
Archivo: Class1.cs Proyecto: hkiaipc/C3
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public Xd100eData GetCachedData()
 {
     if (_cachedData == null ||
         _cachedData.IsComplete() ||
         _cachedData.IsTimeout())
     {
         _cachedData = new Xd100eData();
     }
     return _cachedData;
 }
Ejemplo n.º 5
0
Archivo: Class1.cs Proyecto: hkiaipc/C3
        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        internal void InsertXd100eData(int deviceID, Xd100eData data)
        {
            string columns = //string.Empty;
                "DeviceID, DT,";
            string values =// string.Empty;
                string.Format("{0}, '{1}',", deviceID, data.DT.ToString());

            for (int i = Xd100eData.BeginChannelNO; i <= Xd100eData.EndChannelNO; i++)
            {
                columns += "ai" + i + ",";
                values += data.GetChannelDataAI(i).ToString() + ",";

                columns += "di" + i + ",";
                values += (data.GetChannelDataDI(i) ? "1" : "0") + ",";
            }

            columns += "ir,sr,REx,";
            values += string.Format("{0}, {1}, '{2}',", data.IR, data.SR, data.REx);

            //
            //
            columns += "if1, sf1, ih1, sh1,";
            values += string.Format("{0}, {1}, {2}, {3},", data.IF1, data.SF1, data.IH1, data.SH1);

            columns = RemoveLastChar(columns);
            values = RemoveLastChar(values);

            string s = string.Format("insert into tblXd100eData({0}) values({1})", columns, values);
            ExecuteScalar(s);
        }