Commit 6c4687ed authored by Philipp's avatar Philipp

Initial commit for data streams for OPCUA

parent 65c0397a
......@@ -9,5 +9,6 @@
*.log
# ignore specific files
bt5/bt5list
coupler/opc-ua-server/open62541.c
coupler/opc-ua-server/open62541.h
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>erp5_opcua_frauenhofer</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""
OPCUA to ERP5 OPCUA Document setter / getter glue script.
"""
import json
from erp5.component.module.Log import log
def convertNodeValue(node_id, node_value, type_data):
"""
Based on type_data convert to proper Python type.
For differentiating different integer types
https://docs.pycomm3.dev/en/latest/api_reference/data_types.html
"""
if "STRING" in type_data:
# string
return str(node_value)
elif "REAL:" in type_data:
return float(node_value)
elif "INT" in type_data:
return int(node_value)
elif "UINT" in type_data:
return int(node_value)
elif "UDINT" in type_data:
return int(node_value)
elif "BOOL" in type_data:
return bool(node_value)
else:
raise ValueError("Unsupported data type %s" % node_value)
# XXX: what should be the OPCUA container?
default_id = "data_stream_1"
default_data_stream = context.portal_catalog.data_stream_module.get(default_id, None)
if default_data_stream is None:
# Create a new Data Stream if it doesn't exist
default_data_stream = context.portal_catalog.data_stream_module.newContent(title = "Data Stream 1",
portal_type = "Data Stream",
id = default_id)
# do selection of operation in a REST fashion based in HTTP method
if http_method is None:
http_method = context.REQUEST.method
if http_method == "GET":
# not yet implemented
# assume read request, return what was saved.
return json.dumps(default_data_stream.getData())
elif http_method == "POST":
# assume write request
if data is None:
try:
data = context.REQUEST.data
except AttributeError as e:
log("Warning: 'data' is missing from request.")
raise e
raw_data = data
data = json.loads(data)
if 'node' in data.keys():
# log only set requests for now
node_id = data['node']
node_value = data['val']
# introspect type of the value
type_data = data["data"]
# set to "ERP5 OPCUA Document" but only if it's not a None value
if node_value is not None and node_value != "None":
converted_value = convertNodeValue(node_id, node_value, type_data)
default_data_stream.appendData(raw_data)
log("Data appended to Data Stream: %s" % raw_data)
return default_data_stream
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>http_method=None, default_data_stream=None, data=None, *args, **kwargs</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_handleOPCUARequest_data_stream</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
erp5_mes_configurator
\ No newline at end of file
erp5_opcua_frauenhofer
\ No newline at end of file
erp5_opcua_frauenhofer
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment