realvirtual.io
  • Building Digital Twins with Unity and realvirtual.io
  • Basics
    • Installation
    • Demo Model
      • Old Demo Model
    • Editor User Interface
      • Hierarchy Window
      • 3D Views
      • Quick Edit
      • Move Pivot Points (Pro)
      • Selection Window (Pro)
      • Material Window (Pro)
      • Measurement (Pro)
      • Kinematic Tool (Pro)
      • Model Checker
    • Runtime UI
      • Group Manager
      • Debug Console
      • Responsiveness
      • Runtime Persistence
    • Importing and exporting
    • Folder structure
    • Tutorial
    • Physics
    • CAD import (Pro)
      • CADLink (Pro)
      • CAD Checker (Pro)
      • CAD Updater (Pro)
    • Reusable Components (Prefabs)
    • Cadenas parts4cad
    • Publishing the Digital Twin
    • Revision management
  • News
  • Login & Download Updates (Pro)
  • Components & Scripts
    • Realvirtual
      • Environment Controller
    • MU, Source and Sink
      • Source
      • Sink
    • Motion and Kinematic
      • Drive
      • Kinematic
      • Group
      • Joint
      • CAM
      • TransportSurface
      • Guided Transport
      • Drive behavior
      • Chain
      • Chain element
      • Motion for developers
    • Sensors
      • Sensor
      • Measure
      • MeasureRaycast
    • Picking and Placing MUs
      • Grip
      • Gripper
      • Fixer
      • Pattern
    • Changing MUs
      • MaterialChanger
      • PartChanger
      • Cutter
    • Scene Interaction
      • 3D Buttons
      • Screen Overlay Buttons
      • Scene Selectables
      • Lamp
      • Interact3D
      • UI components
      • HMI components (Pro)
        • Start your own HMI
        • HMI Tab
        • HMI DropDown
        • HMI Puschbutton
        • HMI Switch
        • HMI Value
        • HMI Text
        • HMI Slider
        • HMI Message
        • HMI Marker
      • ModelZoo (Pro)
    • Interfaces
      • Interface Tools
        • Signal Manager
        • Signal Importer Exporter
        • Signal Catcher
        • OnValueChangedReconnect
      • Signal Importer / Exporter
      • ABB RobotStudio (Pro)
      • Denso Robotics (Pro)
      • EthernetIP (Pro)
      • Fanuc (Pro)
      • FMI
      • Igus Rebel
      • MQTT (Pro)
      • Modbus (Pro)
      • OPCUA (Pro)
      • PLCSIM Advanced (Pro)
      • RoboDK (Pro)
      • RFSuite (Pro)
      • SEW SimInterface (Pro)
      • Siemens Simit Interface (Pro)
      • Simit Shared Memory (Pro)
      • Simulink (Pro)
      • S7 TCP
      • TwinCAT (Pro)
      • TwinCAT HMI (Pro)
      • UDP (Pro)
      • Universal Robots (Pro)
      • Wandelbots Nova (Pro)
      • Websocket (Pro)
      • Windmod Y200 (Pro)
      • Custom Interfaces
    • Performance Tools
      • Combine Meshes (Pro)
      • Create Prefab (Pro)
      • Hierarchy Cleanup (Pro)
      • Mesh Optimizer (Pro)
      • Performance Optimizer (Pro)
    • Defining Logic
      • Unity Scripting
      • Behavior Graph
      • Logicsteps
      • Unity Visual Scripting
      • Recorder
    • Robot Inverse Kinematics (Pro)
    • Volume Tracking (Pro)
  • Multiplayer (Pro)
  • Extensions
    • ModelZoo
      • Beckhoff TwinCAT
      • Siemens S7
      • Denso Cobotta 1300
      • Wandelbots Nova Fanuc CRX
      • Universal Robots UR10
      • Fanuc Roboguide
    • realvirtual.io AIBuilder
      • realvirtual.io AI Builder Overview
      • Generate AI Training Data
      • AI Training
      • Testing AI in a Digital Twin
      • Deploying the AI
    • realvirtual.io Simulation
      • Conveyor Library
      • Path System
        • Path finding
        • Line
        • Curve
        • Workstation
        • Catcher
        • Pathmover
    • realvirtual.io Industrial Metaverse
      • Setup Guide
      • VR Modules
      • AR Modules
      • Multiuser
    • AGX Physics
    • VR Builder
    • CMC ViewR
  • Advanced Topics
    • Render Pipelines
    • Mixed Reality with Meta Quest3
    • Upgrade Guide
      • Upgrade to 2022
    • Open Digital Twin Interface
    • Usefull Addons
    • Improving Performance
    • Supported Platforms
    • Compiler Defines
    • For Developers
      • Important Classes and Interfaces
      • Assembly Definitions
      • Starting your development
      • Class documentation
      • realvirtual Init Sequence
      • realvirtualBehavior Lifetime Methods
      • Testing
    • Newtonsoft JSON
    • Troubleshooting
  • Release Notes
  • AI Digital Twin Assistant (GPT4)
  • License Conditions
Powered by GitBook
On this page
  • Prerequisites
  • Annotations in the PLC code
  • Interface Properties
  • Complex data types
Edit on GitHub
  1. Components & Scripts
  2. Interfaces

TwinCAT HMI (Pro)

Connecting Bechoff PLC via Websocket with realvirtual.io

PreviousTwinCAT (Pro)NextUDP (Pro)

Last updated 7 months ago

This interface is only available in realvirtual.io Professional and depends on the BestWebsocketsBundle, which must be purchased separately from the Unity Asset Store: .

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.

Prerequisites

  • 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

Annotations in the PLC code

Within the TwinCAT PLC source all symbols needs to be annotated with { attribute 'TcHmiSymbol.AddSymbol' }, if they should be available for the TwinCATHMI interface.

Interface Properties

IsConnected (Readonly)

True, if the interface is successfully connected to the PLC.

Server Adress

The adress of the Server (Notation must be ws://IP:Port

Status (Readonly)

The current Status of the Websocket, "Open" if connection is active.

IsConnecting (Readonly)

True during reconnection to Server.

DebugMode

If set to true additional messages are printed out to the Unity console

Intervall Time

The Intervaltime in Milliseconds. All update messages are collected to one message inside the PLC within the intervall time.

Subscribe Outputs

If set to true, the outputs are subscribed and only changed outputs are send within the intervall time.

Poll Outputs

If set to true all outputs are send wthin the intervall time.

Symbol Table

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.

Complex data types

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

public void WriteSymbol (string symbol, object signal)

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:

public int WriteSymbolControlled (string symbol, object signal)

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.

EventSignalRead.AddListener(OnSymbolWritten);

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.

   private void OnSymbolWritten(int id, bool error, string reply)
        {
            // Here check if error is false and the id is the same as given back in WriteSymbolControlled
        }

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

© 2022 in2Sight GmbH - 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.

Newtonsoft JSON
https://realvirtual.io
Best Websockets Bundle
TwinCAT HMI interface (based on Websockets) for realvirtual.io
TF2000 license within TwinCAT
BestHTTP and JSON in Scripting Define Symbols
TwinCAT HMI inspector properties