public void erase() { Console.WriteLine("Erasing CPU... "); foreach (wBlockType blockType in Enum.GetValues(typeof(wBlockType))) { ushort[] blockList = new ushort[MAX_BLOCK]; int blockCount = blockList.Length; int result; result = MyClient.ListBlocksOfType((int)blockType, blockList, ref blockCount); if (result == 0) { for (int i = 0; i < blockCount; i++) { if (blockType != wBlockType.SFC && blockType != wBlockType.SFB) { result = MyClient.Delete((int)blockType, blockList[i]); if (result == 0) { Console.WriteLine("Deleted " + blockType + blockList[i]); } else { string error = "Could not delete " + blockType + blockList[i]; throw new wPlcException(error, result); } } } } else { string error = "Failed to list blocks"; throw new wPlcException(error, result); } } Console.WriteLine("Done!"); }