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://10.17.95.80:4840"
server.set_endpoint(endpoint)
servername = "Hey"
server.set_server_name(servername)
## 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
server.start()
print("Server started at {}".format(endpoint))
try:
while True:
if partAtconsensor_1 and pathStart_1 == True:
partCountincoming = partCountincoming +1
print(partCountincoming)
else: partCountincoming
except KeyboardInterrupt:
server.stop()