# Return Module and Channel from Variable

**URL:** <https://www.wago.community/t/return-module-and-channel-from-variable/2873>\
**Category:** CODESYS\
**Tags:** pfc100\
**Created:** [September 14, 2026, 10:30pm UTC](https://www.wago.community/t/return-module-and-channel-from-variable/2873 "2026-09-14T22:30:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ValiantSailor](https://avatars.discourse-cdn.com/v4/letter/v/bb73d2/32.png) [@ValiantSailor](https://www.wago.community/u/ValiantSailor)\
**Post date:** [September 14, 2026, 10:30pm UTC](https://www.wago.community/t/return-module-and-channel-from-variable/2873/1 "2026-09-14T22:30:04Z")

</div>

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

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![AdamReeve](https://sea2.discourse-cdn.com/flex016/user_avatar/www.wago.community/adamreeve/32/59_2.png) [@AdamReeve](https://www.wago.community/u/AdamReeve)\
**Post date:** [September 15, 2026, 12:58pm UTC](https://www.wago.community/t/return-module-and-channel-from-variable/2873/2 "2026-09-15T12:58:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ValiantSailor](https://avatars.discourse-cdn.com/v4/letter/v/bb73d2/32.png) [@ValiantSailor](https://www.wago.community/u/ValiantSailor)\
**Post date:** [September 15, 2026, 1:14pm UTC](https://www.wago.community/t/return-module-and-channel-from-variable/2873/3 "2026-09-15T13:14:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MikePsaltis](https://sea2.discourse-cdn.com/flex016/user_avatar/www.wago.community/mikepsaltis/32/47_2.png) [@MikePsaltis](https://www.wago.community/u/MikePsaltis)\
**Post date:** [September 15, 2026, 2:32pm UTC](https://www.wago.community/t/return-module-and-channel-from-variable/2873/4 "2026-09-15T14:32:22Z")

</div>

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!

 ![image](https://us1.discourse-cdn.com/flex016/uploads/wago/original/2X/b/b867628645657ad8395a82b4eb8a477603ada6f5.png)

 ![image](https://us1.discourse-cdn.com/flex016/uploads/wago/original/2X/8/8563261633e1c9a2926d729ed93be0ff4c2ecffe.png)

I also made a visu.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/wago/original/2X/3/30fffe0382443a07f8db60dc8f02a40d8df2e47f.png)

---

<div class="post-metadata">

**Author:** ![ValiantSailor](https://avatars.discourse-cdn.com/v4/letter/v/bb73d2/32.png) [@ValiantSailor](https://www.wago.community/u/ValiantSailor)\
**Post date:** [September 17, 2026, 9:29am UTC](https://www.wago.community/t/return-module-and-channel-from-variable/2873/5 "2026-09-17T09:29:38Z")

</div>

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?
