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


