winIDEA SDK
test_read_write_memory.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import random
6import isystem.connect as ic
7
8
9winidea_id = ''
10
11
12def test_readWriteMemory():
13 connMgr = ic.ConnectionMgr()
14 connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
15
16 dataCtrl = ic.CDataController(connMgr)
17 addCtrl = ic.CAddressController(connMgr)
18
19 # 4 bytes, 32 bit
20 DATA = [random.randint(0, 100),
21 random.randint(0, 100),
22 random.randint(0, 100),
23 random.randint(0, 100)]
24 NUM = len(DATA)
25 START_ADDRESS = addCtrl.getVariableAddress("main_loop_counter").getAddress()
26
27 print(f"Writing {NUM} bytes to address: {hex(START_ADDRESS)}: {DATA}")
28 wData = ic.VectorBYTE(DATA)
29 # write 4 bytes without getting access status info ('NAI')
30 dataCtrl.writeMemoryNAI(ic.IConnectDebug.fRealTime,
31 0,
32 START_ADDRESS,
33 NUM, 1, # NUM of bytes, 1 byte per MAU
34 wData)
35
36 print(f"Reading {NUM} bytes, starting at address: {hex(START_ADDRESS)}")
37 rData = dataCtrl.readMemory(ic.IConnectDebug.fRealTime,
38 0,
39 START_ADDRESS,
40 NUM, 1)
41 for index, data in enumerate(rData[:NUM]):
42 # bytes, (data + access status)
43 print(f"\tByte {index}: read value: {data}, access status: {rData[index + NUM]}")
44
45
46if __name__ == "__main__":
47 test_readWriteMemory()