本文目录一览:
从Python调用CAPL函数问题,怎么解决
你没有说具体问题是什么,以下介绍一下capl常见问题
一、capl程序组织
- 全局变量的声明
- 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。
- 事件处理
- 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.
- 事件处理不能有返回值。
- 用户定义函数
- 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 unsignedbyte
8bit unsignedint
16bit signedword
16bit unsignedlong
32bit signeddword
32bit unsignedfloat
64bit signeddouble
64bit signedmessage
一条通信消息timer
秒级计时器msTimer
毫秒级计时器
四、运算符
(雷同C语言,只列部分)
- 位操作部分:
<<=
compound assignment(left shift)>>=
compound assignment(right shift)&=
AND^=
XOR|=
OR
五、控制结构
if()
{ } else { }
switch()
{ case : default: }
while()
{}
do{}while();
for(;;){}
break continue
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
进入到调用的模块里函数。