private int PSoC4_EraseAll()
        {
            int    hr;
            string m_sLastError;

            //Check chip level protection here. If PROTECTED then move to OPEN by PSoC4_WriteProtection() API.
            //Otherwise use PSoC4_EraseAll() - in OPEN/VIRGIN modes.
            hr = PSoC4_IsChipNotProtected();
            if (IsSuccess(hr)) //OPEN mode
            {
                //Erase All - Flash and Protection bits. Still be in OPEN mode.
                hr = Programmer.PSoC4_EraseAll(out m_sLastError);
            }
            else
            {                                                     //Move to OPEN from PROTECTED. It automatically erases Flash and its Protection bits.
                byte[] flashProt = new byte[] { };                // do not care in PROTECTED mode
                byte[] chipProt  = new byte[] { CHIP_PROT_OPEN }; //move to OPEN

                hr = Programmer.PSoC4_WriteProtection(flashProt, chipProt, out m_sLastError);
                if (!IsSuccess(hr))
                {
                    Log.PrintLog(this, m_sLastError, LogDetailLevel.LogRelevant);
                    return(hr);
                }

                //Need to reacquire chip here to boot in OPEN mode.
                //ChipLevelProtection is applied only after Reset.
                hr = Programmer.DAP_Acquire(out m_sLastError);
            }
            return(hr);
        }