Код: Выделить всё
func = canoe.CAPL.GetFunction('MyExportedCaplFunc') # gets the exported CAPL function
func.Call() # tries to execute it
< /code>
[b] Проблема: < /strong> < /p>
[*] Код питона выполняет и не сообщает об ошибках. /> < /li>
Если я перезагружаю ядро ноутбука, а затем нажимаю «повторная попытка» на каноэ
, оставшийся код после выполнения функции (основная проблема после вызова функции, на мой взгляд) < /p>
< /li>
< /ul>
Я не уверен, что это вызывает этот сервер. Automation.
Что я попробовал: [/b]
Ожидание/задержка в питоне после вызова com.
Вызовет функцию после подтверждения инициализации через oninit. Stop () или остановка измерения - Popup по -прежнему появляется после
call().
< /li>
< /ul>
Кто -нибудь видел это и нашел надежное решение? Есть ли шаблон, чтобы безопасно запустить экспортируемые функции CAPL через Python Com без блокировки графического интерфейса/основного потока каноэ?class MeasurementEventHandler:
def __init__(self):
self.capl_func = None
self.on_init = False
def OnInit(self):
# This method is called by CANoe when measurement init finishes
print("OnInit event fired. Obtaining CAPL function...")
self.capl_func = c.CAPL.GetFunction("COMTest_WriteWindow") # Replace "square" with your function name
self.on_init = True
# Create CANoe application and get Measurement object
c = Dispatch("CANoe.Application")
measurement = c.Measurement
# Attach event handler for OnInit event
handler = WithEvents(measurement, MeasurementEventHandler)
# Start measurement to trigger OnInit event asynchronously
c.CAPL.Compile()
measurement.Start()
# Wait for OnInit event with message pumping
timeout = 20
start = time.time()
while not handler.on_init and (time.time() - start < timeout):
pythoncom.PumpWaitingMessages()
time.sleep(0.1)
if not handler.on_init:
raise Exception("Timeout waiting for OnInit event")
# Now safely call the CAPL function acquired in OnInit
print("Calling CAPL function captured in OnInit...")
handler.capl_func.Call()
print("CAPL function call completed.")
measurement.Stop()
Код: Выделить всё
includes
{
}
variables
{
}
MainTest(){
COMTest_WriteWindow();
}
export void COMTest_WriteWindow()
{
write("Function called successfully");
}
on init class (object)
При последнем выполнении
Сервер занят всплывающее окно
Подробнее здесь: https://stackoverflow.com/questions/797 ... apl-functi