Skip to content

Commit

Permalink
Attempt methodcalsl with structures
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim Gustafsson committed Jul 9, 2024
1 parent 91195ee commit 702a0f7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default class AddressSpaceGraphics extends ControlMessageSplitScreen {
const enumRelation = node.getNamedRelation('EnumStrings')

if (enumRelation) {
this.addressSpace.relationsToNodes([enumRelation]).then((enumNodeList)=> {
this.addressSpace.relationsToNodes([enumRelation]).then((enumNodeList) => {
const nameList = enumNodeList[0].value
const index = parseInt(this.nodeValueToText(node.data.value))
const value = nameList[index]
Expand Down
41 changes: 41 additions & 0 deletions OPC_UA_Clients/Release2/IJT_Web_Client/Python/CallStructure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from asyncua import ua

def createCallStructure(argument):
"""
This function creates the input call structures
"""

value = argument["value"]
print(value)
inp = 0

match argument["dataType"]:
case 3029:
inp = ua.JoiningProcessIdentificationDataType()
arg0 = value[0]
inp.JoiningProcessId = arg0["value"]
arg1 = value[1]
inp.JoiningProcessOriginId = arg1["value"]
arg2 = value[2]
inp.SelectionName = arg2["value"]
case 3010:
lst = []

for row in value:
entityRow = row['value']
entity = ua.EntityDataType()
entity.Name = entityRow["Name"]
entity.Description = entityRow["Description"]
entity.EntityId = entityRow["EntityId"]
entity.EntityOriginId = entityRow["EntityOriginId"]
entity.IsExternal = entityRow["IsExternal"]
entity.EntityType = entityRow["EntityType"]

lst.append(entity)

inp = ua.Variant(lst, ua.VariantType.ExtensionObject)
print(inp.__dict__)
case _:
inp = ua.Variant(value, ua.VariantType(argument["dataType"]))

return inp
24 changes: 7 additions & 17 deletions OPC_UA_Clients/Release2/IJT_Web_Client/Python/Connection.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@



from asyncua import Client, ua
# from opcua.ua import EventFilter, SimpleAttributeOperand, ContentFilter, FilterOperator, ContentFilterElement
import asyncio
from Python.Serialize import serializeTuple, serializeValue
from Python.CallStructure import createCallStructure
import json
from threading import Thread
#from IPython import embed
Expand Down Expand Up @@ -255,23 +252,16 @@ async def methodcall(self, data):
attrList.append(method)

for argument in arguments:
value = argument["value"]
if argument["dataType"] == 3029:
inp = ua.JoiningProcessIdentificationDataType()
arg0 = value[0]
inp.JoiningProcessId = arg0["value"]
arg1 = value[1]
inp.JoiningProcessOriginId = arg1["value"]
arg2 = value[2]
inp.SelectionName = arg2["value"]
else:
inp = ua.Variant(value, ua.VariantType(argument["dataType"]))
attrList.append(inp)
input = createCallStructure(argument)
attrList.append(input)

print(1)
methodRepr = getattr(obj, "call_method")
print(2)
out = await methodRepr(*attrList) # call the method and get the output
print(3)

#print(serializeValue(out))
print(serializeValue(out))

return { "output" : serializeValue(out) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"connectionpoints": [{"name": "Local", "address": "opc.tcp://127.0.0.1:40451", "autoconnect": false}, {"name": "Windows simulation", "address": "opc.tcp://10.46.19.106:40451", "autoconnect": false}, {"name": "ICB-A", "address": "opc.tcp://10.46.16.68:40451", "autoconnect": true}, {"name": "PF8", "address": "opc.tcp://10.46.16.174:40451", "autoconnect": true}, {"name": "Pf8Demo", "address": "opc.tcp://192.168.1.1:40451", "autoconnect": false}], "command": "set connectionpoints", "endpoint": "common"}
{"connectionpoints": [{"name": "Local", "address": "opc.tcp://127.0.0.1:40451", "autoconnect": false}, {"name": "Windows simulation", "address": "opc.tcp://10.46.19.106:40451", "autoconnect": false}, {"name": "ICB-A", "address": "opc.tcp://10.46.16.68:40451", "autoconnect": false}, {"name": "PF8", "address": "opc.tcp://10.46.16.174:40451", "autoconnect": true}, {"name": "Pf8Demo", "address": "opc.tcp://192.168.1.1:40451", "autoconnect": false}], "command": "set connectionpoints", "endpoint": "common"}

0 comments on commit 702a0f7

Please sign in to comment.