Example #1
0
        private EnergyIndex GetAt(DateTime date, TeleInfoData[] datas)
        {
            EnergyIndex index = new EnergyIndex();

            TeleInfoData data = datas.Where(e => e.Date > date).OrderBy(e => e.Date).FirstOrDefault();

            if (data != null)
            {
                index.PeekHours = data.PeekHourCpt / 1000;
                index.LowHours  = data.LowHourCpt / 1000;
            }

            return(index);
        }
Example #2
0
        /// <summary>
        /// Gets First index of the date
        /// </summary>
        /// <param name="date">date to get</param>
        /// <returns>first index of the date</returns>
        public EnergyIndex GetEnergyIndexesAt(DateTime date)
        {
            EnergyIndex index = new EnergyIndex();

            var          collection = this.database.GetCollection <TeleInfoData>(this.energyCol);
            TeleInfoData data       = collection.AsQueryable().Where(e => e.Date > date).OrderBy(e => e.Date).FirstOrDefault();

            if (data != null)
            {
                index.PeekHours = data.PeekHourCpt / 1000;
                index.LowHours  = data.LowHourCpt / 1000;
            }

            return(index);
        }
Example #3
0
        /// <summary>
        /// Read the TeleInfo frame
        ///
        /// Decode TeleInfo Data Sample frame :
        /// Start with STX (0x02)
        /// Serial number :  ADCO SerialNumber C
        /// Type of billing : OPTARIF HC.. <
        /// Level of power : ISOUSC 30 9
        /// Low Hour (in WH) : HCHC 034172198 )
        /// Peek Hour (IN WH) : HCHP 036245714 3
        /// current period : PTEC HP..
        /// Instant intensity (in A) : IINST 003 Z
        /// Max intensoty (in A) : IMAX 029 J
        /// Apparent Power (in VA) : PAPP 00820 +
        /// Warning over intensity ( in A) : ADPS
        /// HHPHC A ,
        /// MOTDETAT 000000 B
        /// End with ETX (0x03)
        /// </summary>
        private void ReadData()
        {
            Console.WriteLine("Start TeleInfoReader ReadData");
            string line = this.ReadLine();

            // Waiting for the first line of a frame
            while (!line.StartsWith("ADCO"))
            {
                line = this.ReadLine();
            }

            // Here we are at the start of a frame, we read each lines until the next frame
            TeleInfoData infoData = new TeleInfoData()
            {
                Date = DateTime.Now
            };

            do
            {
                string[] datas = line.Split(new char[] { ' ' });

                switch (datas[0])
                {
                case "ADCO":
                    infoData.MeterId = datas[1];
                    break;

                case "ISOUSC":
                    infoData.AccountIntensity = int.Parse(datas[1]);
                    break;

                case "HCHC":
                    infoData.LowHourCpt = decimal.Parse(datas[1]);
                    break;

                case "HCHP":
                    infoData.PeekHourCpt = decimal.Parse(datas[1]);
                    break;

                case "IINST":
                    infoData.ActualIntensity = int.Parse(datas[1]);
                    break;

                case "IMAX":
                    infoData.MaxIntensity = int.Parse(datas[1]);
                    break;

                case "PAPP":
                    infoData.ApparentPower = int.Parse(datas[1]);
                    break;

                case "ADPS":
                    infoData.HasExceed = true;
                    break;
                }

                line = this.ReadLine();
            }while (!line.StartsWith("ADCO"));

            // Launch the reading Event
            if (this.TeleInfoDataRead != null)
            {
                this.TeleInfoDataRead.BeginInvoke(infoData, null, null);
            }

            Console.WriteLine("Stop TeleInfoReader ReadData");
        }
Example #4
0
 /// <summary>
 /// TeleInfo reader event
 /// </summary>
 /// <param name="data">TeleInfo data received</param>
 private void TeleInfoDataRead(TeleInfoData data)
 {
     waiter.Set();
     this.teleInfoSave.AddData(data);
     Console.WriteLine("Date : {2}, HP : {0}, HC : {1}", data.PeekHourCpt, data.LowHourCpt, data.Date.ToShortTimeString());
 }