本文目錄一覽:
從Python調用CAPL函數問題,怎麼解決
你沒有說具體問題是什麼,以下介紹一下capl常見問題
一、capl程序組織
1、全局變量的聲明
–you declare variables that can be read or changed by any part of your CAPL program.
在程序的任何部分都可以讀取和修改。
–It is a good idea to declare messages and timers in this section.
適合定義messages和timers。
2、事件處理
–Event procedures are blocks of code that are executed when an event occurs.
事件發生時執行。
–CAPL allows you to define event procedures for several different kinds of events.
可以為多個不同的事件定義事件處理
–Most of your program code will be in event procedures, since most actions are performed after an event, such as a message being received on the CAN bus.
大多數代碼都寫在事件處理中。
–Event procedures cannot return a value.
事件處理不能有返回值。
3、用戶定義函數
–Your programs can contain procedures that can be used to complement CAPL』s built-in functions.
–These procedures can contain any legal CAPL code and are globally accessible.
–Putting frequently-used code in a procedure makes programs more efficient.
–User-defined functions can return a value of any simple type.
可以有返回值。
二、CAPL文件類型
★兩種
*.CAN 包含CAPL程序(ASCII 文本格式)
*.CBF 編譯.CAN文件得到(二進制文件),只能被CANslyzer或CANoe執行。
三、CAPL數據類型
char 8bit unsigned
byte 8bit unsigned
int 16bit signed
word 16bit unsigned
long 32bit signed
dword 32bit unsigned
float 64bit signed
double 64bit signed
message 一條通信消息
timer 秒級計時器
msTimer 毫秒級計時器
四、運算符
(雷同c語言,只列部分)
位操作部分:
= compound assignment(left shift)
= compound assignment(right shift)
= AND
^= XOR
|= OR
五、控制結構
1、if()
{
}
else
{
}
2、switch()
{
case :
default:
}
3、while()
{}
4、do{}while();
5、for(;;){}
6、break continue
7、this
Python如何調用自定義類中的函數?
定義一個函數只給了函數一個名稱,指定了函數里包含的參數,和代碼塊結構。這個函數的基本結構完成以後,你可以通過另一個函數調用執行,也可以直接從Python提示符執行。
如下實例調用了printme()函數:
複製代碼 代碼如下:#!/usr/bin/python
# Function definition is here
def printme( str ):
“打印任何傳入的字符串”
print str;
return;
# Now you can call printme function
printme(“我要調用用戶自定義函數!”);
printme(“再次調用同一函數”);
#以上實例輸出結果:
#我要調用用戶自定義函數!
#再次調用同一函數
python如何定義和調用函數
1、函數定義
①使用def關鍵字定義函數
②
def 函數名(參數1.參數2.參數3…):
“””文檔字符串,docstring,用來說明函數的作用”””
#函數體
return 表達式
注釋的作用:說明函數是做什麼的,函數有什麼功能。
③遇到冒號要縮進,冒號後面所有的縮進的代碼塊構成了函數體,描述了函數是做什麼的,即函數的功能是什麼。Python函數的本質與數學中的函數的本質是一致的。
2、函數調用
①函數必須先定義,才能調用,否則會報錯。
②無參數時函數的調用:函數名(),有參數時函數的調用:函數名(參數1.參數2.……)
③不要在定義函數的時候在函數體裏面調用本身,否則會出不來,陷入循環調用。
④函數需要調用函數體才會被執行,單純的只是定義函數是不會被執行的。
⑤Debug工具中Step into進入到調用的函數里,Step Into My Code進入到調用的模塊里函數。
原創文章,作者:GFOP,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/149480.html