예제 #1
0
        /// <summary>
        ///   Sends the erase command for BlockID: <paramref name="startBlock" /> and onwards for <paramref name="blockCount" />
        ///   <exception cref="DeviceError">If Device is not initalized or there is a fatal USB error</exception>
        ///   <exception cref="ArgumentException">If there is a problem with your block count settings</exception>
        /// </summary>
        /// <param name="startBlock"> Starting blockID </param>
        /// <param name="blockCount"> Block count (Small blocks!) if set to 0 full device erase will be done </param>
        /// <param name="verboseLevel"> Specifies if you want alot of information on erase errors or just a erase error (default = only print write error without details) </param>
        public void Erase(uint startBlock, uint blockCount, int verboseLevel = 0)
        {
            CheckDeviceState();
            PrintARMVersion();
            AbortRequested = false;
            var     sw = Stopwatch.StartNew();
            XConfig xConfig;

            Init(out xConfig);
            PrintXConfig(xConfig, verboseLevel);
            blockCount = _xcfg.FixBlockCount(startBlock, blockCount);
            var last = startBlock + blockCount - 1;

            UpdateStatus(string.Format("Erasing blocks 0x{0:X} -> 0x{1:X}", startBlock, last));
            for (var block = startBlock; block <= last; block++)
            {
                if (AbortRequested)
                {
                    sw.Stop();
                    UpdateStatus(string.Format("Erase aborted after {0:F0} Minutes and {1:F0} Seconds!", sw.Elapsed.TotalMinutes, sw.Elapsed.Seconds));
                    break;
                }
                UpdateProgress(block, last);
                EraseBlock(block, verboseLevel);
            }
            if (AbortRequested)
            {
                return;
            }
            sw.Stop();
            UpdateStatus(string.Format("Erase completed after {0:F0} Minutes and {1:F0} Seconds!", sw.Elapsed.TotalMinutes, sw.Elapsed.Seconds));
            DeInit();
            Release();
        }