Time Series Data using Python OPCUA

PM_Manufacturing_simple_model.vcmx (321.9 KB)
considering a simple model. I want to extract time series data from the simulation. i.e: when the product entered the milling machine and when left, when the Robot was in action!

Approach i used: I used opc ua plugin to create a server in python. But the value is not getting updated or stored. I must be missing something. Anyone help me out?
code used:

from opcua import ua, uamethod, Server
from time import sleep 
import datetime
i = 0

if __name__ == "__main__":
    """OPC-UA-Server setup
    server = Server()
    endpoint = "opc.tcp://"
    servername = "Hey"

## Object and Variable node
root_node = server.get_root_node()
object_node = server.get_objects_node()
idx = server.register_namespace("OPC_SERVER")
myobj= object_node.add_object(idx, "Variables")

partAtconsensor_1 = myobj.add_variable(idx, "partAtconsensor_1", 0, ua.VariantType.Boolean)
pathStart_1 = myobj.add_variable(idx, "pathStart_1", 0, ua.VariantType.Boolean)
partCountincoming = myobj.add_variable(idx, "partCountincoming", 0, ua.VariantType.Int64)

# start the server 
print("Server started at {}".format(endpoint))

    while True:
        if partAtconsensor_1 and pathStart_1 == True:
            partCountincoming = partCountincoming +1
        else: partCountincoming
except KeyboardInterrupt:

This is not really a forum for anything external to VC software, like programming your own OPC UA server.

Also this looks like a convoluted way of doing data collection from VC simulations unless you need a real-time stream. Usually it is just done using scripts in components which store the information in memory and write to a file on simulation reset or something.

If you want to use such approach, please look at the Python library’s own examples and documentation.


Hello @TSy , thanks!
I was looking on the code that you have given.

And in terms of obtaining data from components in VC:
In order to get the time series value, we need to write/edit the python script i.e: configscript of Sensor Conveyor, which means i need to write a function which actually measures the elapsed time of the simulation and trigger only given the sensor boolean value.

then the info will be stored and after that we can extract that through a OPC UA server ?

what i meant with the ConfigScript:

Please correct me if i am wrong!