python-opcua icon indicating copy to clipboard operation
python-opcua copied to clipboard

opcua server not updating the value the second time

Open siddhartherat1997 opened this issue 5 months ago • 0 comments

Hi , So I have been trying to do some simulation using opcua for powerfactory. the set_value() is working only once . The second time I am calling I am not able to send the value from opcua server to powerfactory. I am attaching the server code.

`from opcua import Server,ua from datetime import datetime import time import matplotlib.pyplot as plt import csv

Define global variables for the OPC UA server and variables

server = None

conv1_kq_set = None

class myServer: def init(self):

    self.conv1_kq_set = None

 

    # Setup the OPC UA server
    self.server = Server()
    
    # Set endpoint for the server
    
def start_server(self):
    #global serverconv1_kq_set
    self.server.set_endpoint("opc.tcp://localhost:5300/freeopcua/server/")
    print("Server endpoint: {}".format(self.server.endpoint))
    
    # Setup the server namespace
    uri = "http://example.org"
    self.idx = self.server.register_namespace(uri)
    
    # Get the Objects node, this is where we should add our nodes
    self.objects = self.server.get_objects_node()
    
    # Create a new object in the server
    self.my_object = self.objects.add_object(self.idx, "MyObject")
    
    
    
    # Create variables in the new object
    self.conv1_kq_set = self.my_object.add_variable(self.idx, "CONV_1_KQ_SET", 0.00)
  
  
    # Set writable properties
   
    self.conv1_kq_set.set_writable()  # Readable and writable
 

    self.conv2_active_power.set_writable()
    self.conv2_kq_set.set_writable()  # Readable and writable
    self.conv2_reactive_power.set_writable()
    self.conv2_voltage_meas.set_writable()
    
    
    # Start the server
    self.server.start()
    print("Server started at {}".format(self.server.endpoint))


# Functions to get the current values of the variables

def set_conv1_kq_set(self,value):
    return self.conv1_kq_set.set_value(value)

`

siddhartherat1997 avatar Sep 04 '24 22:09 siddhartherat1997