Modbus FC5 Illegal function

I am trying to use the modbus library in structured text, I am trying to use FC5 for testing purposes but I am getting diagCode C060 and addDiagcode 0001 (illegal function). I have been able to use these functions in FBD code without running into this issue.
I have confirmed that the connection with my modbus device is working as I am getting a TRUE return on my clientReady variable from the TCP_Client function
I was wondering where the issue might be, below is the code I am running

MB_TCP_Client_91(xActivate := TRUE, xAutoAck := TRUE, strServer_IP := ‚192.168.3.11‘, iPort := 502, xUDP_Mode := FALSE, udtTCP_ComData := varudtTCP_ComData, xReady => clientReady);

IF (clientReady=TRUE AND Input = TRUE) THEN
MB_TCP_FC5_11(xActivate := TRUE, iMT_ID := 1, tUpdateTime:=updateTime, wOutputAddress := 16#007A, wOutputValue := 16#FF00, udtTCP_ComData := varudtTCP_ComData, xDone => done, xError => error, wDiagCode => diagCode, wAddDiagCode => addDiagCode);
END_IF

and here’s a screenshot of all the variables I’m currently using
image.png

Hello,
Did I understand correctly that while using FBD, you were able to use FC5 on the same device you are trying to connect with ST?
And did you try any other FC besides FC5 with ST?
Is it the same device and register your trying to use?
Illegal function means:
The illegal function error is reported back by a Modbus server when either it does not support the function at all, or does not support that function code on the requested registers. Different devices support different functions (consult the device documentation). If the function code is supported, make sure you are not trying to write to a register labeled as read-only. It is common for devices to have holding registers where read-only and read/write registers are mapped next to each other.

Hello!
At the moment, I can recommend you call FC5 instance out of the IF statement scope. It could occur some problems, while communication and queuing are initialize (iMT_ID not processed), or when fb can’t change it’s internal state when IF conditions not TRUE.
//Prev code
MB_TCP_FC5_11(xActivate := clientReady AND Input
, iMT_ID := 1, tUpdateTime:=updateTime, wOutputAddress := 16#007A, wOutputValue := 16#FF00, udtTCP_ComData := varudtTCP_ComData, xDone => done, xError => error, wDiagCode => diagCode, wAddDiagCode => addDiagCode);
//Further code
After that it could be investigate further.
BR