Join us today!
Variable linking using attributes - Auto Linking in TwinCAT
You can use pragmas to assign variables to inputs/outputs directly. If you have hundreds of IOs in your program, this method would be very useful for your application.
Syntax:
{attribute 'TcLinkTo' := '<I/O point name>'}
To get the 'point name' ( name of the input or output), double click on the desired input or output in the device tree, go to 'Variable' tab, and copy the 'Full Name' .
For this output, the syntax is : {attribute 'TcLinkTo':='TIID^Device 1 (EtherCAT)^Term 1 (EK1100)^01_Digital Output (EL2008)^Channel 1^Output'}
Linking this output using TIID; node I/O configuration^I/O devices or node I/O configuration TAB "I/O devices :
//using TIID ; node I/O configuration^I/O devices or node I/O configuration TAB "I/O devices {attribute 'TcLinkTo':='TIID^Device 1 (EtherCAT)^Term 1 (EK1100)^01_Digital Output (EL2008)^Channel 1^Output'} IDigitalOutput1 AT %Q* : BOOL;
You can also use the box name directly: {attribute 'TcLinkTo' := 'TIIB[Box name]^Node'}
//using TIIB[%s]; Box with name %s {attribute 'TcLinkTo':='TIIB[01_Digital Output (EL2008)]^Channel 2^Output'} IDigitalOutput2 AT %Q* : BOOL;
You can also create an array or a structure and assign it to inputs/outputs this way.
Using the box name and an array:
//using TIIB[%s]; Box with name %s and array {attribute 'TcLinkTo':=' [1] := TIIB[01_Analog Input (EL3004)]^AI Standard Channel 1^Value; [2] := TIIB[01_Analog Input (EL3004)]^AI Standard Channel 2^Value; [3] := TIIB[01_Analog Input (EL3004)]^AI Standard Channel 3^Value; [4] := TIIB[01_Analog Input (EL3004)]^AI Standard Channel 4^Value; '} IaAnalogInputEL3004 AT %I* : ARRAY[1..4] OF INT;
Using the box name and a structure:
TYPE ST_EL1008 : STRUCT bInput1 : BOOL; bInput2 : BOOL; bInput3 : BOOL; bInput4 : BOOL; bInput5 : BOOL; bInput6 : BOOL; bInput7 : BOOL; bInput8 : BOOL; END_STRUCT END_TYPE
//using TIIB[%s]; Box with name %s and structure {attribute 'TcLinkTo':=' .bInput1 := TIIB[01_Digital Input (EL1008)]^Channel 1^Input; .bInput2 := TIIB[01_Digital Input (EL1008)]^Channel 2^Input; .bInput3 := TIIB[01_Digital Input (EL1008)]^Channel 3^Input; .bInput4 := TIIB[01_Digital Input (EL1008)]^Channel 4^Input; .bInput5 := TIIB[01_Digital Input (EL1008)]^Channel 5^Input; .bInput6 := TIIB[01_Digital Input (EL1008)]^Channel 6^Input; .bInput7 := TIIB[01_Digital Input (EL1008)]^Channel 7^Input; .bInput8 := TIIB[01_Digital Input (EL1008)]^Channel 8^Input; '} IstEL1008 AT %I* : ST_EL1008;
Representation difference between manual linking and auto linking method:
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
In this link you can expand more:
https://www.dmcinfo.com/latest-thinking/blog/id/10336/how-to-link-hardware-io-in-beckhoff-twincat-3
https://github.com/runtimevic
https://github.com/TcMotion
https://www.youtube.com/playlist?list=PLEfi_hUmmSjFpfdJ6yw3B9yj7dWHYkHmQ
https://github.com/VisualPLC
- 17 Forums
- 267 Topics
- 942 Posts
- 0 Online
- 722 Members