import random
import isystem.connect as ic
winidea_id = ''
def test_readWriteMemory():
connMgr = ic.ConnectionMgr()
connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
dataCtrl = ic.CDataController(connMgr)
addCtrl = ic.CAddressController(connMgr)
DATA = [random.randint(0, 100),
random.randint(0, 100),
random.randint(0, 100),
random.randint(0, 100)]
NUM = len(DATA)
START_ADDRESS = addCtrl.getVariableAddress("mainLoopCounter").getAddress()
print(f"Writing {NUM} bytes to address: {hex(START_ADDRESS)}: {DATA}")
wData = ic.VectorBYTE(DATA)
dataCtrl.writeMemoryNAI(ic.IConnectDebug.fRealTime,
0,
START_ADDRESS,
NUM, 1,
wData)
print(f"Reading {NUM} bytes, starting at address: {hex(START_ADDRESS)}")
rData = dataCtrl.readMemory(ic.IConnectDebug.fRealTime,
0,
START_ADDRESS,
NUM, 1)
for index, data in enumerate(rData[:NUM]):
print(f"\tByte {index}: read value: {data}, access status: {rData[index + NUM]}")
if __name__ == "__main__":
test_readWriteMemory()