我已经创建了一个小型机器人框架测试套件,它将与trace32劳特巴赫进行通信。我的想法是使用一个循环来运行不同的函数名。每次循环,它都会在Trace32后面的批处理中创建一个断点。我写了一个简单的Python脚本作为机器人框架中的库。
test.robot文件
import os
*** Settings ***
Documentation simple test script to control Trace32
Library Collections
Library can.Trace32
Suite Setup
Suite Teardown
*** Variables ***
${temp} 1
*** Test Cases ***
Check Input and Output
[Documentation] test script
[Setup]
#Retrive Data . This list has 5 values
${MainList} Create List
#start debugger
start Debugger
#connect debugger
Connect Debugger
#Iterate 5 times
FOR ${UserAttribute} IN @{MainList}
#sleep 1 sec
Sleep 1 seconds
#call for breakpoint
break Debugger
${temp} +=1
END
Disconnect Debugger
[Teardown]
和trace 32脚本文件:
import time
import ctypes
from ctypes import c_void_p
import enum
T32_DEV = 1
class Trace32:
def start_Debugger(self):
self.t32api = ctypes.cdll.LoadLibrary('D:/test/api/python/t32api64.dll')
self.t32api.T32_Config(b"NODE=",b"localhost")
self.t32api.T32_Config(b"PORT=",b"20000")
self.t32api.T32_Config(b"PACKLEN=",b"1024")
rc = self.t32api.T32_GetChannelSize()
ch1 = ctypes.create_string_buffer(rc)
self.t32api.T32_GetChannelDefaults(ctypes.cast(ch1,ctypes.c_void_p))
ch2 = ctypes.create_string_buffer(rc)
self.t32api.T32_GetChannelDefaults(ctypes.cast(ch2,ctypes.c_void_p))
self.t32api.T32_SetChannel(ctypes.cast(ch2,c_void_p))
def Connect_Debugger(self):
rc = self.t32api.T32_Init()
rc = self.t32api.T32_Attach(T32_DEV)
def breakpoint_Debugger(self):
rc = self.t32api.T32_Ping()
time.sleep(2)
rc = self.t32api.T32_Cmd(b"InterCom M7_0 Break")
time.sleep(3)
rc = self.t32api.T32_Cmd(b"InterCom M7_0 Go")
time.sleep(2)
rc = self.t32api.T32_Cmd(b"InterCom M7_0 break.Set My_func")
time.sleep(2)
def Disconnect_Debugger(self):
rc = self.t32api.T32_Exit()
在robot文件中,我调用start Debugger
和Connect Debugger
函数来启动和连接调试器。我希望self.t32api
是全局的。这样我就可以多次调用break_Debugger
来放置断点。
但不幸的是,我只能在第一次迭代中设置断点。在第二次迭代中,断点不起作用。如何使self.t32api
全局化,直到robot文件完全执行?
1条答案
按热度按时间njthzxwz1#
只需在
Trace32
类的构造函数中初始化它,因此只要Trace32
对象存在,它就会持续存在,然后我们还可以删除start_Debugger()
。