winIDEA SDK
Loading...
Searching...
No Matches
test_batch_access.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# (c) TASKING Germany GmbH, 2023
from typing import List
import isystem.connect as ic
winidea_id = ''
def test_batchAccess():
connMgr = ic.ConnectionMgr()
connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
dataCtrl = ic.CDataController(connMgr)
dbgCtrl = ic.CDebugFacade(connMgr)
ACCESS_FLAG = ic.SBatchAccessHeader.flStopResume
SYMBOL_NAMES = ["mainLoopCounter", "g_char"]
VALUES_TO_WRITE = [6, 42]
NUM_ITEMS = len(SYMBOL_NAMES)
NUM_RUNS = 3
INTERVAL_US = 50000
baHeader = ic.SBatchAccessHeader()
baItemsRead = ic.VectorBatchAccessItem()
baItemsWrite = ic.VectorBatchAccessItem()
baResults = ic.VectorBatchAccessResult(NUM_ITEMS * NUM_RUNS)
baHeader.m_dwFlags = ACCESS_FLAG
baHeader.m_dwNumItems = NUM_ITEMS
baHeader.m_dwNumRuns = NUM_RUNS
baHeader.m_qwRunInterval = INTERVAL_US
# Determine BA memory locations we are interested in
symbolsInfo: List[ic.CSymbolInfo] = []
for index, symName in enumerate(SYMBOL_NAMES):
symbolInfo = dbgCtrl.getSymbolInfo(ic.IConnectDebug.fRealTime, symName)
symbolsInfo.append(symbolInfo)
# prepare BA read items
item = ic.SBatchAccessItem()
item.m_byFlags = ic.SBatchAccessItem.flRead
item.m_bySize = symbolInfo.getSizeMAUs()
item.m_byMemArea = symbolInfo.getMemArea()
item.m_aAddress = symbolInfo.getAddress()
baItemsRead.push_back(item)
# prepare BA write items
item = ic.SBatchAccessItem()
item.m_byFlags = ic.SBatchAccessItem.flWrite
item.m_bySize = symbolInfo.getSizeMAUs()
item.m_byMemArea = symbolInfo.getMemArea()
item.m_aAddress = symbolInfo.getAddress()
# set item data (write) values
ic.CDataController.setByte(item.m_abyData, 0, VALUES_TO_WRITE[index])
ic.CDataController.setByte(item.m_abyData, 1, 0)
ic.CDataController.setByte(item.m_abyData, 2, 0)
ic.CDataController.setByte(item.m_abyData, 3, 0)
baItemsWrite.push_back(item)
print(f"Performing batch access write...")
# we are not interested in batch access timestamps, hence ignore `batchAccess` return value
dataCtrl.batchAccess(ACCESS_FLAG,
baHeader,
baItemsWrite,
baResults)
for index, baResult in enumerate(baResults):
baResult: ic.SBatchAccessItemResult
if baResult.m_byResult != ic.SBatchAccessItemResult.resOK:
print(f"WARNING: Batch write {index} failed!")
print(f"Performing batch access read...")
baResults = ic.VectorBatchAccessResult(NUM_ITEMS * NUM_RUNS)
dataCtrl.batchAccess(ACCESS_FLAG,
baHeader,
baItemsRead,
baResults)
for index, baResult in enumerate(baResults):
baResult: ic.SBatchAccessItemResult
if baResult.m_byResult != ic.SBatchAccessItemResult.resOK:
print(f"WARNING: Batch read {index} failed!")
else:
print(f"\tItem {index} ('{SYMBOL_NAMES[index % NUM_ITEMS]}): "
f"data: {ic.CDataController.getByte(baResult.m_abyData, 0)}")
if __name__ == "__main__":
test_batchAccess()