There is a free Unity asset to simplify the creation of an WinCC Unified Custom Web Control out of an Unity3d application. So, with that you can easily build WinCCUnified screens with real time 3d content built with Unity.
If you use the GraqhQL for Unity asset and if you want to set the headers on HTTP or Websockets in the code, then you must use the the GraphQLHttp or GraphQLWebsockets class. At the base class “GraphQL” there is no “Headers” property!
public GraphQLHttp MyGraphQL;
void Start()
{
if (MyGraphQL != null)
{
MyGraphQL.Headers = new List<Header>()
{
new Header() { Key = "token", Value = "secret"}
};
...
Then you can also execute a GraphQL query in the code.
The GraphQL for Unity Asset can be used to execute GraphQL queries in Unity. The result is set on properties of Unity objects and there is also a Unity Event on the GraphQL Query Object where user-defined function of a GameObject can be triggered every time when a queries returns data or an error.
public class Sample1 : MonoBehaviour
{
public void ResultEvent(GraphQLResult result)
{
if (result.Errors.Count==0)
{
Debug.Log("Data: " + result.Data.ToString());
}
else
{
Debug.Log("Error: " + result.Errors.ToString());
}
}
}
Create a GameObject with this class as component and then you can drag and drop this GameObject to the Query GameObject and select the “ResultEvent” method. Every time when the query is executed then this function will be called with the result data (or error data).
The GraphQL for Unity Asset uses the Newtonsoft version which is built in newer version of Unity (2020+). If you get an error like this:
Assembly 'Library/ScriptAssemblies/Assembly-CSharp.dll' will not be loaded due to errors: Reference has errors 'GraphQL'.
Assembly 'Assets/GraphQL/Libs/GraphQL.dll' will not be loaded due to errors:
GraphQL references strong named Newtonsoft.Json Assembly references: 12.0.0.0 Found in project: 12.0.1.0.
Assembly Version Validation can be disabled in Player Settings "Assembly Version Validation"
Then you can try to remove NewtonSoft dependency from your project – if you have a dependency. And just use the NewtonSoft version which is already built in and shipped with Unity 2020+. If you use an older version of Unity then you can try to copy the NewtonSoft DLL from 2020 and use this in your older Unity version.
Or you can go to Project Settings -> Player -> Other Settings and deactivate “Assembly Version Validation”
Install the newtonsoft package from Unity. Go into the package manager and click “+” and then select “Add package from git URL” and fill in “com.unity.nuget.newtonsoft-json”.
With GraphQL for Unity you can execute GraphQL Queries in a Unity way with GameObjects. But with the asset you can also execute queries in Unity with C# code.
Here is a simple example:
public GraphQL Connection;
public void ScriptQuery()
{
var query = "query($Token: String!) { doit($Token) { result } } ";
var args = new JObject
{
{ "Token", "123" }
};
Connection.ExecuteQuery(query, args, (result) =>
{
Debug.Log(result.Result.ToString());
});
}
Link the Connection variable to your GraphQL GameObject where the connection is set.
Note: the result callback function is called asynchronous and it is not executed in the Game-loop.
At startup it can also write the OPC UA node structure into the graph database, so that the basic model of the OPC UA server is mirrored to the graph database. For that you have to add the “Schemas” section in the config file (see an example configuration file below). There you can choose which RootNodes (and all sub nodes) of your OPC UA systems should be mirrored to the graph database.
Once you have the (simplified) OPC UA information model in the graph database, you can add on top of that your own knowledge graph data and create relations to OPC UA nodes of your machines to enrich the semantic data of the OPC UA model.
With that model you can leverage the power of your Knowledge Graphs in combination with live data from your machines and use Cypher queries to get the knowledge out of the graph.
Here we see an example of the OPC UA server from the SCADA System WinCC Open Architecture. The first level of nodes below the “Objects” node represent Datapoint-Types (e.g. PUMP1) followed by the Datapoint-Instances (e.g.: PumpNr) and below that we see the datapoint elements (e.g. value => speed). An datapoint element is an OPC UA variable where we also see the current value from the SCADA system.
Example Gateway configuration file:
Database:
Logger:
- Id: neo4j
Enabled: true
Type: Neo4j
Url: bolt://nuc1.rocworks.local:7687
Username: "neo4j"
Password: "manager"
Schemas:
- System: opc1 # Replicate node structure to the graph database
RootNodes:
- "ns=2;s=Demo" # This node and everything below this node
- System: winccoa1 # Replicate the nodes starting from "i=85" (Objects) node
WriteParameters:
BlockSize: 1000
Logging:
- Topic: opc/opc1/path/Objects/Demo/SimulationMass/SimulationMass_Float/+
- Topic: opc/opc1/path/Objects/Demo/SimulationMass/SimulationMass_Double/+
- Topic: opc/opc1/path/Objects/Demo/SimulationMass/SimulationMass_Int16/+
- Topic: opc/winccoa1/path/Objects/PUMP1/#
- Topic: opc/winccoa1/path/Objects/ExampleDP_Int/#
If your docker container do not use all your cpu’s, it may be the case that limits are set in /etc/systemd/system/docker.slice. To apply changed settings I had to reboot my machine (just a restart of docker didn’t change the behaviour).
#ModBus data from the Robot can now be used in #Unity for visualisation and also to control the Robot from Unity …
The Unity Package GraphQL for OPCUA is now not only for OPCUA anymore, it can also handle other types which are supported by the Automation Gateway – like the Plc option, which is based on PLC4X.