Twincat 语法
-
- Posts: 178
- Joined: 30 Apr 2009 06:31
Twincat 语法
https://wenku.baidu.com/view/34093b5200 ... 3f663.html
当前进度:
https://infosys.beckhoff.com/content/10 ... 7648659318
http://www.plcacademy.com/category/plc-programming/
https://community.parker.com/technologi ... on-the-fly
https://www.enchantedlearning.com/grammar/punctuation/
http://download-cn.beckhoff.com.cn/download
https://blog.csdn.net/xiaoliu0515_0515/ ... s/78598621
ftp://ftp.beckhoff.com.cn/TwinCAT3/inst ... onPackage/
https://blog.csdn.net/jldemanman/articl ... s/79207148
当前进度:
https://infosys.beckhoff.com/content/10 ... 7648659318
http://www.plcacademy.com/category/plc-programming/
https://community.parker.com/technologi ... on-the-fly
https://www.enchantedlearning.com/grammar/punctuation/
http://download-cn.beckhoff.com.cn/download
https://blog.csdn.net/xiaoliu0515_0515/ ... s/78598621
ftp://ftp.beckhoff.com.cn/TwinCAT3/inst ... onPackage/
https://blog.csdn.net/jldemanman/articl ... s/79207148
Last edited by jiataifeng on 04 Apr 2019 23:06, edited 5 times in total.
-
- Posts: 178
- Joined: 30 Apr 2009 06:31
Re: PLC
上升沿
现在用一个光电开关来做一个产品计数器,原理是一个产品经过开关,计数器加一;假设你的开关接到X0(输入点)上,那么你在程序中就要用一个X0的上升沿驱动计数器,才能保证经过一个产品,计数器只加一,若没有上升沿,PLC会在X0接通时的每一个扫描周期加一。扫描周期知道是啥概念吧,就是说若没有上升沿,开关接通一秒,计数器就加了几十上百次了
上升沿主要是用来保证只在变量改变的那个周期触发。
现在用一个光电开关来做一个产品计数器,原理是一个产品经过开关,计数器加一;假设你的开关接到X0(输入点)上,那么你在程序中就要用一个X0的上升沿驱动计数器,才能保证经过一个产品,计数器只加一,若没有上升沿,PLC会在X0接通时的每一个扫描周期加一。扫描周期知道是啥概念吧,就是说若没有上升沿,开关接通一秒,计数器就加了几十上百次了
上升沿主要是用来保证只在变量改变的那个周期触发。
-
- Posts: 178
- Joined: 30 Apr 2009 06:31
Re: PLC
A Variable has up to 5 properties
1. Name
2. Size (Defined by the Type)
3. Value
4. Memory Location
5. PLC Address
1. Name
2. Size (Defined by the Type)
3. Value
4. Memory Location
5. PLC Address
-
- Posts: 178
- Joined: 30 Apr 2009 06:31
Re: PLC
Global Variables can be read and written to from anywhere in the PLC program
Local Variables can only be written to from within the POU where they are defined
The local variable of any POU can be read by first accessing the POU instance that
the variable is defined in and then using the ‘.’ to access the local variables defined
within that POU
Local variables cannot be written to from another POU
Local Variables can only be written to from within the POU where they are defined
The local variable of any POU can be read by first accessing the POU instance that
the variable is defined in and then using the ‘.’ to access the local variables defined
within that POU
Local variables cannot be written to from another POU
-
- Posts: 178
- Joined: 30 Apr 2009 06:31
Re: PLC
data type
类型转换:
这里
字符串函数:
这里
取变量地址:ADR(变量)
STRING_TO_WSTRING2 here
转义字符:$
byt :=DT_TO_BYTE(DT#1970-01-15-05:05:05); (* Result is 129 *)
str:=DT_TO_STRING(DT#1998-02-13-14:20); (* Result is 'DT#1998-02-13-14:20' *)
vtod:=DT_TO_TOD(DT#1998-02-13-14:20); (* Result is TOD#14:20 *)
vdate:=DT_TO_DATE(DT#1998-02-13-14:20); (* Result is D#1998-02-13 *)
vdw:=DT_TO_DWORD(DT#1998-02-13-14:20); (* Result is 16#34E45690 *)
类型转换:
这里
字符串函数:
这里
取变量地址:ADR(变量)
STRING_TO_WSTRING2 here
转义字符:$
byt :=DT_TO_BYTE(DT#1970-01-15-05:05:05); (* Result is 129 *)
str:=DT_TO_STRING(DT#1998-02-13-14:20); (* Result is 'DT#1998-02-13-14:20' *)
vtod:=DT_TO_TOD(DT#1998-02-13-14:20); (* Result is TOD#14:20 *)
vdate:=DT_TO_DATE(DT#1998-02-13-14:20); (* Result is D#1998-02-13 *)
vdw:=DT_TO_DWORD(DT#1998-02-13-14:20); (* Result is 16#34E45690 *)
Last edited by jiataifeng on 25 Feb 2019 22:23, edited 7 times in total.
-
- Posts: 178
- Joined: 30 Apr 2009 06:31
Re: Twincat 语法
IF A THEN
//
ELSIF B THEN
//
.
.
ELSIF N> THEN
//
ELSE
//
END_IF;
//
ELSIF B THEN
//
.
.
ELSIF N> THEN
//
ELSE
//
END_IF;
-
- Posts: 178
- Joined: 30 Apr 2009 06:31
Re: Twincat 语法
CASE A OF
1:
//
2,3:
//
4..9:
//
ELSE
//
END_CASE;
1:
//
2,3:
//
4..9:
//
ELSE
//
END_CASE;
-
- Posts: 178
- Joined: 30 Apr 2009 06:31
Re: Twincat 语法
FOR i := 1 TO 5 BY 1 DO
//
END_FOR;
WHILE A>0 DO
//
END_WHILE;
REPEAT
//
UNTIL
A > 0
END_REPEAT;
CONTINUE;//跳出当前循环
EXIT;//跳出循环
RETURN//返回
JMP label;// 类似go to
nVar1 := 0;
_label1 : nVar1 := nVar1+1;
(*instructions*)
IF (nVar1 < 10) THEN
JMP _label1;
END_IF;
//
END_FOR;
WHILE A>0 DO
//
END_WHILE;
REPEAT
//
UNTIL
A > 0
END_REPEAT;
CONTINUE;//跳出当前循环
EXIT;//跳出循环
RETURN//返回
JMP label;// 类似go to
nVar1 := 0;
_label1 : nVar1 := nVar1+1;
(*instructions*)
IF (nVar1 < 10) THEN
JMP _label1;
END_IF;
Last edited by jiataifeng on 12 Sep 2018 05:03, edited 9 times in total.
-
- Posts: 178
- Joined: 30 Apr 2009 06:31
Re: Twincat 语法
Function A或 Function block B 的 Action成员 Reset 类似于不带参数的成员变量,可以直接调用 Function Block,或Function里的变量。这有利于封装。
Method是带参数的成员变量。
调用的形式为:
<FB-instance>.<action> or <program>.<action>
即:
实例.A.Reset();//通过找到第一个实例,顺藤摸瓜找到对应的A或B,然后调用
实例.B.Reset();
A.Reset(); //不可以,除非A是program
B.Reset(); //不可以,除非B是program
Method是带参数的成员变量。
调用的形式为:
<FB-instance>.<action> or <program>.<action>
即:
实例.A.Reset();//通过找到第一个实例,顺藤摸瓜找到对应的A或B,然后调用
实例.B.Reset();
A.Reset(); //不可以,除非A是program
B.Reset(); //不可以,除非B是program
Last edited by jiataifeng on 12 Sep 2018 05:03, edited 1 time in total.
-
- Posts: 178
- Joined: 30 Apr 2009 06:31
Re: Twincat 语法
Property的GET和SET会被自动调用(when a read or write access occurs to the function block that implements the property.)
TwinCAT calls the Set accessor when write access to the property occurs, i.e. when you use the property name as input parameter.
TwinCAT calls the Get accessor when read access to the property occurs, i.e. when you use the property name as output parameter.
使用不使用 REFERENCE TO 和REF= 只是影响到直接访问结构中的成员变量
例子:
TYPE ST_Sample :
STRUCT
bVar : BOOL;
nVar : INT;
END_STRUCT
END_TYPE
FUNCTION_BLOCK FB_Sample
VAR
stLocal : ST_Sample;
END_VAR
Declaration of the property FB_Sample.MyProp with the return type "REFERENCE TO ST_Sample":
PROPERTY MyProp : REFERENCE TO ST_Sample
Implementation of the Get method of the property FB_Sample.MyProp:
MyProp REF= stLocal;
Implementation of the Set method of the property FB_Sample.MyProp:
stLocal := MyProp;
Calling the Get and Set methods in the main program MAIN:
PROGRAM MAIN
VAR
fbSample : FB_Sample;
nSingleGet : INT;
stGet : ST_Sample;
bSet : BOOL;
stSet : ST_Sample;
END_VAR
// Get - single member and complete structure possible
nSingleGet := fbSample.MyProp.nVar;
stGet := fbSample.MyProp;
// Set - only complete structure possible
IF bSet THEN
fbSample.MyProp := stSet;
bSet := FALSE;
END_IF
Through the declaration of the return type of the property MyProp as "REFERENCE TO ST_Sample" and through the use of the reference operator REF= in the Get method of this property, a single element of the returned structured data type can be accessed directly on calling the property.
VAR
fbSample : FB_Sample;
nSingleGet : INT;
END_VAR
nSingleGet := fbSample.MyProp.nVar;
If the return type were only to be declared as "ST_Sample", the structure returned by the property would first have to be assigned to a local structure instance. The individual structure elements could then be queried on the basis of the local structure instance.
VAR
fbSample : FB_Sample;
stGet : ST_Sample;
nSingleGet : INT;
END_VAR
stGet := fbSample.MyProp;
nSingleGet := stGet.nVar;
TwinCAT calls the Set accessor when write access to the property occurs, i.e. when you use the property name as input parameter.
TwinCAT calls the Get accessor when read access to the property occurs, i.e. when you use the property name as output parameter.
使用不使用 REFERENCE TO 和REF= 只是影响到直接访问结构中的成员变量
例子:
TYPE ST_Sample :
STRUCT
bVar : BOOL;
nVar : INT;
END_STRUCT
END_TYPE
FUNCTION_BLOCK FB_Sample
VAR
stLocal : ST_Sample;
END_VAR
Declaration of the property FB_Sample.MyProp with the return type "REFERENCE TO ST_Sample":
PROPERTY MyProp : REFERENCE TO ST_Sample
Implementation of the Get method of the property FB_Sample.MyProp:
MyProp REF= stLocal;
Implementation of the Set method of the property FB_Sample.MyProp:
stLocal := MyProp;
Calling the Get and Set methods in the main program MAIN:
PROGRAM MAIN
VAR
fbSample : FB_Sample;
nSingleGet : INT;
stGet : ST_Sample;
bSet : BOOL;
stSet : ST_Sample;
END_VAR
// Get - single member and complete structure possible
nSingleGet := fbSample.MyProp.nVar;
stGet := fbSample.MyProp;
// Set - only complete structure possible
IF bSet THEN
fbSample.MyProp := stSet;
bSet := FALSE;
END_IF
Through the declaration of the return type of the property MyProp as "REFERENCE TO ST_Sample" and through the use of the reference operator REF= in the Get method of this property, a single element of the returned structured data type can be accessed directly on calling the property.
VAR
fbSample : FB_Sample;
nSingleGet : INT;
END_VAR
nSingleGet := fbSample.MyProp.nVar;
If the return type were only to be declared as "ST_Sample", the structure returned by the property would first have to be assigned to a local structure instance. The individual structure elements could then be queried on the basis of the local structure instance.
VAR
fbSample : FB_Sample;
stGet : ST_Sample;
nSingleGet : INT;
END_VAR
stGet := fbSample.MyProp;
nSingleGet := stGet.nVar;
Last edited by jiataifeng on 28 Sep 2018 22:53, edited 1 time in total.