#!/usr/bin/python # -*- coding: utf-8 -*- """ @Title: Python Remote API example on how to use T32_ExecuteCommand() and T32_ExecuteFunction() with ctypes @Description: Python Remote API example on how to use T32_ExecuteCommand() and T32_ExecuteFunction() with ctypes TRACE32's configuration file "config.t32" has to contain these lines: RCL=NETASSIST PORT=20000 The port value may be changed but has to match with the port number used in this python script. Example output using t32marm: The current CPU is b'NONE' The current CPU is b'CortexA9MPCore' @Keywords: ctypes, Python, T32_ExecuteCommand, T32_ExecuteFunction @Copyright: (C) 1989-2015 Lauterbach GmbH, licensed for use with TRACE32(R) only $Id: t32api.py 116756 2020-01-27 07:42:44Z jvogl $ """ import platform import ctypes import libhelper def check_error(error): """Raises a ValueError if error is not zero.""" if error != 0: raise ValueError(f"{error}") if __name__ == "__main__": # configuration cpufamily = "RISCV" cpu = "RV64" t32api = libhelper.load_dll() libhelper.declare_fnc_args_ret(t32api) # configuration check_error(t32api.T32_Config(b"NODE=", b"localhost")) check_error(t32api.T32_Config(b"PORT=", b"20000")) check_error(t32api.T32_Config(b"PACKLEN=", b"1024")) # init check_error(t32api.T32_Init()) check_error(t32api.T32_Attach(1)) try: c_buffer = (ctypes.c_char * 4096)() c_result_type = ctypes.c_uint32() # ping check_error(t32api.T32_Ping()) check_error(t32api.T32_ExecuteFunction(b"SOFTWARE.VERSION()", c_buffer, len(c_buffer), c_result_type)) print(f"SOFTWARE.VERSION(): {c_buffer.value.decode()}") # Check CPUFAMILY() check_error(t32api.T32_ExecuteFunction(b"CPUFAMILY()", c_buffer, len(c_buffer), c_result_type)) if c_buffer.value != cpufamily.encode(): raise ValueError(f"CPUFAMILY(): Expected '{cpufamily}' got '{c_buffer.value.decode()}'") # get current CPU error = t32api.T32_ExecuteFunction(b"CPU()", c_buffer, len(c_buffer), c_result_type) if error != 0: raise ValueError(error, c_buffer.value) else: print(f"The current CPU is {c_buffer.value}") # set CPU (works with t32marm, adjust CPU for other architectures) error = t32api.T32_ExecuteCommand(f"SYStem.CPU {cpu}".encode(), c_buffer, len(c_buffer)) if error != 0: raise ValueError(error, c_buffer.value.decode()) # get CPU again error = t32api.T32_ExecuteFunction(b"CPU()", c_buffer, len(c_buffer), c_result_type) if error != 0: raise ValueError(error, c_buffer.value) else: print(f"The current CPU is {c_buffer.value.decode()}") finally: # exit check_error(t32api.T32_Exit())