TwinCAT HMI
Connecting Bechoff PLC via Websocket with realvirtual.io
Last updated
Connecting Bechoff PLC via Websocket with realvirtual.io
Last updated
This interface is only available in realvirtual.io Professional and depends on the BestWebsocketsBundle, which must be purchased separately from the Unity Asset Store: Best Websockets Bundle.
Important: Currently, the interface works only with BestHTTP V2, which is no longer available on the Asset Store. After purchasing, please contact us at info@realvirtual.io or reach out to the BestHTTP developer to obtain BestHTTP V2. Additionally, in your project's scripting define symbols, you need to add REALVIRTUAL_BESTHTTP
(without the "3") to use this version.
This interface is beside TwinCAT ADS another interface for Beckhoff PLCs. It requires HMI licenses on the TwinCAT PLC. The advantage of this interface is that it does not depend on an installation on the device on which the simulation model is running. Communication takes place exclusively via WebSockets. This interface works on any type of target platform and also works within WebGL builds.
In contrary TwinCAT ADS requires ADS installed on the machine and is by this limited to Windows System.
The interface can be added to a realvirtual.io scene by selecting game4automation > Add Object > Interface > TwinCATHMI.
TE2000 license is needed for properties (HMI) configuration.
TE2000 Version 1.12.758.8 and above
You need on your PLC TF2000 licenses
REALVIRTUAL_BESTHTTP3
needs to be added to your Unity Project Project Settings > Player > Script Compilation
Newtonsoft.Json needs to be available and installed. In latest standard Unity releases Newtonsoft is already included. For enabling Newtonsoft please also add REALVIRTUAL_JSON
to your Scripting Define Symbols Project Settings > Player > Script Compilation
. For more infomation about how to install and get please check section Newtonsoft JSON
Within the TwinCAT PLC source all symbols needs to be annotated with { attribute 'TcHmiSymbol.AddSymbol' }, if they should be available for the TwinCATHMI interface.
True, if the interface is successfully connected to the PLC.
The adress of the Server (Notation must be ws://IP:Port
The current Status of the Websocket, "Open" if connection is active.
True during reconnection to Server.
If set to true additional messages are printed out to the Unity console
The Intervaltime in Milliseconds. All update messages are collected to one message inside the PLC within the intervall time.
If set to true, the outputs are subscribed and only changed outputs are send within the intervall time.
If set to true all outputs are send wthin the intervall time.
It is possible to import all symbold from an external CSV file. The table must look like this:
Security
If you want to use security features and login into the PLC with domain, user and password you need to set this to true and define the user and the password.
EventSignalRead
An Event which is fired when a Signal is read from the interface.
Only primitive datatypes like floats, ints, bools are transformed automatically to the realvirtual.io PLCInput and PLCOutput Variables.
Reading primitives within complex data
For reading complex datatypes you can access the primitive data within the complex datatype by adressing them like this:
Reading complex data with C# scripts
For subscribing a complex datatype you should create a variable of Type PLCOutputText. Within this text you will get the complex data as a Json. You can now use within a C# script JSON deserialization to transfer this JSON to a C# data type.
Writing complex data with C# scripts
For writing complex data you can call the public Method WriteSymbol
This will serialize the given object into a JSON and send it to the PLC. It is important that the C# data structure is identical to the data structure within the PLC.
Writing complex data with write acknowledgement
Usually, when using WriteSymbol for direct writing symbols into the PLC, the function is non blocking. You don't get any value back and you won't be automatically informed if the symbol is not written. In very complex and big data structures writing can take some time.
If you want to be sure that the data is written there is another write command:
This function is giving back an id as an INT
Before calling WriteSymbolControlled you should subscribe to this event, which will be called as soon as a reply is send from the PLC.
The code for your event should look somehow like this. You need now to check if the method was exactly called for your WriteSymbolControlled id (which was given back in the call) and if there was no error (error == false). You can also look in detail into the reply which is given you as a full JSON string in reply.
© 2022 in2Sight GmbH https://realvirtual.io - All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including printing, saving, photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher.