Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

New Contributor II

I am running into an issue when trying to run PSoC4/SWD/Python_Ex/ with python 3.

The issue is in the PSoC4_EraseAll()

  #original code  hResult = pp.PSoC4_WriteProtection(buffer(data1), buffer(data2))

hResult = pp.PSoC4_WriteProtection(memoryview(data1), memoryview(data2))  # port to python 3

From what I googled, memoryview is the replacement for buffer in python 3 but this change produces a windows exception.

  hResult = pp.PSoC4_WriteProtection(memoryview(data1), memoryview(data2))

  File "<COMObject PSoCProgrammerCOM.PSoCProgrammerCOM_Object>", line 2, in PSoC4_WriteProtection

  File "C:\Program Files (x86)\Python38-32\lib\site-packages\win32com\client\", line 287, in _ApplyTypes_

    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -1114130), None)

I am guessing memoryview is not a drop in replacement?

1 Solution
New Contributor II

I have it working now. This is what I had to do.

First, I was using python 3 32-bit. I switched to 64-bit. I am not sure if the 32-bit was the main problem but I think it might be. I haven't gone back to test it.

Second, change to this,

  # Move to OPEN from PROTECTED. It automatically erases Flash and its Protection bits.

        flashProt = []  # do not care in PROTECTED mode

        chipProt = []

        for i in range(0, 1):


        data1 = bytearray(flashProt)

        data2 = bytearray(chipProt)

        hResult = pp.PSoC4_WriteProtection(data1, data2)

Unfortunately, I cannot explain why all the others fail, but with this, I can program when the protection bits are set.

View solution in original post

7 Replies