0
Answered

Problems with SignalChanged behaviour of PLCOutput class

Tim Peperkamp 5 years ago in realvirtual.io Starter and Professional updated 5 years ago 19

Dear game4utomation team,

Recently we bought the Game4Automation Pro Asset in Unity, and so far we really like it.

We set up a simple project in Simit and managed to get the interface working with the shared memory solution.

For this we used the Update() method off Unity, now we would like to use a event based system to reduce the load on the system. In the PLCOutput class the event SignalChanged is available and we tried to implement this.

So in this example we would like to toggle a bool to change the color on a traffic light.

public class Verkeerslicht3 : NetworkBehaviour

{

public Material yellowMaterial;

public PLCOutputBool yellowEnable;

public MeshRenderer yellowMeshRenderer;

void Start()

{

yellowEnable.SignalChanged += OnYellowEnableStateChange;

}


private void OnYellowEnableStateChange(Signal obj)

{

RpcSetGeel(obj);

}


[ClientRpc]

private void RpcSetGeel(bool state)

{

yellowMeshRenderer.material = state ? yellowMaterial : disabledMaterial;

}

But if we toggle the Bool in Simit the OnYellowEnableStateChange is not called.

Can you help with this?

Answer

Answer

Hi Tim,

there was a problem with the automatic settings of the defines.

Please check if the PLCOutput Script was added to your variable automatically:


If not please set in the defines manually "GAME4AUTOMATION" and reimport all OPCSignals.


Now it should work

Under review

Thanks for the positive feedback. Because of vacation I can’t check the issue before Wednesday next week - but I will take care about it ASAP. And if you like it please give a positive rating in the Asset Store.

Hi, I tried to reproduced the problem but in my test the Signal Changed event worked as expected. Can you please send us with a private message a model where it is not working.

Best regards

Thomas

Hey Thomas, 

Thanks for the response, I will send a Unity Project to info@game4automation.com 

Best regards

Tim

Hey Tim,

I checked. The PLCOutPutBoolChanged Events should not be used. They are very limited and they only work if PLCOutPutBool.Value is changed via script. Most probably we are going to remove these events in the next release for preventing misunderstandings.

I assume that you might want to detect if the value is changed and then start something which consumes some computing time. In this case I would recommend to detect in the behaviour model script update method (in your case the script Verkeerslicht3) if the value of the Signal is changed. If it is changed you can call your computing time consuming method - in your case I assume it is a network communication which will be started.

Hope that helps - best regards

Thomas

Hey Thomas,

Thanks for looking in to this!

Yes we want a event when a value is changed in the interface.

We are working on large projects, where we have 1000 - 20.000 variables in Simit.

Checking all those variables in the update method would cost a lot of resources.

So we try to avoid the update method where we can.

Would it be possible to implement a on changed event like the "PLCOutPutBoolChanged" event when a variable changes in the interface, in the next release?


Best regards,

Tim

Hi,

1000 - 20.000 is a lot. I am expecting more the Interface itself to be a bottleneck. By design - because of the SHM interface - Unity needs to loop through all the variables each cycle and to update them. In relation to that, I think that the mentioned update method is not costing much additional resources. For providing the change event I would need to implement a setter for the Structs StatusBool, StatusInt.... And this setter will be called each cycle (because of the necessity to loop through all SHM Variables) and will do more or less the same as the proposed update method. So I don't see so far a big advantage in implementing this.

Are the variables changing very fast in your application? Did you consider using OPCUA because there the variables are watchable and you can implement an event which is called when they are updated. Or is it necessary to use Simit?

Best regards

Thomas


Hi Tim,

I think I found a flexible way. We could implement Unity Events on the Signals.


This seems to be a very flexible and transparent way for the user:


Could you please check this if this fits your needs. If everything works for your side we would release. I will send you a beta version today or on Monday. Does that fits for you?

Best regards

Thomas

Hey Thomas,

Thanks for thinking along, we use Unity for making DigitalTwins of tunnels and bridges so there are a lot of IO’s, but they are not changing that often.

We are using OPCUA in our projects between control and Simit.

I am looking to the possibilities of the OPCUA driver now.

Your new solution looks really promising, will this solution work for SHM and the OPCUA interface?

I am looking forward to the beta version

Best regards,

Tim

Hi Tim,

Simit would need to be in this case the OPCUA server. Game4Automation is only able to be the client. Are you using Simit for modelling the logic or is it more acting only as an interface. If it is just an interface you could connect to the OPCUA server in the PLC directly from Game4Automation.

Please send me your Game4Automation Invoice number (i would need this to check your license).

You will get the Beta this afternoon.

And yes - this solution works for all Signals - independent from the Interface type.

Best regards

Thomas

... and please give Game4Automation a positive feedback in the Asset Store Reviews - this is really helpfull!

Hi Thomas, 

Yes i have set up Simit as OPCUA server and this is working.

We use logic in the Simit.

I will send a mail to info@game4automation.com with my invoice number.

I also left a review in the asset store :)


Best regards,

Tim

Hi Tim,

I will send you the beta via mail download link.

At the end it was easier as expected and we had an error in the signal override stuff what caused some problems.

At the end now it should work like you expected at the beginning. You can register to Signal change events by:

    var com = GetComponent<PLCInputBool>();
    com.SignalChanged += SignalChangedRuntime;

}



public void SignalChangedRuntime(Signal signal)
{
    Debug.Log("Signal Changed Runtime " + signal.ToString());
}

Or you can use as an alternative UnityEvents in the Inspector:

You can see how it can be used in the Script TestSignalChanged attached to CanConveyorSensor in the Demo model.

The signal changed events should now be also emitted if you use Simit as an Interface.

Please check if everything works if expected. We are going to release this officially next week.

Hey Thomas,

I have implemented your beta solution in my example program with the SharedMemoryInterface and its working really well, nice job !

After that i switched to the OPC-UA interface to see if that is working the same, but I don’t get a event when a PLCOutputBool is changing.

Is it possible to get the same behavior in the OPC-UA interface?

Best regards,

Tim

Hi Tim,

I am wondering why the event doesn’t works with OPCUA in the Beta - I will check an make it work

Best regards 

Thomas

Answer

Hi Tim,

there was a problem with the automatic settings of the defines.

Please check if the PLCOutput Script was added to your variable automatically:


If not please set in the defines manually "GAME4AUTOMATION" and reimport all OPCSignals.


Now it should work

Hi Thomas,

I looked in my "Scripting Define Symbols" and GAME4AUTOMATION and GAME4AUTOMATION_PROFESSIONAL where already there.

I have set up a connection to a SIMIT OPC UA Server, and the system variables in the folder "Server" are working fine.

They get a PLC script added to them. 

But if i add Variables in Simit and go to the folder InSimitOpcBin where my custom variables are. the dont get the PLC Output script