Return Module and Channel from Variable

Hej,
So I am a bit new to CodeSys. I am trying to get the module and channel number from a variable, which is used as an input to a function, but cannot find out how this works here. The goal is I select a variable as an input to the function and then the module is replaced here (in this case RTD_750_51) for use in the channel configuration and the channel number of the variable is returned as an int. Any ideas? Thank you in advance.

Module is named

FUNCTION VAR_WAGO : MB_DUT
VAR_INPUT
	rawSensor: INT;
	usiChannel_451                  : USINT := 1; // Target channel (1 to 8)
END_VAR
VAR
    xGetRawChannelConfig            : BOOL := TRUE;
    xSetRawChannelConfig            : BOOL;
    utRawChannelConfig              : WagoSysModule_750_451.WagoTypesModule_750_451.typRawChannelConfiguration;
    eServiceState_Get               : WagoSysModule_750_451.WagoTypesModuleBase.eServiceState;
    
    // Choose your target sensor type (e.g., Pt1000)
    mySensorType                    : WagoTypesModule_750_451.eSensorType := WagoTypesModule_750_451.eSensorType.Pt1000_EN60751_01;
    xError                          : BOOL;
    ogetError_451                   : WagoSysModule_750_451.WagoSysErrorBase.FbResult;
	
END_VAR

// 1. Read the current configuration
eServiceState_Get:= RTD_750_451_16.GetRawChannelConfiguration(
    usiChannel:= usiChannel_451, 
    xTrigger:= xGetRawChannelConfig, 
    utRawChannelConfiguration:= utRawChannelConfig, 
    xError=> xError, 
    oError=> ogetError_451);
// 2. Once retrieved successfully, modify and push the new settings
CASE eServiceState_Get OF 
    WagoTypesModuleBase.eServiceState.DONE:
        utRawChannelConfig.Settings.eSensorType := mySensorType; // Adjust channel type here
        xSetRawChannelConfig := TRUE; // Trigger the write operation
END_CASE
// 3. Return raw configured value
VAR_WAGO.aChVAL := INT_TO_WORD (rawSensor);

At quick glance, without digging into all the details of your code, I think you need to create a Function Block for VAR_WAGO instead of a Function. A Function has no internal memory from scan to scan, and so it cannot execute the function block methods of FbModule_750_451. A Function Block, on the other hand, uses a declared instance to have its own memory so it can continue to process over multiple plc scans. Instead of setting the function to return a value of type MB_DUT, add a VAR_OUTPUT to your function block of type MB_DUT instead.

Thank you for the reply. However, even using a FB instead, how do I get the module name and channel number of said module as variables inside the FB?
The goal is you have a FB, where you select a variable, that is connected to an input and a number for configuration select case. Inside the FB, you then get the channel number and module name to be used for channel configuration.
Hope that explains my issue a bit better

You should be able to pass an I_Port interface into the function block. A function block is likely appropriate here, I think these methods take more than one scan cycle to finish.

I just tried implementing this this on a project with a 750-1491 module, and it works!

I also made a visu.

Thanks, but this still does not answer my question as regards to how do I get the channel ID from the input variable. Passing the variable (in this case I_port) is not he issue, but internally returning it from the external GVL linked to HW input is my issue. Is this possible?