OPC UA Update Signal "Sim is Running" to external OPC UA Server

Hello Everybody,
I would appreciate some help. I have successfully connected an OPC-UA Server to my model. I want to let the server know, if the Sim is running or not. I built a boolean signal, that VC should change via python script. If changed, the signal appears on the server. I checked forum + python api and didn´t find an answer unfortunately.

I managed to transmit the “True” when my sim is running in the OnRun(): function. What I can’t figure out, is how to send the “False” message. I tried to use the OnContinue() and OnStop(): function to trigger the signal. The signal behaviour is changed (confirmed by a print statement), but the var doesn´t get updated towards the server. This arises two main questions:

  • is the OPC-UA Server only updated while the Sim is running?
  • if so, how can I Transmit the information that the Sim has been stopped “in the last second” ?

Every help is appreciated, thanks a lot!

Kind Regards

JW

My Code for the behaviour I am updating:

from vcScript import *
# For more Docs see python api --> VCSimulation
sim = getSimulation()

# Used to get the signal value asap 
def setValue(sig_name, sig_value):
  comp = getComponent()
  sig = comp.findBehaviour(sig_name)
  sig.signal(sig_value)

def OnStop():
  setValue("Sim_is_Running", False)
  pass

def OnContinue():
  setValue("Sim_is_Running", True)
  pass

def OnRun():
  
  while sim.IsRunning: 
    setValue("Sim_is_Running", True)
    delay(5)
  pass

is the OPC-UA Server only updated while the Sim is running?

Yes, the Connectivity feature only sends and receives values when simulation is running. Further, the simulation signals (signal behavior) only trigger their change events when simulation is running.
If the Connectivity did update when simulation is paused / reset, it could e.g. do unwanted permanent changes to your simulation model while you are editing it.

if so, how can I Transmit the information that the Sim has been stopped “in the last second” ?

There isn’t really any proper way from Python that I can think of. In theory you could try to use a property instead of a signal (as those provide events also when simulation is paused / reset), and then do a hack from Python where you detect simulation pause and immediately resume it for a bit, then pause again.

From the .NET API it is possible to request the Connectivity core to synchronize a given variable group “manually” when simulation is paused / reset. Same “single update” functionality is available as a button in the Connected variables panel.

Thanks for the inspiration TSy,
I´ll try to work with your given ideas and I will post my solution here. I am currently thinking about implementing an external optimizer that would change parameters in the layout to find the optimal solution. For that idea, I would have to start und restart the sim with other presets of parameters automatically.

With your information given, this means that I would have to write additional code in .NET to stop/Start the sim from an external source? My hope was, that I could mostly just work with communication through OPC-UA.

Thanks!