import isystem.connect as ic
winidea_id = ''
def test_erase():
connMgr = ic.ConnectionMgr()
connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
ideCtrl = ic.CIDEController(connMgr)
devName = "ST STM32F4xxxG_1024KB"
eraseSize = 0x4000
optCtrl = ic.COptionController(connMgr, "/iOPEN/Data.UMI.Devices.Devices")
devIndex = optCtrl.index_of("Name",devName)
print("Index of the item whose 'Name' attribute has value " + devName + f": {devIndex}")
storageCtrl = ic.CStorageDeviceFactory.makeDevice(connMgr, ic.EStorageDevice_EmbeddedFlashDevice, devIndex)
print(f"Erasing entire device with index {devIndex}...")
storageCtrl.erase(ic.IConnectUMI.wProgDevice)
print(f"Erasing first {int(eraseSize)} bytes of a device with index {devIndex}...")
addUrl = f"/iOPEN/Data.UMI.Devices.Devices[{devIndex}].DeviceAddress"
add = ideCtrl.getOptionInt(addUrl)
storageCtrl.erase(ic.IConnectUMI.wProgDevice, add, int(eraseSize))
if __name__ == "__main__":
test_erase()