New answer
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 an ENUM
value (data type: EPlcMappingStatus
) with the values MS_Unmapped
, MS_Mapped
or MS_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 return EPlcMappingStatus.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 the PlcTaskSystemInfo.FirstCycle
, or have it part of your initialization state inside your FB body.
Old answer
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>