i am trying to check if a specific input from a hardware device is linked to my plc application on Twincat 3.1, in my example below i would like to check if "Terminal Overtemperature" is linked to a variable in the plc application side at runtime.
I appreciate any help, thanks in advance.
PS1: I do know that i can evaluate the "InputToggle" or the "CycleCounter" but these variables will only provide information if any input is linked.
PS2: I also try the method provided by Beckhoff Infosys Documentation (pragma approach), Attribute 'TcLinkTo' / 'TcLinkToOSO', this will force to link the variable every time that the configuration is downloaded nevertheless if the input is not found or if the parameter is not correctly set in the attribute (ex. wrong name) this will just generate a warning in compiling time and this warning will be deleted at runtime
There is a way. You can do this with F_GetMappingStatus
The function
F_GetMappingStatus
returns the current mapping status of a PLC variable. The function returns anENUM
value (data type:EPlcMappingStatus
) with the valuesMS_Unmapped
,MS_Mapped
orMS_Partial
.
Make sure you call it in the Cyclic Context, that is not during FB_init
or call_after_init
, see here:
Next up there is the
F_GetMappingStatus
function. It checks whether a variable is linked to a physical device. Great to use for automatic simulation and fallback or hiding items in a template. This is a function that you do not want to call cyclicly given it is fairly expensive. It is therefore perfect to be called as part of the initialization phase. However, if called outside the Cyclic Context it will always returnEPlcMappingStatus.MS_Unmapped
, regardless of actual mapped status. This is undesirable and therefore it must be called inside a regular task cycle. You can either use thePlcTaskSystemInfo.FirstCycle
, or have it part of your initialization state inside your FB body.
You can use the Automation Interface's HRESULT ProduceMappingInfo();
. This method will return an XML file with all mapped variables.
Example return from InfoSys:
<VarLinks>
<OwnerA Name="TIID^Device 1 (EtherCAT)">
<OwnerB Name="TIXC^Untitled2^Untitled2_Obj1 (CModule1)">
<Link VarA="Term 1 (EK1100)^Term 3 (EL1008)^Channel 5^Input" VarB="Inputs^Value" />
<Link VarA="Term 1 (EK1100)^Term 2 (EL2008)^Channel 4^Output" VarB="Outputs^Value" />
</OwnerB>
</OwnerA>
<OwnerA Name="TIPC^Untitled1^Untitled1 Instance">
<OwnerB Name="TIID^Device 1 (EtherCAT)^Term 1 (EK1100)^Term 2 (EL2008)">
<Link VarA="PlcTask Outputs^MAIN.bOutput1" VarB="Channel 1^Output" />
<Link VarA="PlcTask Outputs^MAIN.bOutput3" VarB="Channel 3^Output" />
<Link VarA="PlcTask Outputs^MAIN.bOutput2" VarB="Channel 2^Output" />
</OwnerB>
<OwnerB Name="TIID^Device 1 (EtherCAT)^Term 1 (EK1100)^Term 3 (EL1008)">
<Link VarA="PlcTask Inputs^MAIN.bInput1" VarB="Channel 1^Input" />
<Link VarA="PlcTask Inputs^MAIN.bInput3" VarB="Channel 3^Input" />
<Link VarA="PlcTask Inputs^MAIN.bInput2" VarB="Channel 2^Input" />
<Link VarA="PlcTask Inputs^MAIN.bInput4" VarB="Channel 4^Input" />
</OwnerB>
</OwnerA>
</VarLinks>