manuel2705
manuel2705

Reputation: 45

How to implement FB GetLocalAmsNetId?

this is my first question here on stackoverflow and im hoping someone might be able to help me out. I'm trying to get the local AmsNetId of my TwinCat PLC system. The Code is running on the TwinCat System locally. The function is working properly, no problems compiling. But the functionblock FB_GetLocalAmsNetId never seems to return the Ams Net Id. fbGetAmsNetId.bBusy is always busy. I dont know what i'm doing wrong.

Variables:

FUNCTION_BLOCK FB_GetAmsNetId
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
    fbGetAmsNetId : FB_GetLocalAmsNetId;
    bRequestStarted : BOOL := FALSE;
    sAmsNetId : T_AmsNetId;
END_VAR

Programcode:

IF(bRequestStarted = FALSE) THEN
    fbGetAmsNetId(bExecute := TRUE, tTimeOut := T#2S);
    bRequestStarted := TRUE;
ELSE
    IF(NOT fbGetAmsNetId.bBusy) THEN
        sAmsNetId := fbGetAmsNetId.AddrString;
        fbGetAmsNetId.bExecute := FALSE;
        bRequestStarted := FALSE;
    END_IF
END_IF

Upvotes: 1

Views: 966

Answers (2)

Kudapucat
Kudapucat

Reputation: 128

Look at the following functions in TC2_IOFunctions https://infosys.beckhoff.com/english.php?content=../content/1033/tcplclib_tc2_iofunctions/59098123.html&id=

IOF_GetDeviceIDs() - Tells you the number of devices then their IDs in words IOF_GetDeviceNetId() - Gives you the NetID for each device Also you can get the local machine NetID if you need using GetLocalAmsNetID from TC2_Utilities

Upvotes: 0

Filippo Boido
Filippo Boido

Reputation: 1206

You need to cyclically call fbGetAmsNetId in your code, otherwise FB_GetLocalAmsNetId will not be able to finish it's internal operations beeing executed for only one plc cycle.

For example:

fbGetAmsNetId();
IF(bRequestStarted = FALSE) THEN
    fbGetAmsNetId(bExecute := TRUE, tTimeOut := T#2S);
    bRequestStarted := TRUE;
ELSE
    IF(NOT fbGetAmsNetId.bBusy) THEN
        sAmsNetId := fbGetAmsNetId.AddrString;
        fbGetAmsNetId.bExecute := FALSE;
        bRequestStarted := FALSE;
    END_IF
END_IF

Upvotes: 1

Related Questions