@uamethod decorator --> DOES Automatically convert to and from variants ? #1078
Unanswered
dibyendumca
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
SCREEN SHOTS ...
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
PLEASE REFER THE CODE SNIPPET BELOW...
############################################################################################
@uamethod
def Multiply(parent, x, y):
# Function Multiply
msgLog = messageLogger()
res = 0.0
msgLog.WriteLog( LogErr.INF, "Multiply method called with parameters: " + str(x) + ", " + str(y))
try:
res = x * y
except Exception as e:
msgLog.WriteLog(
LogErr.ERR, "Oops!" + sys.exc_info()[0] + "occurred.")
msgLog.WriteLog(
LogErr.ERR, "Oops!" + e.class + "occurred.")
print()
else:
msgLog.WriteLog(LogErr.INF, "Result: " + str(res))
return res
NOW ADDING THE FUNCTION Multiply(x, y) ...
WHENEVER I AM CALLING THE FUNCTION Multiply(x, y) WITH PARAMETERS x=2 AND y=3 from FreeOpcUa Client tool,
I AM GETTING THE FOLLOWING ERROR ...
###############################################################################################
Multiply method called with parameters: Variant(Value=2.0, VariantType=<VariantType.Double: 11>, Dimensions=None, is_array=False), 3.0
Error executing method call CallMethodRequest(ObjectId=NodeId(Identifier=2, NamespaceIndex=2, NodeIdType=<NodeIdType.FourByte: 1>), MethodId=NodeId(Identifier=6, NamespaceIndex=2, NodeIdType=<NodeIdType.FourByte: 1>), InputArguments=[Variant(Value=2.0, VariantType=<VariantType.Double: 11>, Dimensions=None, is_array=False), Variant(Value=3.0, VariantType=<VariantType.Double: 11>, Dimensions=None, is_array=False)]), an exception was raised:
Traceback (most recent call last):
File "...\CustomFeaturesStub.py", line 54, in Multiply
res = x * y
TypeError: unsupported operand type(s) for *: 'Variant' and 'float'
AFTER MODIFYING THE CODE OF THE FUNCTION Multiply(x, y) ...
CODE SNIPPET ....
@uamethod
def Multiply(parent, x, y):
# Function Multiply
msgLog = messageLogger()
x = x.Value
y = y.Value
res = 0.0
msgLog.WriteLog(
LogErr.INF, "Multiply method called with parameters: " + str(x) + ", " + str(y))
try:
res = x * y
except Exception as e:
msgLog.WriteLog(
LogErr.ERR, "Oops!" + sys.exc_info()[0] + "occurred.")
msgLog.WriteLog(
LogErr.ERR, "Oops!" + e.class + "occurred.")
print()
else:
msgLog.WriteLog(LogErr.INF, "Result: " + str(res))
return res
ERROR ...
Error executing method call CallMethodRequest(ObjectId=NodeId(Identifier=2, NamespaceIndex=2, NodeIdType=<NodeIdType.FourByte: 1>), MethodId=NodeId(Identifier=6, NamespaceIndex=2, NodeIdType=<NodeIdType.FourByte: 1>), InputArguments=[Variant(Value=2.0, VariantType=<VariantType.Double: 11>, Dimensions=None, is_array=False), Variant(Value=3.0, VariantType=<VariantType.Double: 11>, Dimensions=None, is_array=False)]), an exception was raised:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\asyncua\server\address_space.py", line 583, in _call
result = await self._run_method(node.call, method.ObjectId, *method.InputArguments)
File "C:\ProgramData\Anaconda3\lib\site-packages\asyncua\server\address_space.py", line 602, in _run_method
res = await asyncio.get_event_loop().run_in_executor(self._pool, p)
File "C:\ProgramData\Anaconda3\lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\opcua\common\methods.py", line 69, in wrapper
result = func(self, parent, *[arg.Value for arg in args])
File "D:\MADI04\PROJECTS\PYTHON\ASYNCUA\DacXpertM\CustomFeaturesStub.py", line 51, in Multiply
y = y.Value
AttributeError: 'float' object has no attribute 'Value'
#########################################################################################
IS THIS A BUG ???, @uamethod --> Converting only the 2nd parameter from VARIANT to FLOAT, but not the 1st parameter
Beta Was this translation helpful? Give feedback.
All reactions