QQ登录

只需一步,快速开始

威纶通触摸屏宏指令自定义函数存储

[ 复制链接 ]

自定义函数存储
在使用宏编辑器时,为了减少定义函数的时间,我们可从内建的函数库搜寻所需的函数。然而,当我们编辑宏时,若有某些特定的函数常常使用,却无法从内建函数库搜寻到时,就可以自行定义所需的函数并储起来。当下次需要再定义相同的函数时,可由  “宏指令库” 呼叫出已储存的函数,方便函数编辑。另外,宏指令库 也大幅提升了用户自订函数的可移植性。建立函数前可先查看现有内建函数或在线函数库是否有现成函数可使用。
具体使用方法为,进入宏指令列表窗口,点击窗口右边按钮“宏指令库..”,以弹出的窗口中如编辑宏一样操作。
在使用宏时,还有些事宜在注意
1. 储存局部变量的空间是4KB,所以各种不同变量类型的最大数组大小为如下:
char  a[4096]
bool  b[4096]
short  c[2048]
int    d[1024]
float  e[1024]
2. 一个  EasyBuider Pro 工程中最多包含  255 个宏指令。
3. 宏指令有可能造成触摸屏宕机,可能的原因为:
宏指令中执行了一个死循环命令   
数组的大小超过了宏指令的变量容量
4. PLC 的通讯速度可能影响宏指令的执行速度。相对的,使用过多的宏指令,可能会造成与  PLC 的通讯速度变慢。
在编译时会出现一些错误提示,下面是错误提示归纳
错误信息的格式:
error C#: error 描述
(# 是错误信息编号)
举例:error C37undeclaredidentifieri
当编译后提示有错误信息时,这个错误的描述内容可以参考错误信息编号。
(C1) 语法  error:“标识符”
出现这个信息时,有许多种可能;
例如:   
macro_commandmain()
char i,123xyz   // 不支持这个变量类型
endmacro_command
(C2)„identifier‟ used without having been initialized (使用的标识符没有初始化)
宏指令必须定义声明的数组变量的大小
例如:
macro_commandmain()
char i
intg    // i 必须为一个数值常数
endmacro_command
(C3)redefinition error : „identifier‟ (标识符被重复定义)
函数名称和变量名称在有效范围内,必须是唯一的。
例如:
macro_commandmain()
intg[10]g   // 重复定义错误
endmacro_command
(C4)function 函数名称  error : „identifier‟ (函数名称定义错误)
保留的关键词和常数,不能被定义为函数名称
例如:
sub intif()  // 函数名称定义错误
(C5)parentheses have not come in pairs (圆括号没有成对的出现)
语句中缺少了  ( or )
举例:
macro_commandmain  ) // 缺少了  (
(C6)illegal expression without matching „if‟ (if 语句中没有合法的表达式)
也就是在 if语句中缺少表达式
(C7)illegal expression (no „then‟) without matching „if‟ (if 语句中缺少了then)
也就是 ifthen 没有成对
(C8)illegal expression (no „end if‟) (if 语句中缺少了 enf if)
缺少了  end if
(C9)illegal „end if‟ without matching „if‟ (end if 语句前缺少了if)
End if语句前缺少了if语句
(C10)illegal „else‟ (不合法的  else 语句)
这个  if 语句的格式为:
if “逻辑表达式” then
else if “逻辑表达式” then    
end if
任何与以上格式不符合的语句,在编译时就会错误。
(C17)illegal expression (no 'for') without matching „next‟ (没有与  next 相配的  for 语句)
for 语句错误:在  next 前,缺少了  for 语句
(C18)illegal variable type (not integer or char) (不合法的变量类型)
变量类型定义错误,此处应为整数类型或字符类型变量
(C19)variable type error
缺少赋值语句
(C20)must be keyword „to‟ or „down‟ (缺少了关键词  “to” 或者  “down”)
缺少了关键词  to 或者  down
(C21)illegal expression (no 'next') (非法的表达式,缺少了  next)
for 语句的格式为:
for “变量” = “初始值” to “结束值” step
next “变数”   
任何与上述格式不符合的语句,编译时会错误。
(C22)„wend‟ statement contains no „while‟
循环缺少  while 关键词,”wend 前面应有  while 关键词
(C23)illegal expression without matching „wend‟
缺少  wend 关键词
while 语句的格式为:
while “逻辑表达式”
wend
任何不符合上述语法的,在编译时会错误。
(C24) 语法  error : „break‟
不合法的  break 语句。break 语句只能在  for 循环、while 循环选择结构中使用。
(C25) 语法  error : „continue‟
不合法的  continue 语句。continue 语句只会在  for 或者  while 语句中出现。
(C26) 语法  error
表达式不正确
(C27) 语法  error
表达式中缺少了一个运算符号可能会造成这个编译错误信息。
例如  :
macro_commandmain( )   
int a, b
for a =0 to 2   
b = 4 +xyz   // 不合法之处:xyz 变量没有被定义
next a
endmacro_command
(C28)must be „macro_command‟
此处应该为  macro_command
(C29)must be key word „sub‟
子函数的定义格式为:
sub data type function_函数名称  ()
………..   
end sub
例如:
sub intpow (int exp)
…….
end sub
任何不符合上述语法结构的,在编译时会错误。
(C30)number of parameters is incorrect
参数个数不对。
(C31)parameter type is incorrect
参数数据类型不相配。调用函数时,参数必须在数据类型、个数上一一对应才能通过编译,否则编译时将
出现此项错误讯息。
(C32)variable is incorrect
变量类型不正确。当变量被当成参数传递给一个函数时,变量的数据类型应与函数所宣告的类型相同,否
则将出现此项错误讯息。
(C33)function 函数名称  : undeclared function
没有定义的函数名称
(C34)expected constant expression
不合法的数组下标表达形式
(C35)invalid array declaration
不合法的数组定义
(C36)array index error
不合法的数组下标
(C37)undeclared identifier : i „identifier‟
使用没有定义的变量。只能使用已经定义的变量和函数,否则编译时将出现此项错误讯息。
(C38)un-supported PLC data address
通讯函数GetData( )SetData(   )的参数中有包含  PLC 地址类型信息,当  PLC地址类型不是此种
PLC 支持的地址类型时,编译时将出现此项错误信息。
(C39)„idenifier‟ must be integer, char or constant
数组的格式为:
声明:  array_函数名称”constant (constantis the size of the array)
使用:  array_函数名称”integer,character or constant
任何不符合上述规则的数组表达式,编译时将会错误
(C40)execution 语法  should not exist beforevariable declaration or constant definition
变量定义语句的前面不能有执行语句
例如  :
macro_commandmain(  )  
int a, b
for a =0 To 2   
b = 4 +a
int h ,k  // 定义变量语句在此处是错误的,在一个函数内定义变量语句的前面
不能有执行语句,例如  b = 4 + a  
next a
endmacro_command
(C41)float variables cannot be contained in shift calculation
移位运算中,操作数不能为浮点数。
(C42)function must return a value
函数应有返回值
(C43)function should not return a value
函数不应有返回值
(C44)float variables cannot be contained in calculation
运算中不能有  float 型数据
(C45)PLC address error
PLC 地址错误
(C46)array size overflow (max. 4k)
一维数组的大小超过  4k
(C47)macro command entry function is not only one
宏指令程序入口只能有一个
(C48)macro command entry function must be only one
宏指令入口函数不是唯一。宏指令的入口函数只能有一个,形式为:
macro_commandfunction_函数名称( )   
endmacro_command   
(C49) anextended addressee‟s station number must be between 0 and 255
在宏指令中,扩展地址内的站号大小只能从  0   255
例如  :
SetData(bits[0], “PLC 1”, LB , 300#123, 100)
// illegal: 300#123 意思是站号为  300, 但是最大值是  255
(C50) aninvalid PLC 函数名称
在宏指令中,PLC 的名称并未定义在系统参数的设备列表中
(C51)macro command do not control a remote device
宏指令只能控制本机连接的设备
例如  :   
SetData(bits[0], &#8218LC 1‛, LB , 300#123, 100)
PLC1 连接在远程的触摸屏上,所以它不能被执行。


整套教程已发布于
威纶通触摸屏宏指令入门与精通视频教程
回复

使用道具 举报

快速回复 返回列表 客服中心 搜索