Join us today!

Variable linking us...
 
Notifications
Clear all

Variable linking using attributes - Auto Linking in TwinCAT

2 Posts
2 Users
4 Reactions
1,442 Views
TwinControls
Posts: 71
Admin
Topic starter
(@beckhoffsupport)
Member
Joined: 2 years ago

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' . 

path

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'}

boxname
//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:

automanual

 

Reply
1 Reply
1 Reply
runtimevictor
(@runtimevictor)
Joined: 2 years ago

Estimable Member
Posts: 156

@beckhoffsupport ,

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

Reply
Share: