//
        // Download the TrendLog in many blocks of NbRecordByStep values
        // it could be a (ligh) problem with sliding windows logs with high speed
        // modification : it will lost some values and duplicate some others.
        //
        private void DownloadFullTrendLog()
        {
            uint ItemCount;
            int  Idx;

            try
            {
                // First index is 1
                Idx = 1;

                do
                {
                    byte[] TrendBuffer;
                    ItemCount = (uint)Math.Min(NbRecordsByStep, Logsize - Idx + 1);
                    if (Idx == 951)
                    {
                        Idx = 951;
                    }

                    //read
                    if ((comm.ReadRangeRequest(adr, object_id, (uint)Idx, ref ItemCount, out TrendBuffer) == false) || (ItemCount <= 0))
                    {
                        Trace.TraceError("Couldn't load log data");
                        BeginInvoke(new Action <bool>(UpdateEnd), false);
                        return;
                    }

                    int len = 0;
                    for (int itm = 0; itm < ItemCount; itm++)
                    {
                        //decode
                        BacnetLogRecord[] records;
                        int l;
                        if ((l = System.IO.BACnet.Serialize.Services.DecodeLogRecord(TrendBuffer, len, TrendBuffer.Length - len, CurvesNumber, out records)) < 0)
                        {
                            Trace.TraceError("Couldn't decode log data");
                            BeginInvoke(new Action <bool>(UpdateEnd), false);
                            return;
                        }
                        len += l;

                        //update interface
                        for (int i = 0; i < records.Length; i++, Idx++)
                        {
                            if (records[i].type == BacnetTrendLogValueType.TL_TYPE_UNSIGN || records[i].type == BacnetTrendLogValueType.TL_TYPE_SIGN || records[i].type == BacnetTrendLogValueType.TL_TYPE_REAL)
                            {
                                Pointslists[i].Add(new XDate(records[i].timestamp), (double)Convert.ChangeType(records[i].Value, typeof(double)));
                            }
                            else
                            {
                                Pointslists[i].Add(new XDate(records[i].timestamp), double.NaN);
                            }

                            AddToList(Idx, records[i].timestamp, records[i].type, records[i].Value, records[i].statusFlags.ConvertToInt());
                        }
                    }

                    // Update progress bar
                    BeginInvoke(new Action <int>(UpdateProgress), (int)ItemCount);
                } while (((Idx + 1) < Logsize) && (StopDownload == false));

                BeginInvoke(new Action <bool>(UpdateEnd), true);
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error during log data: " + ex.Message);
                try
                {
                    // Exception if Form is closed
                    BeginInvoke(new Action <bool>(UpdateEnd), false);
                }
                catch { }
            }
        }